From: Andrew Cooper Date: Tue, 20 Jun 2017 18:18:54 +0000 (+0100) Subject: x86/grant: Disallow misaligned PTEs X-Git-Tag: archive/raspbian/4.8.1-1+rpi1+deb9u3^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2931be464330f4e78c7bf0aa9b79afb806930907;p=xen.git x86/grant: Disallow misaligned PTEs Pagetable entries must be aligned to function correctly. Disallow attempts from the guest to have a grant PTE created at a misaligned address, which would result in corruption of the L1 table with largely-guest-controlled values. This is XSA-227 Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Gbp-Pq: Name x86grant-disallow-misaligned-ptes --- diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index afc65d4c8b..50b2fc4e19 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -3965,6 +3965,9 @@ static int create_grant_pte_mapping( l1_pgentry_t ol1e; struct domain *d = v->domain; + if ( !IS_ALIGNED(pte_addr, sizeof(nl1e)) ) + return GNTST_general_error; + adjust_guest_l1e(nl1e, d); gmfn = pte_addr >> PAGE_SHIFT; @@ -4022,6 +4025,16 @@ static int destroy_grant_pte_mapping( struct page_info *page; l1_pgentry_t ol1e; + /* + * addr comes from Xen's active_entry tracking so isn't guest controlled, + * but it had still better be PTE-aligned. + */ + if ( !IS_ALIGNED(addr, sizeof(ol1e)) ) + { + ASSERT_UNREACHABLE(); + return GNTST_general_error; + } + gmfn = addr >> PAGE_SHIFT; page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);