From: Chao Gao <chao.gao@intel.com>
To: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-coco@lists.linux.dev" <linux-coco@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Van De Ven, Arjan" <arjan.van.de.ven@intel.com>,
"Xu, Yilun" <yilun.xu@intel.com>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"kas@kernel.org" <kas@kernel.org>,
"hpa@zytor.com" <hpa@zytor.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"bp@alien8.de" <bp@alien8.de>,
"tglx@kernel.org" <tglx@kernel.org>
Subject: Re: [RFC PATCH v1 1/3] x86/virt/seamldr: Allocate 'struct seamldr_params' after image validation
Date: Tue, 3 Nov 2026 14:30:38 +0800 [thread overview]
Message-ID: <aul_jq5X63s7QnTS@intel.com> (raw)
In-Reply-To: <5397736259f9743da43ad41b2e2a995e6372f1f7.camel@intel.com>
On Tue, Nov 03, 2026 at 07:58:06AM +0800, Edgecombe, Rick P wrote:
>On Fri, 2026-10-30 at 01:52 -0700, Chao Gao wrote:
>> 'struct seamldr_params' is the in-memory ABI the kernel passes to P-SEAMLDR
>> to update the TDX module. It has a fixed size and is allocated before the
>> update image is validated.
>>
>> To support larger TDX modules, the ABI was extended to let
>> 'struct seamldr_params' link to extra pages. The number of extra pages
>> depends on the module page count, which can be trusted only after the image
>> header is validated.
>>
>> Move the allocation after the image validation in init_seamldr_params(),
>> so a later change can allocate 'struct seamldr_params' and the extra
>> pages as one buffer. Rename the function to build_seamldr_params() since
>> it now allocates and returns a buffer rather than filling in one the
>> caller provides.
>>
>> No functional change intended.
>
>So we want to have the allocation happen after header->module_nr_pages is
>verified so we don't allocate some ridiculous size. And the verification
>currently happens all in one place. So move the allocation.
>
>Did you look at just moving the one header field check earlier? Wondering if it
>requires less churn.
I didn't. It works too, and we can drop this patch by doing the check in
alloc_seamldr_params() (added in patch 2) instead:
static struct seamldr_params *alloc_seamldr_params(u32 nr_module_pages)
{
struct seamldr_params *params;
u32 nr_chain_pages;
u32 nr_direct;
u64 *link;
+ if (nr_module_pages > SEAMLDR_MAX_NR_MODULE_PAGES)
+ return ERR_PTR(-EINVAL);
+
/*
* Number of module pages that fit directly in
* module_pages_pa_list[]. Minus one as the last entry is
* reserved to point to the first chain page.
*/
nr_direct = SEAMLDR_NR_MODULE_PA_ENTRIES - 1;
My concern is that this spreads the header checks across two functions.
The churn is a one-time cost, while keeping all the checks in one place
helps readability for the long term. That said, I am fine with going
with less churn if you prefer.
>
>Hmm, also, this is an admin only thing right? What goes wrong if the admin user
>passes a huge value?
Right, it is admin only, and nothing too bad happens. A u32
module_nr_pages can ask for about 32GB of chain pages. Anything above
KMALLOC_MAX_SIZE (4MB) hits the WARN_ON_ONCE() in the page allocator,
taints the kernel and fails the update with -ENOMEM.
So it is not a serious problem. But relying on "it does not hurt" has a
cost of its own. Every reader has to work out why the unvalidated value
is safe to use. Using the value only after it is validated is more
straightforward.
>
>In any case, I think the log could be simpler and more plain while still
>explaining what is happening better.
If we keep this patch, how about:
'struct seamldr_params' is the in-memory ABI passed to P-SEAMLDR to
update the TDX module. It has a fixed size and is allocated before
the update image header is validated.
A later change will append a variable number of pages to the
structure, sized by header->module_nr_pages. The allocation then
needs to come after that field is checked, so that a bogus header
cannot make the kernel attempt a huge allocation.
All header checks are in one place. Move the allocation after them
instead of splitting the module_nr_pages check out.
Rename init_seamldr_params() to build_seamldr_params() since it now
allocates and returns the structure rather than filling in one the
caller provides.
No functional change intended.
next prev parent reply other threads:[~2026-11-03 6:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 8:52 [RFC PATCH v1 0/3] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Chao Gao
2026-10-30 8:52 ` [RFC PATCH v1 1/3] x86/virt/seamldr: Allocate 'struct seamldr_params' after image validation Chao Gao
2026-11-02 23:58 ` Edgecombe, Rick P
2026-11-03 6:30 ` Chao Gao [this message]
2026-11-03 18:55 ` Edgecombe, Rick P
2026-10-30 8:52 ` [RFC PATCH v1 2/3] x86/virt/seamldr: Support large TDX module binaries Chao Gao
2026-11-03 0:35 ` Edgecombe, Rick P
2026-11-03 8:57 ` Chao Gao
2026-10-30 8:53 ` [RFC PATCH v1 3/3] x86/virt/seamldr: Support multiple sigstruct pages Chao Gao
2026-11-02 23:50 ` [RFC PATCH v1 0/3] TDX: P-SEAMLDR: Support large TDX modules and sigstructs Edgecombe, Rick P
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aul_jq5X63s7QnTS@intel.com \
--to=chao.gao@intel.com \
--cc=arjan.van.de.ven@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kas@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
--cc=yilun.xu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox