Re: [PATCH v8 08/21] x86/virt/seamldr: Allocate and populate a module update request

From: Dave Hansen

Date: Fri May 08 2026 - 12:49:03 EST


On 5/7/26 06:19, Chao Gao wrote:
...
>>> + /*
>>> + * Don't care about user passing the wrong file, but protect
>>> + * kernel ABI by preventing accepting garbage.
>>> + */
>>> + if (memcmp(blob->signature, "TDX-BLOB", 8))
>>> + return ERR_PTR(-EINVAL);
>>
>> Is there really no helper in the kernel anywhere that can safely do the
>> 8-byte compare against two known-to-the-compiler 8-byte-wide fields
>> without hard-coding the 8?
>
> I couldn't find a helper that automatically derives the comparison
> length from the operands. 'strcmp()' is not suitable here because
> 'blob->signature' is not NUL-terminated.
>
> Do you mean just avoiding the hard-coded 8, e.g.
>
> if (memcmp(blob->signature, "TDX-BLOB", sizeof(blob->signature)))
> return ERR_PTR(-EINVAL);
>
> or define the 'u8 signature[8]' as a u64 and compare it with a constant, like
>
> /* Little-endian encoding of "TDX-BLOB" string */
> #define TDX_IMAGE_SIGNATURE 0x424f4c422d584454ULL
>
> if (blob->signature != TDX_IMAGE_SIGNATURE)
> return ERR_PTR(-EINVAL);

Either one of those is fine with me. I'd probably do the sizeof()
variant, but no strong preference.

>>> + struct seamldr_params *params;
>>> + int module_pg_cnt, sig_pg_cnt;
>>> + const u8 *sig, *module;
>>> + int i;
>>> +
>>> + params = (struct seamldr_params *)get_zeroed_page(GFP_KERNEL);
>>> + if (!params)
>>> + return ERR_PTR(-ENOMEM);
>>
>> kzmalloc(PAGE_SIZE, GFP_KERNEL) will save you a cast.
>
> I noticed that 'kzalloc_obj()' can be used here, which avoids spelling out
> the size and GFP flags explicitly. So I ended up with:
>
> params = kzalloc_obj(*params);

That's fine too.