KVM: arm64: Fix alignment of kvm_hyp_memcache allocations
PATCH 1/1 KVM: arm64: Fix alignment of kvm_hyp_memcache allocations
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.
--- arch/arm64/include/asm/kvm_host.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/include/asm/kvm_host.h +1 -1
@@ -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 ;
Signature · 1 line
2.48.1.502.g6dc24dfdaf-goog
Quoted 8 lines · Quentin Perret
When allocating guest stage-2 page-table pages at EL2, pKVM can consume pages from the host-provided
kvm_hyp_memcache. Aspgtable.cexpects zeroed pages,guest_s2_zalloc_page()actively implements this zeroing with aPAGE_SIZEmemset. 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.[...]
Applied to fixes, thanks!
[1/1] KVM: arm64: Fix alignment of kvm_hyp_memcache allocations
commit: b938731ed2d4eea8e268a27bfc600581fedae2a9
Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.