Skip to content

Commit 59eb886

Browse files
committed
KVM: arm64: Fix nested S2 MMU structures reallocation
jira VULN-187401 cve-pre CVE-2026-46317 commit-author Marc Zyngier <maz@kernel.org> commit 5417a2e For each vcpu that userspace creates, we allocate a number of s2_mmu structures that will eventually contain our shadow S2 page tables. Since this is a dynamically allocated array, we reallocate the array and initialise the newly allocated elements. Once everything is correctly initialised, we adjust pointer and size in the kvm structure, and move on. But should that initialisation fail *and* the reallocation triggered a copy to another location, we end-up returning early, with the kvm structure still containing the (now stale) old pointer. Weeee! Cure it by assigning the pointer early, and use this to perform the initialisation. If everything succeeds, we adjust the size. Otherwise, we just leave the size as it was, no harm done, and the new memory is as good as the ol' one (we hope...). Fixes: 4f128f8 ("KVM: arm64: nv: Support multiple nested Stage-2 mmu structures") Reported-by: Alexander Potapenko <glider@google.com> Tested-by: Alexander Potapenko <glider@google.com> Link: https://lore.kernel.org/r/20250204145554.774427-1-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org> (cherry picked from commit 5417a2e) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent ea98742 commit 59eb886

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

arch/arm64/kvm/nested.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,27 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
6868
if (!tmp)
6969
return -ENOMEM;
7070

71+
swap(kvm->arch.nested_mmus, tmp);
72+
7173
/*
7274
* If we went through a realocation, adjust the MMU back-pointers in
7375
* the previously initialised kvm_pgtable structures.
7476
*/
7577
if (kvm->arch.nested_mmus != tmp)
7678
for (int i = 0; i < kvm->arch.nested_mmus_size; i++)
77-
tmp[i].pgt->mmu = &tmp[i];
79+
kvm->arch.nested_mmus[i].pgt->mmu = &kvm->arch.nested_mmus[i];
7880

7981
for (int i = kvm->arch.nested_mmus_size; !ret && i < num_mmus; i++)
80-
ret = init_nested_s2_mmu(kvm, &tmp[i]);
82+
ret = init_nested_s2_mmu(kvm, &kvm->arch.nested_mmus[i]);
8183

8284
if (ret) {
8385
for (int i = kvm->arch.nested_mmus_size; i < num_mmus; i++)
84-
kvm_free_stage2_pgd(&tmp[i]);
86+
kvm_free_stage2_pgd(&kvm->arch.nested_mmus[i]);
8587

8688
return ret;
8789
}
8890

8991
kvm->arch.nested_mmus_size = num_mmus;
90-
kvm->arch.nested_mmus = tmp;
9192

9293
return 0;
9394
}

0 commit comments

Comments
 (0)