powerpc: extend execmem_params for kprobes allocations
authorMike Rapoport (IBM) <rppt@kernel.org>
Sun, 5 May 2024 16:06:23 +0000 (19:06 +0300)
committerLuis Chamberlain <mcgrof@kernel.org>
Tue, 14 May 2024 07:31:43 +0000 (00:31 -0700)
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>
arch/powerpc/kernel/kprobes.c
arch/powerpc/kernel/module.c

index 9fcd01bb2ce6cd957ec9509bc3de2aefb868c49a..14c5ddec305633806df8250a54fba4bb7abbfe35 100644 (file)
@@ -126,26 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offse
        return (kprobe_opcode_t *)(addr + offset);
 }
 
-void *alloc_insn_page(void)
-{
-       void *page;
-
-       page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE);
-       if (!page)
-               return NULL;
-
-       if (strict_module_rwx_enabled()) {
-               int err = set_memory_rox((unsigned long)page, 1);
-
-               if (err)
-                       goto error;
-       }
-       return page;
-error:
-       execmem_free(page);
-       return NULL;
-}
-
 int arch_prepare_kprobe(struct kprobe *p)
 {
        int ret = 0;
index ac80559015a306889adcd076cabea8de80f49e98..2a23cf7e141bac56dc73375212cca76439d0d5f0 100644 (file)
@@ -94,6 +94,7 @@ static struct execmem_info execmem_info __ro_after_init;
 
 struct execmem_info __init *execmem_arch_setup(void)
 {
+       pgprot_t kprobes_prot = strict_module_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
        pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC;
        unsigned long fallback_start = 0, fallback_end = 0;
        unsigned long start, end;
@@ -132,6 +133,12 @@ struct execmem_info __init *execmem_arch_setup(void)
                                .fallback_start = fallback_start,
                                .fallback_end   = fallback_end,
                        },
+                       [EXECMEM_KPROBES] = {
+                               .start  = VMALLOC_START,
+                               .end    = VMALLOC_END,
+                               .pgprot = kprobes_prot,
+                               .alignment = 1,
+                       },
                        [EXECMEM_MODULE_DATA] = {
                                .start  = VMALLOC_START,
                                .end    = VMALLOC_END,