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 v2 03/10] KVM: x86: Unmap VMAs for KVM-internal memslots when the memslot is freed
Date: Fri, 02 Oct 2026 09:13:41 +0000	[thread overview]
Message-ID: <20261002091342.50ADA1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261001202234.3794060-4-seanjc@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: double unmap of internal memslot VMA causes host UAF
--

commit 120ca6d762cdf95d09e394aff4bb4af6d01288d6
Author: Sean Christopherson <seanjc@google.com>
KVM: x86: Unmap VMAs for KVM-internal memslots when the memslot is freed

This commit unmaps KVM-created VMAs for KVM-internal memslots when the
associated memslot is freed directly, instead of using x86's internal API,
to prevent VMA leaks on teardown.

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 79468ddfe4736..e91bd79dd3cc6 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c

[ ... ]

> @@ -10066,6 +10048,16 @@ void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot)
>  	}
>  
>  	kvm_page_track_free_memslot(slot);
> +
> +	/*
> +	 * Free memory regions allocated on behalf of userspace, unless the
> +	 * memory map has changed due to process exit or fd copying.  Leak the
> +	 * mapping on failure, e.g. if the task is killed, worst case scenario,
> +	 * the page(s) will be reclaimed when the process exits.
> +	 */
> +	if (current->mm == kvm->mm && slot->id >= KVM_USER_MEM_SLOTS &&
> +	    !WARN_ON_ONCE(!slot->npages))
> +		vm_munmap(slot->userspace_addr, slot->npages * PAGE_SIZE);
>  }

[Severity: High]
Does this unconditionally unmap the VMA for every freed internal memslot object,
potentially leading to a double unmap?

In __x86_set_memory_region(), the twin memslot objects are created with the
exact same userspace_addr for each address space:

	for (i = 0; i < kvm_arch_nr_memslot_as_ids(kvm); i++) {
		struct kvm_userspace_memory_region2 m;

		m.slot = id | (i << 16);
		m.flags = 0;
		m.guest_phys_addr = gpa;
		m.userspace_addr = hva;
...

When the VM is destroyed or the memslot is deleted, KVM iterates over all
address spaces and calls kvm_arch_free_memslot() for each memslot object.

Because vm_munmap() is called here without checking if slot->as_id is 0, could
it unmap the same HVA range multiple times?

If a concurrent thread maps memory between the two unmaps, the new memory
might be silently unmapped, potentially leading to memory corruption and
use-after-free in the host.

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

  parent reply	other threads:[~2026-10-02  9:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 20:22 [PATCH v2 00/10] KVM: Fix+harden against bad uaccess using dying VM Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 01/10] KVM: Reject user accesses to guest memory if current->mm != kvm->mm Sean Christopherson
2026-10-01 21:08   ` James Houghton
2026-10-01 21:18     ` Sean Christopherson
2026-10-01 21:28       ` James Houghton
2026-10-01 20:22 ` [PATCH v2 02/10] KVM: PPC: Flush/zap all memslots on kvm_arch_flush_shadow_all() Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 03/10] KVM: x86: Unmap VMAs for KVM-internal memslots when the memslot is freed Sean Christopherson
2026-10-01 21:26   ` James Houghton
2026-10-02  9:13   ` sashiko-bot [this message]
2026-10-02 13:36     ` Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 04/10] KVM: Disallow setting memslots when the VM is being destroyed Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 05/10] KVM: Destroy memslots immediately after mmu_notifiers are unregistered Sean Christopherson
2026-10-02  9:13   ` sashiko-bot
2026-10-02 14:07     ` Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 06/10] KVM: WARN if KVM attempts to do guest-related uaccess with "wrong" process Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 07/10] KVM: WARN and reject guest-based uaccess if VM is dying Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 08/10] KVM: nVMX: Don't flush shadow VMCS12 to guest memory during vCPU teardown Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 09/10] KVM: nVMX: Don't try to load eVMCS12 page when the VM is dying Sean Christopherson
2026-10-01 20:22 ` [PATCH v2 10/10] KVM: Pre-check uaccesses in KVM's APIs to read/write guest memory Sean Christopherson
2026-10-02  9:13   ` sashiko-bot
2026-10-02 13:54     ` Sean Christopherson
2026-10-02 20:30 ` [syzbot ci] Re: KVM: Fix+harden against bad uaccess using dying VM syzbot ci
2026-10-02 20:39   ` 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=20261002091342.50ADA1F000FF@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