From: Peter Fang <peter.fang@intel.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <kvm@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] virt: tdx-guest: Allocate Quote buffer dynamically
Date: Mon, 27 Jul 2026 03:13:50 -0700 [thread overview]
Message-ID: <20260727101350.GB482062@pedri> (raw)
In-Reply-To: <20260717215520.76C261F000E9@smtp.kernel.org>
On Fri, Jul 17, 2026 at 09:55:19PM +0000, sashiko-bot@kernel.org wrote:
> 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.
> --
>
> > @@ -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?
Good catch... I think this race could happen. /dev/tdx_guest is
considered a legacy interface now but this needs to be fixed. I'll add
it to the cleanup list.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260717214349.4075994-1-peter.fang@intel.com?part=2
next prev parent reply other threads:[~2026-07-27 10:13 UTC|newest]
Thread overview: 14+ 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-22 13:21 ` Binbin Wu
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
2026-07-27 10:13 ` Peter Fang [this message]
2026-07-20 13:35 ` Dave Hansen
2026-07-21 6:49 ` Peter Fang
2026-07-21 13:48 ` Dave Hansen
2026-07-21 16:43 ` Edgecombe, Rick P
2026-07-22 7:36 ` Peter Fang
2026-07-22 12:00 ` Kiryl Shutsemau
2026-07-23 8:19 ` Peter Fang
2026-07-22 6:39 ` Peter Fang
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=20260727101350.GB482062@pedri \
--to=peter.fang@intel.com \
--cc=kvm@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox