]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: arm64: Fix alignment of kvm_hyp_memcache allocations
authorQuentin Perret <qperret@google.com>
Thu, 13 Feb 2025 15:36:14 +0000 (15:36 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 13 Feb 2025 17:57:27 +0000 (17:57 +0000)
When allocating guest stage-2 page-table pages at EL2, pKVM can consume
pages from the host-provided kvm_hyp_memcache. As pgtable.c expects
zeroed pages, guest_s2_zalloc_page() actively implements this zeroing
with a PAGE_SIZE memset. Unfortunately, we don't check the page
alignment of the host-provided address before doing so, which could
lead to the memset overrunning the page if the host was malicious.

Fix this by simply force-aligning all kvm_hyp_memcache allocations to
page boundaries.

Fixes: 60dfe093ec13 ("KVM: arm64: Instantiate guest stage-2 page-tables at EL2")
Reported-by: Ben Simner <ben.simner@cl.cam.ac.uk>
Signed-off-by: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20250213153615.3642515-1-qperret@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_host.h

index c77acc99045764cf5230f84ef5c9f8432c7d983e..3a7ec98ef123807bf76a5dce86839acae3d577e0 100644 (file)
@@ -100,7 +100,7 @@ static inline void push_hyp_memcache(struct kvm_hyp_memcache *mc,
 static inline void *pop_hyp_memcache(struct kvm_hyp_memcache *mc,
                                     void *(*to_va)(phys_addr_t phys))
 {
-       phys_addr_t *p = to_va(mc->head);
+       phys_addr_t *p = to_va(mc->head & PAGE_MASK);
 
        if (!mc->nr_pages)
                return NULL;