Skip to content

Commit 36de1e4

Browse files
rpptakpm00
authored andcommitted
x86/kprobes: enable EXECMEM_ROX_CACHE for kprobes allocations
x86::alloc_insn_page() always allocates ROX memory. Instead of overriding this method, add EXECMEM_KPROBES entry in execmem_info with pgprot set to PAGE_KERNEL_ROX and use ROX cache when configuration and CPU features allow it. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Cc: Daniel Gomez <[email protected]> Cc: Petr Pavlu <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ab674b6 commit 36de1e4

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -481,24 +481,6 @@ static int prepare_singlestep(kprobe_opcode_t *buf, struct kprobe *p,
481481
return len;
482482
}
483483

484-
/* Make page to RO mode when allocate it */
485-
void *alloc_insn_page(void)
486-
{
487-
void *page;
488-
489-
page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE);
490-
if (!page)
491-
return NULL;
492-
493-
/*
494-
* TODO: Once additional kernel code protection mechanisms are set, ensure
495-
* that the page was not maliciously altered and it is still zeroed.
496-
*/
497-
set_memory_rox((unsigned long)page, 1);
498-
499-
return page;
500-
}
501-
502484
/* Kprobe x86 instruction emulation - only regs->ip or IF flag modifiers */
503485

504486
static void kprobe_emulate_ifmodifiers(struct kprobe *p, struct pt_regs *regs)

arch/x86/mm/init.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,14 @@ struct execmem_info __init *execmem_arch_setup(void)
10981098
.pgprot = pgprot,
10991099
.alignment = MODULE_ALIGN,
11001100
},
1101-
[EXECMEM_KPROBES ... EXECMEM_BPF] = {
1101+
[EXECMEM_KPROBES] = {
1102+
.flags = flags,
1103+
.start = start,
1104+
.end = MODULES_END,
1105+
.pgprot = PAGE_KERNEL_ROX,
1106+
.alignment = MODULE_ALIGN,
1107+
},
1108+
[EXECMEM_FTRACE ... EXECMEM_BPF] = {
11021109
.flags = EXECMEM_KASAN_SHADOW,
11031110
.start = start,
11041111
.end = MODULES_END,

0 commit comments

Comments
 (0)