From: Dan Carpenter <error27@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Sean Christopherson" <seanjc@google.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
"Karthik Bhargavan" <karthik@pereq.eu>,
"Clément Blaudeau" <clement@cryspen.com>
Subject: [PATCH] KVM: nVMX: Prevent potential user space corruption
Date: Mon, 9 Nov 2026 08:38:47 +0300 [thread overview]
Message-ID: <dab486f129c36ba1cfb322ceb56ec6fdef020ca3.1793959700.git.dan@cryspen.com> (raw)
At the start of the function it does:
if (is_guest_mode(vcpu) &&
nested_cpu_has_shadow_vmcs(vmcs12) &&
vmcs12->vmcs_link_pointer != INVALID_GPA)
kvm_state.size += sizeof(user_vmx_nested_state->shadow_vmcs12);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This says if the three conditions: is_guest_mode(),
nested_cpu_has_shadow_vmcs() and != INVALID_GPA are met then we are
copying sizeof(shadow_vmcs12), which is 4k, bytes to the user.
Later, we check if the user has enough space to handle the copy and
if "user_data_size" is too small we bail out.
if (user_data_size < kvm_state.size)
goto out;
But at the end of the function it accidentally left out the
is_guest_mode() part of the condition so potentially we could copy more
than "user_data_size" bytes which would result in userspace corruption.
Presumably, users normally allocate enough space and we don't often
corrupt memory in practice.
Add the is_guest_mode() condition to fix this bug.
Fixes: fa58a9fa7497 ("KVM: nVMX: include shadow vmcs12 in nested state")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan@cryspen.com>
---
This bug was found through our formal analysis work at Pereq.eu.
I do not view this as a very serious bug because it requires userspace's
participation in corrupting itself. Userspace can corrupt itself
directly if it wants. However Claude says it cannot share the
reproducer for this bug to anyone under any circumstances so I have not
been able to test a before and after. I have run the kvm-tests on a
patched kernel.
arch/x86/kvm/vmx/nested.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 879183c1bfa5..a9c126f702d6 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -6878,7 +6878,8 @@ static int vmx_get_nested_state(struct kvm_vcpu *vcpu,
if (copy_to_user(user_vmx_nested_state->vmcs12, vmcs12, VMCS12_SIZE))
return -EFAULT;
- if (nested_cpu_has_shadow_vmcs(vmcs12) &&
+ if (is_guest_mode(vcpu) &&
+ nested_cpu_has_shadow_vmcs(vmcs12) &&
vmcs12->vmcs_link_pointer != INVALID_GPA) {
if (copy_to_user(user_vmx_nested_state->shadow_vmcs12,
get_shadow_vmcs12(vcpu), VMCS12_SIZE))
--
2.53.0
next reply other threads:[~2026-11-09 5:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 5:38 Dan Carpenter [this message]
2026-11-09 5:50 ` Dan Carpenter
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=dab486f129c36ba1cfb322ceb56ec6fdef020ca3.1793959700.git.dan@cryspen.com \
--to=error27@gmail.com \
--cc=bp@alien8.de \
--cc=clement@cryspen.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=karthik@pereq.eu \
--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
all inboxes | Powered by JetHome®