[PATCH 2/3] KVM: arm64: Check the host stage-2 PGD allocation for NULL
From: Xuheng Li via B4 Relay
Date: Thu Nov 05 2026 - 17:33:38 EST
From: Xuheng Li <xuheng@xxxxxxxxxxxxxxx>
host_s2_zalloc_pages_exact() passes the result of hyp_alloc_pages() to
hyp_split_page(hyp_virt_to_page(addr)) without checking it for NULL.
If the host stage-2 pool cannot supply the PGD, hyp_virt_to_page(NULL)
yields a bogus struct hyp_page, and hyp_split_page() reads and writes
through it, which ends in a hyp panic during pKVM initialisation
although kvm_pgtable_stage2_init() is prepared to fail with -ENOMEM.
The pool is sized so that this allocation, the first one made from it,
cannot fail, so nothing in mainline reaches this path once the pool
size is computed correctly. Return NULL early anyway, so that a
mis-sized pool makes initialisation fail cleanly.
Signed-off-by: Xuheng Li <xuheng@xxxxxxxxxxxxxxx>
---
arch/arm64/kvm/hyp/nvhe/mem_protect.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
index d4c332a91..ee0848f2e 100644
--- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c
+++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c
@@ -85,6 +85,9 @@ static void *host_s2_zalloc_pages_exact(size_t size)
{
void *addr = hyp_alloc_pages(&host_s2_pool, get_order(size));
+ if (!addr)
+ return NULL;
+
hyp_split_page(hyp_virt_to_page(addr));
/*
--
2.53.0