Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 1/6] KVM: nVMX: Ensure KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit
Date: Fri, 24 Jul 2026 01:07:07 +0000	[thread overview]
Message-ID: <20260724010707.8CD3C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724004757.131420-2-seanjc@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] An L1 guest can trigger a silent host memory leak (pinned pages and kmap space) by repeatedly executing VMLAUNCH with an invalid guest state.
--

--- Patch [1]: [PATCH 1/6] KVM: nVMX: Ensure KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit ---
commit 529c03d57fc94827c8dfbb4372dfae1313c5dd93
Author: Sean Christopherson <seanjc@google.com>

KVM: nVMX: Ensure KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit

This patch ensures KVM_REQ_GET_NESTED_STATE_PAGES is always checked and 
cleared when emulating a nested VM-Exit. This prevents double-mapping 
vmcs12 pages if KVM manages to bail from VM-Enter without processing the 
request and then emulates VMLAUNCH or VMRESUME.

Cc: stable@vger.kernel.org

> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index b5460de4b1a72..f2518d67e7de5 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -5066,8 +5066,9 @@ void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
>  	/* trying to cancel vmlaunch/vmresume is a bug */
>  	kvm_warn_on_nested_run_pending(vcpu);
>  
> -#ifdef CONFIG_KVM_HYPERV
> +	/* Note, "checking" the request also clears the request. */
>  	if (kvm_check_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu)) {
> +#ifdef CONFIG_KVM_HYPERV

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential memory
leak related to how nested VM-Entry failures handle mapped pages.

If an L1 guest prepares a VMCS12 with valid addresses for mapped pages (like
virtual_apic_page_addr) but intentionally configures an invalid guest state 
(e.g., an invalid CR0 value), nested_vmx_enter_non_root_mode() maps the 
pages before validating the guest state:

arch/x86/kvm/vmx/nested.c:nested_vmx_enter_non_root_mode() {
    ...
    if (nested_vmx_check_guest_state(vcpu, vmcs12,
                                     &entry_failure_code)) {
        exit_reason.basic = EXIT_REASON_INVALID_STATE;
        vmcs12->exit_qualification = entry_failure_code;
        goto vmentry_fail_vmexit;
    }
    ...
}

The error path in vmentry_fail_vmexit synthesizes a VM-Exit back to L1 but 
returns without calling nested_put_vmcs12_pages() to unmap the resources:

arch/x86/kvm/vmx/nested.c:vmentry_fail_vmexit() {
    ...
    if (!from_vmentry)
        return NVMX_VMENTRY_VMEXIT;

    load_vmcs12_host_state(vcpu, vmcs12);
    vmcs12->vm_exit_reason = exit_reason.full;
    ...
    return NVMX_VMENTRY_VMEXIT;
}

If the L1 guest resumes and executes VMLAUNCH again, KVM calls
kvm_vcpu_map() on the already populated map structures:

virt/kvm/kvm_main.c:__kvm_vcpu_map() {
    ...
    map->pinned_page = NULL;
    map->page = NULL;
    map->hva = NULL;
    ...
}

This unconditionally clears the pointers without unmapping or verifying the
previous state, dropping the only KVM reference to the previously pinned
host page and kmap address.

Could a malicious L1 guest repeatedly trigger this in a tight loop to
exhaust host memory and kmap virtual space?

>  		/*
>  		 * KVM_REQ_GET_NESTED_STATE_PAGES is also used to map
>  		 * Enlightened VMCS after migration and we still need to

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724004757.131420-1-seanjc@google.com?part=1

  reply	other threads:[~2026-07-24  1:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  0:47 [PATCH 0/6] KVM: Harden kvm_vcpu_map() usage against memory leaks Sean Christopherson
2026-07-24  0:47 ` [PATCH 1/6] KVM: nVMX: Ensure KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit Sean Christopherson
2026-07-24  1:07   ` sashiko-bot [this message]
2026-07-24  0:47 ` [PATCH 2/6] KVM: nSVM: Add CLASS()es for automagically handling local kvm_vcpu_map() usage Sean Christopherson
2026-07-24  0:47 ` [PATCH 3/6] KVM: nSVM: Use CLASS(kvm_vcpu_map_local) for SMM VMCB mappings Sean Christopherson
2026-07-24  0:47 ` [PATCH 4/6] KVM: nVMX: Use CLASS(kvm_vcpu_map_local_readonly) for MSR bitmap merging Sean Christopherson
2026-07-24  0:47 ` [PATCH 5/6] KVM: PPC: Use CLASS(kvm_vcpu_map_local_readonly) for patching dcbz Sean Christopherson
2026-07-24  1:03   ` sashiko-bot
2026-07-24  1:15     ` Sean Christopherson
2026-07-24  0:47 ` [PATCH 6/6] KVM: Harden kvm_vcpu_map() against double-mapping and thus leaking references Sean Christopherson
2026-07-24  1:11   ` sashiko-bot

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=20260724010707.8CD3C1F000E9@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