From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v2 2/2] KVM: arm64: nv: Fix null ptr deref on nested wp/unmap, teardown race
Date: Sat, 22 Aug 2026 18:05:56 +0000 [thread overview]
Message-ID: <20260822180557.762691F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260822-kvm-arm-nested-virt-fix-v2-2-ac4059a0eaa6@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free of `kvm->arch.nested_mmus` array during nested page table walks
- [High] Memory Leak of `kvm->arch.nested_mmus` on VM teardown via fd closure
--
--- Patch [2]: [PATCH v2 2/2] KVM: arm64: nv: Fix null ptr deref on nested wp/unmap, teardown race ---
commit 82456f58d55471e0202bc28188ae985c14d4be0a
Author: Lorenzo Stoakes (ARM) <ljs@kernel.org>
KVM: arm64: nv: Fix null ptr deref on nested wp/unmap, teardown race
This commit fixes a NULL pointer dereference in the nested page table walk
paths. It resolves a race condition where concurrent stage 2 teardown can set
the page table pointer to NULL while the MMU lock is temporarily dropped.
> diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> index 17123f0b6daba..f69722e1592a5 100644
> --- a/arch/arm64/kvm/nested.c
> +++ b/arch/arm64/kvm/nested.c
[ ... ]
> @@ -1295,7 +1306,7 @@ void kvm_nested_s2_unmap(struct kvm *kvm, bool may_block)
> kvm_stage2_unmap_range(mmu, 0, kvm_phys_size(mmu), may_block);
[Severity: High]
This isn't a bug introduced by this patch, but can this lead to a
use-after-free of the mmu pointer?
When we pass the array element pointer down the call chain:
kvm_nested_s2_unmap()
-> kvm_stage2_unmap_range()
-> __unmap_stage2_range()
-> stage2_apply_range()
stage2_apply_range() can drop kvm->mmu_lock by calling
cond_resched_rwlock_write().
Concurrently, kvm_vcpu_init_nested() can reallocate and free the
kvm->arch.nested_mmus array, or kvm_arch_flush_shadow_all() can free it
locklessly. When stage2_apply_range() reacquires the lock, could it
dereference the dangling mmu pointer?
[Severity: High]
This is a pre-existing issue, but does kvm->arch.nested_mmus leak during VM
teardown via fd closure?
It looks like the array is currently only freed in kvm_arch_flush_shadow_all(),
which is triggered exclusively by the MMU notifier's release hook.
If a VM is closed via file descriptor, mmu_notifier_unregister() is called
which does not invoke the release callback. Since kvm_arch_destroy_vm() doesn't
appear to clean up the nested_mmus array, is this memory permanently orphaned?
> }
>
> - kvm_invalidate_vncr_ipa(kvm, 0, BIT(kvm->arch.mmu.pgt->ia_bits));
> + kvm_invalidate_vncr_ipa_all(kvm);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260822-kvm-arm-nested-virt-fix-v2-0-ac4059a0eaa6@kernel.org?part=2
next prev parent reply other threads:[~2026-08-22 18:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 17:46 [PATCH v2 0/2] KVM: arm64: Fix spurious warn, null ptr deref on S2 teardown race Lorenzo Stoakes (ARM)
2026-08-22 17:46 ` [PATCH v2 1/2] KVM: arm64: Fix spurious warning for benign stage 2 " Lorenzo Stoakes (ARM)
2026-08-22 18:02 ` sashiko-bot
2026-08-23 5:38 ` Yao Yuan
2026-08-24 13:29 ` Lorenzo Stoakes (ARM)
2026-08-22 17:46 ` [PATCH v2 2/2] KVM: arm64: nv: Fix null ptr deref on nested wp/unmap, " Lorenzo Stoakes (ARM)
2026-08-22 18:05 ` sashiko-bot [this message]
2026-08-23 7:53 ` [PATCH v2 0/2] KVM: arm64: Fix spurious warn, null ptr deref on S2 " Marc Zyngier
2026-08-24 13:15 ` Lorenzo Stoakes (ARM)
2026-08-24 15:56 ` Marc Zyngier
2026-08-24 17:34 ` Lorenzo Stoakes (ARM)
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=20260822180557.762691F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=ljs@kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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