Skip to content

Commit 05e85d3

Browse files
KAGA-KOKOgregkh
authored andcommitted
x86/modules: Set VM_FLUSH_RESET_PERMS in module_alloc()
commit 4c4eb3ecc91f4fee6d6bf7cfbc1e21f2e38d19ff upstream. Instead of resetting permissions all over the place when freeing module memory tell the vmalloc code to do so. Avoids the exercise for the next upcoming user. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4e6310e commit 05e85d3

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

arch/x86/kernel/ftrace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
415415
/* ALLOC_TRAMP flags lets us know we created it */
416416
ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP;
417417

418-
set_vm_flush_reset_perms(trampoline);
419-
420418
if (likely(system_state != SYSTEM_BOOTING))
421419
set_memory_ro((unsigned long)trampoline, npages);
422420
set_memory_x((unsigned long)trampoline, npages);

arch/x86/kernel/kprobes/core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ void *alloc_insn_page(void)
427427
if (!page)
428428
return NULL;
429429

430-
set_vm_flush_reset_perms(page);
431430
/*
432431
* First make the page read-only, and only then make it executable to
433432
* prevent it from being W+X in between.

arch/x86/kernel/module.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ void *module_alloc(unsigned long size)
7474
return NULL;
7575

7676
p = __vmalloc_node_range(size, MODULE_ALIGN,
77-
MODULES_VADDR + get_module_load_offset(),
78-
MODULES_END, gfp_mask,
79-
PAGE_KERNEL, VM_DEFER_KMEMLEAK, NUMA_NO_NODE,
80-
__builtin_return_address(0));
77+
MODULES_VADDR + get_module_load_offset(),
78+
MODULES_END, gfp_mask, PAGE_KERNEL,
79+
VM_FLUSH_RESET_PERMS | VM_DEFER_KMEMLEAK,
80+
NUMA_NO_NODE, __builtin_return_address(0));
81+
8182
if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) {
8283
vfree(p);
8384
return NULL;

0 commit comments

Comments
 (0)