From: sashiko-bot@kernel.org
To: weichenchen <weichen.chen@linux.alibaba.com>, kvm@vger.kernel.org
Subject: Re: [PATCH v2] KVM: x86: Fix stalled descriptor table accesses to MMIO
Date: Thu, 19 Nov 2026 06:21:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-222518@kernel.org> (raw)
In-Reply-To: <20261119055747.23819-1-weichen.chen@linux.alibaba.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: x86: unmasked addr.ea increment in em_lgdt_lidt() breaks
32-bit wrap
--
commit 14df3ccaae0dc59c054ba57d9b0335ad6207effb
Author: weichenchen <weichen.chen@linux.alibaba.com>
KVM: x86: Fix stalled descriptor table accesses to MMIO
This commit switches LGDT, LIDT, SGDT, and SIDT operand accesses from
standard memory accessors to emulated memory accessors and common writeback
so MMIO operands do not stall emulation.
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index c1b21282187f3..3a9a67f4b0d7c 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
[ ... ]
> @@ -3465,14 +3447,27 @@ static int em_sidt(struct x86_emulate_ctxt *ctxt)
>
> static int em_lgdt_lidt(struct x86_emulate_ctxt *ctxt, bool lgdt)
> {
> - struct desc_ptr desc_ptr;
> + struct segmented_address addr = ctxt->src.addr.mem;
> + struct desc_ptr desc_ptr = {};
> + unsigned long limit_addr, base_addr;
> + unsigned int base_bytes, desc_bytes;
> int rc;
>
> if (ctxt->mode == X86EMUL_MODE_PROT64)
> ctxt->op_bytes = 8;
> - rc = read_descriptor(ctxt, ctxt->src.addr.mem,
> - &desc_ptr.size, &desc_ptr.address,
> - ctxt->op_bytes);
> + base_bytes = ctxt->op_bytes == 2 ? 3 : ctxt->op_bytes;
> + desc_bytes = sizeof(desc_ptr.size) + base_bytes;
> +
> + /* Check both fields before an MMIO read can have side effects. */
> + rc = linearize(ctxt, addr, sizeof(desc_ptr.size), false, &limit_addr);
> + if (rc != X86EMUL_CONTINUE)
> + return rc;
> + addr.ea += sizeof(desc_ptr.size);
> + rc = linearize(ctxt, addr, base_bytes, false, &base_addr);
> + if (rc != X86EMUL_CONTINUE)
> + return rc;
> +
> + rc = read_emulated(ctxt, limit_addr, &desc_ptr, desc_bytes);
[Severity: Medium]
Does incrementing addr.ea without 32-bit masking break 32-bit address
wraparound for LGDT/LIDT at the top of a 4GB segment?
Because addr.ea is a 64-bit unsigned long, an operand at 0xfffffffe or
0xffffffff in 16-bit or 32-bit mode overflows addr.ea to 0x100000000 or
0x100000001, causing the second linearize() call to fail the addr.ea > lim
check and inject a spurious #GP(0) or #SS(0) when lim == 0xffffffff.
A single linearize(ctxt, addr, desc_bytes, false, &limit_addr) call (or
segmented_read(ctxt, ctxt->src.addr.mem, &desc_ptr, desc_bytes)) already
checks that the full descriptor fits within the segment limit when
lim != 0xffffffff while preserving 32-bit wraparound when lim == 0xffffffff,
and avoids the unused base_addr variable.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119055747.23819-1-weichen.chen@linux.alibaba.com?part=1
prev parent reply other threads:[~2026-11-19 6:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 5:57 [PATCH v2] KVM: x86: Fix stalled descriptor table accesses to MMIO weichenchen
2026-11-19 6:21 ` 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=sashiko-outbox-222518@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=weichen.chen@linux.alibaba.com \
/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