From: sashiko-bot@kernel.org
To: "Yosry Ahmed" <yosry@kernel.org>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 1/2] KVM: x86: Check EFER validity on KVM_SET_SREGS*
Date: Mon, 13 Jul 2026 18:14:13 +0000 [thread overview]
Message-ID: <20260713181413.94A481F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260713180153.2728382-2-yosry@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the return value of `kvm_x86_call(set_efer)` is ignored in `__set_sregs_common()`, leading to a silent failure when nested state allocation fails.
--
--- Patch [1]: [PATCH v3 1/2] KVM: x86: Check EFER validity on KVM_SET_SREGS* ---
commit 6edd9e84461af3c58ac965b84f89b7c4985ddeb3
Author: Yosry Ahmed <yosry@kernel.org>
KVM: x86: Check EFER validity on KVM_SET_SREGS*
This commit adds checks to validate EFER against both KVM and guest caps
during KVM_SET_SREGS* writes, preventing userspace from writing bogus values
through the per-vendor set_efer callbacks.
> diff --git a/arch/x86/kvm/regs.c b/arch/x86/kvm/regs.c
> index bd8147798cc3e..8f66438989e47 100644
> --- a/arch/x86/kvm/regs.c
> +++ b/arch/x86/kvm/regs.c
[ ... ]
> @@ -564,7 +564,8 @@ static bool kvm_is_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
> }
>
> return kvm_is_valid_cr4(vcpu, sregs->cr4) &&
> - kvm_is_valid_cr0(vcpu, sregs->cr0);
> + kvm_is_valid_cr0(vcpu, sregs->cr0) &&
> + kvm_valid_efer(vcpu, sregs->efer);
> }
>
> static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,
> int *mmu_reset_needed, bool update_pdptrs)
> {
[ ... ]
> vcpu->arch.cr3 = sregs->cr3;
> kvm_register_mark_dirty(vcpu, VCPU_REG_CR3);
> kvm_x86_call(post_set_cr3)(vcpu, sregs->cr3);
>
> *mmu_reset_needed |= vcpu->arch.efer != sregs->efer;
> kvm_x86_call(set_efer)(vcpu, sregs->efer);
[Severity: High]
This isn't a bug introduced by this patch, but should the return value
of kvm_x86_call() be checked here?
If a userspace process calls the KVM_SET_SREGS ioctl with EFER.SVME set,
kvm_x86_call(set_efer) could call into svm_set_efer(), which attempts to
allocate nested state via svm_allocate_nested().
If the system is under memory pressure, this allocation can fail and return
-ENOMEM. Because the return value is ignored in __set_sregs_common(),
doesn't this lead to a silent failure where KVM fails to set the guest's
EFER register but still returns success to userspace?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713180153.2728382-1-yosry@kernel.org?part=1
next prev parent reply other threads:[~2026-07-13 18:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 18:01 [PATCH v3 0/2] KVM: x86: Fix missing EFER validity checks Yosry Ahmed
2026-07-13 18:01 ` [PATCH v3 1/2] KVM: x86: Check EFER validity on KVM_SET_SREGS* Yosry Ahmed
2026-07-13 18:09 ` Yosry Ahmed
2026-07-13 18:14 ` sashiko-bot [this message]
2026-07-13 18:54 ` Yosry Ahmed
2026-07-13 18:01 ` [PATCH v3 2/2] KVM: selftests: Extend set_sregs test to cover EFER Yosry Ahmed
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=20260713181413.94A481F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yosry@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