From: sashiko-bot@kernel.org
To: "Peter Fang" <peter.fang@intel.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 2/2] virt: tdx-guest: Allocate Quote buffer dynamically
Date: Fri, 17 Jul 2026 21:55:19 +0000 [thread overview]
Message-ID: <20260717215520.76C261F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260717214349.4075994-3-peter.fang@intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Premature exposure of the misc device allows a Use-After-Free (UAF) on the module initialization error path if `alloc_quote_buf()` fails.
--
--- Patch [2]: [PATCH v2 2/2] virt: tdx-guest: Allocate Quote buffer dynamically ---
commit e37e54ca6bcf9f24fca7285847baa3251ff5dfba
Author: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
virt: tdx-guest: Allocate Quote buffer dynamically
This modifies the TDX attestation driver to dynamically allocate the Quote
buffer based on the size reported by the TDX module. It uses alloc_pages_exact()
to allocate up to a 4MB contiguous buffer and fails quietly if the allocation
cannot be satisfied.
> diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
> index d0303e31e8161..ce2c2ef746762 100644
> --- a/drivers/virt/coco/tdx-guest/tdx-guest.c
> +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
[ ... ]
> @@ -417,7 +442,7 @@ static int __init tdx_guest_init(void)
> if (ret)
> goto deinit_mr;
>
> - quote_data = alloc_quote_buf();
> + quote_data = alloc_quote_buf("e_data_len);
[Severity: High]
This is a pre-existing issue, but this patch makes it significantly more
likely to trigger by introducing a large contiguous memory allocation (up to
4MB) that can easily fail on fragmented systems.
Can this lead to a Use-After-Free on the initialization error path?
If misc_register(&tdx_misc_dev) (called just before this hunk) succeeds,
the /dev/tdx_guest device is immediately exposed to userspace. A userspace
process can open it and call ioctl(TDX_CMD_GET_REPORT0), entering
tdx_do_report() which uses tdx_report_buf.
If alloc_quote_buf() then fails, the error path calls misc_deregister() and
tdx_mr_deinit().
tdx_mr_deinit() executes:
kfree(tdx_report_buf);
This freeing happens without acquiring mr_lock, meaning it can race with the
ongoing ioctl. Could the concurrent ioctl in tdx_do_report() then access the
freed tdx_report_buf?
Should misc_register() be moved to the end of tdx_guest_init() after all
resource allocations succeed?
> if (!quote_data) {
> pr_err("Failed to allocate Quote buffer\n");
> ret = -ENOMEM;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260717214349.4075994-1-peter.fang@intel.com?part=2
prev parent reply other threads:[~2026-07-17 21:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 21:43 [PATCH v2 0/2] tdx-guest: Make Quote buffer size dynamic Peter Fang
2026-07-17 21:43 ` [PATCH v2 1/2] x86/tdx: Add helper to query maximum TD Quote size Peter Fang
2026-07-17 21:43 ` [PATCH v2 2/2] virt: tdx-guest: Allocate Quote buffer dynamically Peter Fang
2026-07-17 21:55 ` sashiko-bot [this message]
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=20260717215520.76C261F000E9@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.