From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 3/8] KVM: x86: Manually check DR4/5 write values to fix SVM intercept priority
Date: Fri, 12 Jun 2026 23:28:28 +0000 [thread overview]
Message-ID: <20260612232829.482311F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612230113.684301-4-seanjc@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Lack of canonical address checks for DR0-DR3 writes allows malicious userspace or guests to crash the host kernel, and breaks nested virtualization exception priorities.
--
commit 85827e7c2e927fda473c503a8703cddac0182bb8
Author: Sean Christopherson <seanjc@google.com>
KVM: x86: Manually check DR4/5 write values to fix SVM intercept priority
This patch manually pre-checks values written to DR4/5 (DR6/DR7 aliases) to
avoid relying on ->set_dr() for #GP signaling. This fixes an SVM intercept
priority issue where nSVM relies on the emulator to perform exception checks.
> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
> index 4484c5fa19e33..a1bccab0eefee 100644
> --- a/arch/x86/kvm/emulate.c
> +++ b/arch/x86/kvm/emulate.c
> @@ -3853,15 +3853,23 @@ static int check_dr_read(struct x86_emulate_ctxt *ctxt)
> static int check_dr_write(struct x86_emulate_ctxt *ctxt)
> {
> u64 new_val = ctxt->src.val64;
> - int dr = ctxt->modrm_reg;
> int rc;
>
> rc = check_dr_read(ctxt);
> if (rc != X86EMUL_CONTINUE)
> return rc;
>
> - if ((dr == 6 || dr == 7) && (new_val & 0xffffffff00000000ULL))
> - return emulate_gp(ctxt, 0);
> + switch (ctxt->modrm_reg) {
> + case 4:
> + case 5:
> + case 6:
> + case 7:
> + if (new_val & 0xffffffff00000000ULL)
> + return emulate_gp(ctxt, 0);
> + break;
> + default:
> + break;
[Severity: Critical]
This is a pre-existing issue, but does this code need to check for canonical
addresses on DR0-DR3?
If a malicious guest forces instruction emulation of a write to DR0-DR3 with a
non-canonical address, this default case allows it to return X86EMUL_CONTINUE.
Since kvm_set_dr() also doesn't check for canonical addresses on DR0-DR3,
could this allow a non-canonical value to be written to vcpu->arch.db[0..3]?
If hardware breakpoints are active, KVM restores these registers using
set_debugreg(), which eventually calls native_set_debugreg():
arch/x86/include/asm/debugreg.h:native_set_debugreg() {
...
case 0:
asm("mov %0, %%db0" ::"r" (value));
break;
...
}
Because this inline assembly lacks an exception table entry (_ASM_EXTABLE),
could writing a non-canonical address generate an unhandled #GP in host
kernel mode and crash the host?
Additionally, by omitting the #GP check in the emulator, would this incorrectly
synthesize a VM-exit to L1 instead of injecting a #GP to L2, breaking nested
virtualization exception priorities on SVM?
> + }
>
> return X86EMUL_CONTINUE;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260612230113.684301-1-seanjc@google.com?part=3
next prev parent reply other threads:[~2026-06-12 23:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-12 23:01 [PATCH v3 0/8] KVM: x86: Fix emulated MOV DR{4,5} #GP bugs Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 1/8] KVM: x86: Treat any non-zero return from set_dr() as a faulting condition Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 2/8] KVM: x86: Prioritize DR7.GD #DB over #GP due to illegal DR6/7 value Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 3/8] KVM: x86: Manually check DR4/5 write values to fix SVM intercept priority Sean Christopherson
2026-06-12 23:28 ` sashiko-bot [this message]
2026-06-12 23:01 ` [PATCH v3 4/8] KVM: x86: Prioritize #UD on MOV DR over #GP due to non-zero CPL Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 5/8] KVM: VMX: Prioritize DR7.GD=1 #DB over CPL>0 #GP on Intel Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 6/8] KVM: x86: Use kvm_dr{6,7}_valid() to check DR{4,5,6,7} write values in emulator Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 7/8] KVM: x86: WARN if MOV DR emulation hits a "too late" #GP Sean Christopherson
2026-06-12 23:01 ` [PATCH v3 8/8] KVM: x86: Read CR4.DE in emulator if and only if accessing DR4 or DR5 Sean Christopherson
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=20260612232829.482311F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=seanjc@google.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