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 2/2] virt: tdx-guest: Allocate Quote buffer dynamically
Date: Fri, 12 Jun 2026 11:22:02 +0000	[thread overview]
Message-ID: <20260612112202.82E011F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612110853.3188196-3-peter.fang@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unbounded host-provided quote size causes guest kernel warning (and potential panic) during allocation.
--

commit 918e9fdc48e5a03b41dab3a999be1a3f631327c1
Author: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>

virt: tdx-guest: Allocate Quote buffer dynamically

This commit modifies the TDX attestation driver to allocate the Quote
buffer dynamically based on the size reported by the TDX module. It falls
back to a default 128 KB buffer if the reported size is unavailable,
supporting larger quotes needed for newer schemes.

> diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
> --- a/drivers/virt/coco/tdx-guest/tdx-guest.c
> +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
[ ... ]
> @@ -223,19 +223,43 @@ static void free_quote_buf(void *buf)
>  	free_pages_exact(buf, len);
>  }
>  
> -static void *alloc_quote_buf(void)
> +static size_t get_quote_buf_size(void)
>  {
> -	size_t len = PAGE_ALIGN(GET_QUOTE_BUF_SIZE);
> -	unsigned int count = len >> PAGE_SHIFT;
> +	size_t buf_sz = GET_QUOTE_DEFAULT_BUF_SIZE;
> +	u32 quote_sz;
> +
> +	quote_sz = tdx_get_max_quote_size();
> +
> +	if (quote_sz)
> +		/* Reported size does not include GetQuote header */
> +		buf_sz = TDX_QUOTE_BUF_LEN(quote_sz);
> +
> +	return PAGE_ALIGN(buf_sz);
> +}
> +
> +static void *alloc_quote_buf(size_t *buflen)
> +{
> +	unsigned int count;
> +	size_t len;
>  	void *addr;
>  
> +	len = get_quote_buf_size();
> +
> +	/*
> +	 * This fails if the requested size exceeds the buddy allocator's
> +	 * maximum order (order-10, 4MB).
> +	 */
>  	addr = alloc_pages_exact(len, GFP_KERNEL | __GFP_ZERO);

[Severity: High]
If the host provides an excessively large quote_sz, could this allocation
trigger a kernel warning?

The comments indicate the buddy allocator will fail requests exceeding
its maximum order. However, passing an unbounded, host-controlled size
directly to alloc_pages_exact() without __GFP_NOWARN will trigger a
WARN_ON_ONCE_GFP in the page allocator's slow path before failing.

If a host is malicious or misconfigured, could this be used to spam the
guest's kernel log or cause a denial-of-service crash if the guest runs
with panic_on_warn=1?

Would it be better to explicitly check the size against a reasonable upper
bound or include the __GFP_NOWARN flag here?

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

  reply	other threads:[~2026-06-12 11:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 11:08 [PATCH 0/2] tdx-guest: Make Quote buffer size dynamic Peter Fang
2026-06-12 11:08 ` [PATCH 1/2] x86/tdx: Add helper to query maximum TD Quote size Peter Fang
2026-06-12 12:36   ` Kiryl Shutsemau
2026-06-12 14:25   ` Xiaoyao Li
2026-06-12 11:08 ` [PATCH 2/2] virt: tdx-guest: Allocate Quote buffer dynamically Peter Fang
2026-06-12 11:22   ` sashiko-bot [this message]
2026-06-12 12:37   ` Kiryl Shutsemau

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=20260612112202.82E011F000E9@smtp.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.