Skip to content

Commit 1b750c2

Browse files
rpptmcgrof
authored andcommitted
powerpc: extend execmem_params for kprobes allocations
powerpc overrides kprobes::alloc_insn_page() to remove writable permissions when STRICT_MODULE_RWX is on. Add definition of EXECMEM_KRPOBES to execmem_params to allow using the generic kprobes::alloc_insn_page() with the desired permissions. As powerpc uses breakpoint instructions to inject kprobes, it does not need to constrain kprobe allocations to the modules area and can use the entire vmalloc address space. Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
1 parent e2effa2 commit 1b750c2

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

arch/powerpc/kernel/kprobes.c

-20
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offse
126126
return (kprobe_opcode_t *)(addr + offset);
127127
}
128128

129-
void *alloc_insn_page(void)
130-
{
131-
void *page;
132-
133-
page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE);
134-
if (!page)
135-
return NULL;
136-
137-
if (strict_module_rwx_enabled()) {
138-
int err = set_memory_rox((unsigned long)page, 1);
139-
140-
if (err)
141-
goto error;
142-
}
143-
return page;
144-
error:
145-
execmem_free(page);
146-
return NULL;
147-
}
148-
149129
int arch_prepare_kprobe(struct kprobe *p)
150130
{
151131
int ret = 0;

arch/powerpc/kernel/module.c

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static struct execmem_info execmem_info __ro_after_init;
9494

9595
struct execmem_info __init *execmem_arch_setup(void)
9696
{
97+
pgprot_t kprobes_prot = strict_module_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
9798
pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC;
9899
unsigned long fallback_start = 0, fallback_end = 0;
99100
unsigned long start, end;
@@ -132,6 +133,12 @@ struct execmem_info __init *execmem_arch_setup(void)
132133
.fallback_start = fallback_start,
133134
.fallback_end = fallback_end,
134135
},
136+
[EXECMEM_KPROBES] = {
137+
.start = VMALLOC_START,
138+
.end = VMALLOC_END,
139+
.pgprot = kprobes_prot,
140+
.alignment = 1,
141+
},
135142
[EXECMEM_MODULE_DATA] = {
136143
.start = VMALLOC_START,
137144
.end = VMALLOC_END,

0 commit comments

Comments
 (0)