Re: [PATCH 2/2] KVM: arm64: nv: Fix null ptr deref in kvm_nested_s2_unmap() on S2 teardown

"Lorenzo Stoakes (ARM)" <[email protected]>
Newsgroups dev.linux.lists.sashiko-reviews,dev.linux.lists.kvmarm
Message-ID <aomxsuiSpUmHyqu_@gremlin>
On Sat, Aug 22, 2026 at 08:28:18AM +0100, Marc Zyngier wrote:
> On Thu, 13 Aug 2026 16:56:02 +0100,
> "Lorenzo Stoakes (ARM)" <[email protected]> wrote:
> >
> > On Wed, Aug 12, 2026 at 02:01:01PM +0000, [email protected] wrote:
> > > Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> > >
> > > Pre-existing issues:
> > > - [Critical] Use-After-Free on `kvm->arch.nested_mmus` array due to concurrent teardown.
> >
> > Addressed by Marc's changes + discussed over there.
> >
> > > - [Critical] Incomplete Fix: `kvm_nested_s2_wp()` is vulnerable to the same NULL pointer dereference and UAF.
> >
> > OK interesting!
>
> Will you respin this series with kvm_nested_s2_wp() fixed in a similar
> way? Something like below.

Ack yeah, will do!

>
> Thanks,
>
> 	M.
>
> diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> index 00580ba6e8ba0..ebc4f4dc47836 100644
> --- a/arch/arm64/kvm/nested.c
> +++ b/arch/arm64/kvm/nested.c
> @@ -1262,6 +1262,14 @@ void kvm_handle_s1e2_tlbi(struct kvm_vcpu *vcpu, u32 inst, u64 val)
>  	invalidate_vncr_va(vcpu->kvm, &scope);
>  }
>
> +static void kvm_invalidate_vncr_ipa_all(struct kvm *kvm)
> +{
> +	lockdep_assert_held_write(&kvm->mmu_lock);
> +
> +	if (kvm->arch.mmu.pgt)
> +		kvm_invalidate_vncr_ipa(kvm, 0, BIT(kvm->arch.mmu.pgt->ia_bits));
> +}
> +
>  void kvm_nested_s2_wp(struct kvm *kvm)
>  {
>  	int i;
> @@ -1278,7 +1286,7 @@ void kvm_nested_s2_wp(struct kvm *kvm)
>  			kvm_stage2_wp_range(mmu, 0, kvm_phys_size(mmu));
>  	}
>
> -	kvm_invalidate_vncr_ipa(kvm, 0, BIT(kvm->arch.mmu.pgt->ia_bits));
> +	kvm_invalidate_vncr_ipa_all(kvm);
>  }
>
>  void kvm_nested_s2_unmap(struct kvm *kvm, bool may_block)
> @@ -1297,7 +1305,7 @@ void kvm_nested_s2_unmap(struct kvm *kvm, bool may_block)
>  			kvm_stage2_unmap_range(mmu, 0, kvm_phys_size(mmu), may_block);
>  	}
>
> -	kvm_invalidate_vncr_ipa(kvm, 0, BIT(kvm->arch.mmu.pgt->ia_bits));
> +	kvm_invalidate_vncr_ipa_all(kvm);
>  }
>
>  void kvm_nested_s2_flush(struct kvm *kvm)
>
> --
> Without deviation from the norm, progress is not possible.

--
Cheers, Lorenzo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.