From 4e40ef62eec6fc5e4780988c2e246308b4a49fee Mon Sep 17 00:00:00 2001 From: Jan Andres Date: Fri, 4 Sep 2020 10:53:10 +0200 Subject: [PATCH] Fix NX bit handling for Linux 5.8+ Do not use vmap() to map the cross page, it needs to be executable and vmap() unconditionally sets the NX bit starting with commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable") in 5.8-rc1. Emulate previous behavior of vmap() by using alloc_vm_area() and explicitly setting the PTE. --- vmmon-only/linux/hostif.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/vmmon-only/linux/hostif.c b/vmmon-only/linux/hostif.c index 66979fb..3d6d3e0 100644 --- a/vmmon-only/linux/hostif.c +++ b/vmmon-only/linux/hostif.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -624,7 +625,24 @@ HostIF_FastClockUnlock(int callerID) // IN static void * MapCrossPage(struct page *p) // IN: { +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0) return vmap(&p, 1, VM_MAP, VM_PAGE_KERNEL_EXEC); +#else + /* Starting with 5.8, vmap() always sets the NX bit, but the cross + * page needs to be executable. */ + pte_t *ptes[1]; + struct vm_struct *area = alloc_vm_area(1UL << PAGE_SHIFT, ptes); + if (area == NULL) + return NULL; + + set_pte(ptes[0], mk_pte(p, VM_PAGE_KERNEL_EXEC)); + + preempt_disable(); + __flush_tlb_all(); + preempt_enable(); + + return area->addr; +#endif }