[PATCH v10 04/10] powerpc/kprobes: Mark newly allocated probes as ROX
Christophe Leroy
christophe.leroy at csgroup.eu
Tue Mar 30 16:05:47 AEDT 2021
Le 30/03/2021 à 06:51, Jordan Niethe a écrit :
> From: Russell Currey <ruscur at russell.cc>
>
> Add the arch specific insn page allocator for powerpc. This allocates
> ROX pages if STRICT_KERNEL_RWX is enabled. These pages are only written
> to with patch_instruction() which is able to write RO pages.
>
> Reviewed-by: Daniel Axtens <dja at axtens.net>
> Signed-off-by: Russell Currey <ruscur at russell.cc>
> Signed-off-by: Christophe Leroy <christophe.leroy at csgroup.eu>
> [jpn: Reword commit message, switch to __vmalloc_node_range()]
> Signed-off-by: Jordan Niethe <jniethe5 at gmail.com>
> ---
> v9: - vmalloc_exec() no longer exists
> - Set the page to RW before freeing it
> v10: - use __vmalloc_node_range()
> ---
> arch/powerpc/kernel/kprobes.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
> index 01ab2163659e..3ae27af9b094 100644
> --- a/arch/powerpc/kernel/kprobes.c
> +++ b/arch/powerpc/kernel/kprobes.c
> @@ -25,6 +25,7 @@
> #include <asm/sections.h>
> #include <asm/inst.h>
> #include <linux/uaccess.h>
> +#include <linux/vmalloc.h>
>
> DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
> DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
> @@ -103,6 +104,19 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset)
> return addr;
> }
>
> +void *alloc_insn_page(void)
> +{
> + if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) {
> + return __vmalloc_node_range(PAGE_SIZE, 1, MODULES_VADDR, MODULES_END,
> + GFP_KERNEL, PAGE_KERNEL_ROX, VM_FLUSH_RESET_PERMS,
> + NUMA_NO_NODE, __builtin_return_address(0));
> + } else {
> + return __vmalloc_node_range(PAGE_SIZE, 1, MODULES_VADDR, MODULES_END,
> + GFP_KERNEL, PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS,
> + NUMA_NO_NODE, __builtin_return_address(0));
> + }
> +}
> +
What about
void *alloc_insn_page(void)
{
pgprot_t prot = IS_ENABLED(CONFIG_STRICT_KERNEL_RWX) ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
return __vmalloc_node_range(PAGE_SIZE, 1, MODULES_VADDR, MODULES_END,
GFP_KERNEL, prot, VM_FLUSH_RESET_PERMS,
NUMA_NO_NODE, __builtin_return_address(0));
}
> int arch_prepare_kprobe(struct kprobe *p)
> {
> int ret = 0;
>
More information about the Linuxppc-dev
mailing list