All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peter Fang" <peter.fang@intel.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote
Date: Fri, 04 Dec 2026 18:36:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-250433@kernel.org> (raw)
In-Reply-To: <20261204182022.324230-2-peter.fang@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] x86/virt/tdx: uninit HPA list nodes and tail read in
  tdx_quote_generate()
- [Medium] x86/virt/tdx: missing cond_resched() in tdx_quote_get() retry
  loop
--

commit 822505db95798a7ae7ce913170aae5958aefcee1
Author: Peter Fang <peter.fang@intel.com>

x86/virt/tdx: Add interface to generate a Quote

This commit adds tdx_quote_generate() and a TDH.QUOTE.GET SEAMCALL wrapper so
KVM can request a signed TDX Quote using caller-provided host pages.

> diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> index dbe17a136dced..39f280190b73d 100644
> --- a/arch/x86/virt/vmx/tdx/tdx.c
> +++ b/arch/x86/virt/vmx/tdx/tdx.c
> @@ -2529,6 +2529,102 @@ void tdx_free_control_page(struct page *page)
>  }
>  EXPORT_SYMBOL_FOR_KVM(tdx_free_control_page);
>  
> +static u64 tdx_quote_get(struct tdx_td *td, u16 session_id,
> +			 struct page *report_page, u64 report_size,
> +			 u64 *quote_hpa_list, u64 quote_buf_size,
> +			 u64 *quote_size)
> +{

[ ... ]

> +	do {
> +		r = seamcall_ret(TDH_QUOTE_GET, &args);
> +	} while (r == TDX_INTERRUPTED_RESUMABLE);

[Severity: Medium]
Should this retry loop call cond_resched()?

seamcall_ret() only calls preempt_enable(), which does not reschedule on
CONFIG_PREEMPT_NONE or CONFIG_PREEMPT_VOLUNTARY kernels.  In sleepable
runtime context, spinning across TDX_INTERRUPTED_RESUMABLE retries can starve
other tasks and delay RCU quiescent states, unlike init_tdmr().

[ ... ]

> +int tdx_quote_generate(struct tdx_td *td, u16 session_id,
> +		       struct page *report_page, u64 report_size,
> +		       struct page **quote_pages, u64 quote_buf_size,
> +		       u64 *quote_size, u64 *seamcall_err)
> +{
> +	int num_quote_pages, num_nodes, ret = 0;
> +	u64 *node_head, *node_entry;
> +	u64 r;
> +
> +	/*
> +	 * Pass the quote buffer to the TDX module as an HPA linked list. Each
> +	 * node holds 4KB page HPAs and the last entry points to the next node.
> +	 */
> +	node_head = kmalloc(PAGE_SIZE, GFP_KERNEL);
> +	if (!node_head)
> +		return -ENOMEM;
> +
> +	node_entry = node_head;
> +	num_quote_pages = PFN_UP(quote_buf_size);
> +	num_nodes = 1;
> +
> +	/* Populate the linked list. Allocate new nodes as needed. */
> +	for (int i = 0, pages = 0; pages < num_quote_pages;
> +	     i = (i + 1) % HPAS_PER_NODE) {
> +		if (i == HPAS_PER_NODE - 1) {
> +			u64 *new_node = kmalloc(PAGE_SIZE, GFP_KERNEL);
> +
> +			if (!new_node) {
> +				ret = -ENOMEM;
> +				goto out_free_nodes;
> +			}
> +
> +			/* Write the 'next' pointer. */
> +			node_entry[i] = __pa(new_node);
> +			node_entry = new_node;
> +			num_nodes++;
> +			continue;
> +		}
> +
> +		node_entry[i] = page_to_phys(quote_pages[pages]);
> +		pages++;
> +	}
> +
> +	r = tdx_quote_get(td, session_id, report_page, report_size, node_head,
> +			  quote_buf_size, quote_size);
> +
> +	*seamcall_err = r;
> +
> +	if (r != TDX_SUCCESS)
> +		ret = -EIO;
> +
> +out_free_nodes:
> +	for (int i = 0; i < num_nodes; i++) {
> +		node_entry = node_head;
> +		node_head = __va(node_head[HPAS_PER_NODE - 1]);
> +		kfree(node_entry);
> +	}

[Severity: Medium]
Can node_head and new_node pass uninitialized slab memory to TDH_QUOTE_GET
and read an uninitialized next pointer in out_free_nodes?

Both allocations use kmalloc() instead of kzalloc(), and the loop only sets
entries for pages < num_quote_pages and the next pointer when chaining a new
node.  Unused trailing HPA slots and the final node's next pointer remain
uninitialized, which can cause TDH_QUOTE_GET to fail or walk bad addresses.

The final iteration of out_free_nodes also unconditionally reads
node_head[HPAS_PER_NODE - 1] on every call, including -ENOMEM, triggering an
uninitialized heap read.  Allocating nodes with kzalloc() and skipping the
next-pointer read on the last node avoids both issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204182022.324230-1-peter.fang@intel.com?part=1

  reply	other threads:[~2026-12-04 18:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:18 [PATCH v3 0/8] Enable DICE-based TDX quoting Peter Fang
2026-12-04 18:18 ` [PATCH v3 1/8] x86/virt/tdx: Add interface to generate a Quote Peter Fang
2026-12-04 18:36   ` sashiko-bot [this message]
2026-12-04 19:15   ` Dave Hansen
2026-12-04 22:02     ` Edgecombe, Rick P
2026-12-04 21:44   ` Adrian Hunter
2026-12-04 22:04     ` Edgecombe, Rick P
2026-12-04 18:18 ` [PATCH v3 2/8] x86/virt/tdx: Add interface to check quoting capabilities Peter Fang
2026-12-04 18:44   ` sashiko-bot
2026-12-04 18:18 ` [PATCH v3 3/8] KVM: TDX: Require at least one quoting session and thread per CPU Peter Fang
2026-12-04 18:44   ` sashiko-bot
2026-12-04 18:18 ` [PATCH v3 4/8] KVM: TDX: Add KVM_TDX_GET_QUOTE sub-ioctl for quoting Peter Fang
2026-12-04 18:51   ` sashiko-bot
2026-12-04 18:18 ` [PATCH v3 5/8] KVM: TDX: Report maximum Quote size in TDX capabilities Peter Fang
2026-12-04 18:18 ` [PATCH v3 6/8] KVM: TDX: Document KVM_TDX_GET_QUOTE Peter Fang
2026-12-04 18:36   ` sashiko-bot
2026-12-04 18:18 ` [PATCH v3 7/8] x86/virt/tdx: Enable the quoting extension Peter Fang
2026-12-04 18:52   ` sashiko-bot
2026-12-04 18:18 ` [PATCH v3 8/8] x86/virt/tdx: Add documentation for DICE-based quoting Peter Fang
2026-12-04 18:40 ` [PATCH v3 0/8] Enable DICE-based TDX quoting Jason Gunthorpe
2026-12-04 18:47   ` Edgecombe, Rick P
2026-12-04 18:50     ` Jason Gunthorpe
2026-12-04 19:11       ` Edgecombe, Rick P
2026-12-04 23:51         ` Jason Gunthorpe
2026-12-05  1:50           ` 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=sashiko-outbox-250433@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=peter.fang@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.