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.
This commit is contained in:
Jan Andres authored and Michal Kubecek committed 2020-09-19 21:58:43 +02:00
1 parent 11bf1a7d96
commit 4e40ef62ee
1 file changed
+18
+18
View File
@@ -47,6 +47,7 @@
#include <asm/asm.h>
#include <asm/io.h>
#include <asm/page.h>
#include <asm/tlbflush.h>
#include <asm/uaccess.h>
#include <asm/irq_vectors.h>
#include <linux/capability.h>
@@ -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
}