From: sashiko-bot@kernel.org
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 1/2] x86/tdx: Fix off-by-one in port I/O handling
Date: Wed, 27 May 2026 12:47:44 +0000 [thread overview]
Message-ID: <20260527124745.333EC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260527120544.2903923-2-kas@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] VMM-controlled Register Poisoning in CPUID emulation.
--
commit 8bf39531f06bffdf9286b3ddc6968088a81a8929
Author: Kiryl Shutsemau (Meta) <kas@kernel.org>
x86/tdx: Fix off-by-one in port I/O handling
This commit corrects an off-by-one error in the mask calculation for port io
handling. The previous implementation used a mask that was one bit too wide
for all io sizes, which is now corrected.
Link: https://lore.kernel.org/all/CAKw_Dz96rfSQc6Rn+9QBcUFHhmkK+9zu+P=bxowfZwxrATCBRg@mail.gmail.com/
> diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
> index 186915a17c50f..65119362f9a25 100644
> --- a/arch/x86/coco/tdx/tdx.c
> +++ b/arch/x86/coco/tdx/tdx.c
> @@ -693,7 +693,7 @@ static bool handle_in(struct pt_regs *regs, int size, int port)
> .r13 = PORT_READ,
> .r14 = port,
> };
> - u64 mask = GENMASK(BITS_PER_BYTE * size, 0);
> + u64 mask = GENMASK(BITS_PER_BYTE * size - 1, 0);
> bool success;
>
> /*
[ ... ]
[Severity: Critical]
This is a pre-existing issue, but can a malicious hypervisor poison the upper
32 bits of the registers during cpuid emulation?
Architecturally, the cpuid instruction returns 32-bit values in eax, ebx,
ecx, and edx. In 64-bit mode, writes to these 32-bit registers must
zero-extend to their 64-bit counterparts.
Looking at handle_cpuid() in arch/x86/coco/tdx/tdx.c, the 64-bit results
fetched from the untrusted hypervisor are copied directly into the guest's
pt_regs:
arch/x86/coco/tdx/tdx.c:handle_cpuid() {
...
/*
* As per TDX GHCI CPUID ABI, r12-r15 registers contain contents of
* EAX, EBX, ECX, EDX registers after the CPUID instruction execution.
* So copy the register contents back to pt_regs.
*/
regs->ax = args.r12;
regs->bx = args.r13;
regs->cx = args.r14;
regs->dx = args.r15;
return ve_instr_len(ve);
}
Since these are not cast to u32 or zero-extended, does this allow the
hypervisor to supply values with non-zero upper 32 bits and potentially lead
to out-of-bounds memory accesses or control flow hijacking?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260527120544.2903923-1-kas@kernel.org?part=1
next prev parent reply other threads:[~2026-05-27 12:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 12:05 [PATCH v3 0/2] x86/tdx: Port I/O emulation fixes Kiryl Shutsemau (Meta)
2026-05-27 12:05 ` [PATCH v3 1/2] x86/tdx: Fix off-by-one in port I/O handling Kiryl Shutsemau (Meta)
2026-05-27 12:47 ` sashiko-bot [this message]
2026-05-27 15:38 ` Edgecombe, Rick P
2026-05-27 12:05 ` [PATCH v3 2/2] x86/tdx: Fix zero-extension for 32-bit port I/O Kiryl Shutsemau (Meta)
2026-05-27 13:12 ` sashiko-bot
2026-05-27 15:45 ` Edgecombe, Rick P
2026-05-27 17:45 ` Dave Hansen
2026-05-28 10:14 ` Kiryl Shutsemau
2026-05-28 16:43 ` Dave Hansen
2026-05-28 17:25 ` Dave Hansen
2026-05-28 19:58 ` David Laight
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=20260527124745.333EC1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--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 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.