From: Kayra Cizmeci <kayracizmeci@gmail.com>
To: seanjc@google.com, pbonzini@redhat.com
Cc: tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Kayra Cizmeci <kayracizmeci@gmail.com>
Subject: [PATCH v3 2/2] KVM: x86: Add limit check to IDT in __emulate_int_real()
Date: Sun, 2 Aug 2026 16:44:28 +0300 [thread overview]
Message-ID: <20260802134428.69252-2-kayracizmeci@gmail.com> (raw)
In-Reply-To: <20260802134428.69252-1-kayracizmeci@gmail.com>
Currently there are no limit check at __emulate_int_real(),
and normally greater numbers than the IDT limits needs to
cause a #GP, but currently there is no limit check for doing that.
So add a limit check for IDT to catch greater numbers than the IDT
limit and if the number is greater than the IDT limit inject a #GP.
Signed-off-by: Kayra Cizmeci <kayracizmeci@gmail.com>
---
v1: adds IDT limit check to __emulate_int_real(), link:
https://lore.kernel.org/kvm/20260608123503.23298-1-kayracizmeci@gmail.com/
v2: fixes the sign-extension of INT n, link:
https://lore.kernel.org/kvm/20260608134642.25849-1-kayracizmeci@gmail.com/
v3: rewrote commit messages, split 1 commit into 2 commits and rebased
onto current mainline.
arch/x86/kvm/emulate.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index ec3138801bb7..68d099131d47 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -2023,7 +2023,11 @@ static int __emulate_int_real(struct x86_emulate_ctxt *ctxt, int irq)
gva_t eip_addr;
u16 cs, eip;
- /* TODO: Add limit checks */
+ ops->get_idt(ctxt, &dt);
+
+ if (dt.size < (irq << 2) + 3)
+ return emulate_gp(ctxt, 0);
+
ctxt->src.val = ctxt->eflags;
rc = em_push(ctxt);
if (rc != X86EMUL_CONTINUE)
@@ -2041,8 +2045,6 @@ static int __emulate_int_real(struct x86_emulate_ctxt *ctxt, int irq)
if (rc != X86EMUL_CONTINUE)
return rc;
- ops->get_idt(ctxt, &dt);
-
eip_addr = dt.address + (irq << 2);
cs_addr = dt.address + (irq << 2) + 2;
--
2.53.0
next prev parent reply other threads:[~2026-08-02 13:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 13:44 [PATCH v3 1/2] KVM: x86: Fix sign-extension of the INT n vector in the emulator Kayra Cizmeci
2026-08-02 13:44 ` Kayra Cizmeci [this message]
2026-08-24 8:45 ` [PATCH v3 2/2] KVM: x86: Add limit check to IDT in __emulate_int_real() Kayra Cizmeci
2026-09-13 16:47 ` Kayra Cizmeci
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=20260802134428.69252-2-kayracizmeci@gmail.com \
--to=kayracizmeci@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/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