Skip to content

Commit 17da30e

Browse files
committed
linux-kernel: modkernel_ffi: Use __vmalloc_node_range() to allocate PAGE_KERNEL_EXEC pages in new kernels.
1 parent 7a3a010 commit 17da30e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ports/linux-kernel/modkernel_ffi.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#define pr_fmt(fmt) "MPY: ffi: " fmt
2929

30+
#include <linux/version.h>
3031
#include <linux/kallsyms.h>
3132
#include <linux/module.h>
3233
#include <linux/kprobes.h>
@@ -779,6 +780,17 @@ STATIC const mp_obj_type_t callback_type = {
779780
.locals_dict = (void*)&callback_locals_dict,
780781
};
781782

783+
STATIC void *__vmalloc_exec(size_t size) {
784+
// in 88dca4ca5a the pgprot parameter was removed, so we'll call the lower function.
785+
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 7, 0)
786+
return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL_EXEC);
787+
#else
788+
return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
789+
GFP_KERNEL, PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
790+
__builtin_return_address(0));
791+
#endif
792+
}
793+
782794
STATIC mp_obj_t kernel_ffi_callback(mp_obj_t func) {
783795
size_t nargs = check_func_for_cb(func, false);
784796

@@ -799,7 +811,7 @@ STATIC mp_obj_t kernel_ffi_callback(mp_obj_t func) {
799811
u8 push_rax[1];
800812
u8 movabs_rax_parameter[10];
801813
u8 ret[1];
802-
} __attribute__((packed)) *trampoline = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
814+
} __attribute__((packed)) *trampoline = __vmalloc_exec(PAGE_SIZE);
803815
if (NULL == trampoline) {
804816
mp_raise_OSError(0);
805817
}
@@ -834,7 +846,7 @@ STATIC mp_obj_t kernel_ffi_callback(mp_obj_t func) {
834846
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
835847
};
836848

837-
u8 *trampoline = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
849+
u8 *trampoline = __vmalloc_exec(PAGE_SIZE);
838850
if (NULL == trampoline) {
839851
mp_raise_OSError(0);
840852
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy