Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Dan Carpenter <dan@pereq.eu>
Cc: Priyanka Mani <priyankamani2100@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org,  linux-kernel@vger.kernel.org,
	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>
Subject: Re: [PATCH] KVM: nSVM: Check full nested state size before writing to user buffer
Date: Thu, 12 Nov 2026 08:44:50 -0800	[thread overview]
Message-ID: <avXtAsi3Llq6Ua1n@google.com> (raw)
In-Reply-To: <avWnci8x0fn_4ck-@stanley.mountain>

On Thu, Nov 12, 2026, Dan Carpenter wrote:
> On Thu, Nov 12, 2026 at 06:41:43AM +0000, Priyanka Mani wrote:
> > svm_get_nested_state() compares the userspace-provided buffer size against
> > kvm_state.size before adding KVM_STATE_NESTED_SVM_VMCB_SIZE for a vCPU that
> > is in guest mode.  When L2 is active and userspace passes a size that is
> > large enough for the header but too small for the vmcb12 payload, KVM thus
> > skips the early exit, copies out the header, clears and fills the full 4KiB
> > vmcb12 area past the end of the buffer described by userspace, and only
> > then does the caller notice that the returned size is larger than the
> > provided one and fail with -E2BIG.
> > 
> > As a result, KVM writes up to 4KiB beyond the buffer userspace said it
> > has, and if that memory isn't mapped, the ioctl fails with -EFAULT instead
> > of the documented -E2BIG without reporting the required size.
> > 
> > Compute the full size before the check, as vmx_get_nested_state() does, so
> > that a too-small buffer is rejected without writing anything to it.
> 
> I would prefer to instead move the if (user_data_size < kvm_state.size)
> check until right before the copy_to_user().  It's more future proof
> that way.

+1

Side topic, your mail got flagged by gmail with:

  This message isn't authenticated and the sender can't be verified.

      reply	other threads:[~2026-11-12 16:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  6:41 [PATCH] KVM: nSVM: Check full nested state size before writing to user buffer Priyanka Mani
2026-11-12  6:48 ` sashiko-bot
2026-11-12 16:42   ` Sean Christopherson
2026-11-12 11:48 ` Dan Carpenter
2026-11-12 16:44   ` Sean Christopherson [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=avXtAsi3Llq6Ua1n@google.com \
    --to=seanjc@google.com \
    --cc=bp@alien8.de \
    --cc=dan@pereq.eu \
    --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=priyankamani2100@gmail.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