Loading arch/arm/Kconfig.debug +0 −13 Original line number Diff line number Diff line Loading @@ -75,19 +75,6 @@ config DEBUG_USER 8 - SIGSEGV faults 16 - SIGBUS faults config KERNEL_TEXT_RDONLY bool "Set kernel text section pages as read only" depends on FREE_PAGES_RDONLY help The kernel text pages are always mapped in the kernel. This means that anyone can write to the page if they have the address. Enable this option to mark the kernel text pages as read only to trigger a fault if any code attempts to write to a page part of the kernel text section. This may have a performance impact. If unsure, say N. # These options are only for real kernel hackers who want to get their hands dirty. config DEBUG_LL bool "Kernel low-level debugging functions (read help!)" Loading arch/arm/include/asm/cacheflush.h +7 −4 Original line number Diff line number Diff line Loading @@ -508,13 +508,16 @@ int set_memory_rw(unsigned long addr, int numpages); int set_memory_x(unsigned long addr, int numpages); int set_memory_nx(unsigned long addr, int numpages); void flush_uprobe_xol_access(struct page *page, unsigned long uaddr, void *kaddr, unsigned long len); #ifdef CONFIG_KERNEL_TEXT_RDONLY #ifdef CONFIG_DEBUG_RODATA void mark_rodata_ro(void); void set_kernel_text_rw(void); void set_kernel_text_ro(void); #else static inline void set_kernel_text_rw(void) { } static inline void set_kernel_text_ro(void) { } #endif void flush_uprobe_xol_access(struct page *page, unsigned long uaddr, void *kaddr, unsigned long len); #endif arch/arm/include/asm/fixmap.h +6 −2 Original line number Diff line number Diff line Loading @@ -28,6 +28,10 @@ enum fixed_addresses { FIX_KMAP_BEGIN = __end_of_permanent_fixed_addresses, FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS) - 1, /* Support writing RO kernel text via kprobes, jump labels, etc. */ FIX_TEXT_POKE0, FIX_TEXT_POKE1, __end_of_fixed_addresses = (FIXADDR_END - FIXADDR_START) >> PAGE_SHIFT, }; Loading @@ -40,7 +44,7 @@ enum fixed_addresses { extern void __early_set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags); #define __set_fixmap __early_set_fixmap void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot); #include <asm-generic/fixmap.h> Loading arch/arm/kernel/Makefile +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ test-kprobes-objs += kprobes-test-arm.o endif obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o obj-$(CONFIG_ARM_THUMBEE) += thumbee.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_KGDB) += kgdb.o patch.o obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_HAVE_TCM) += tcm.o obj-$(CONFIG_OF) += devtree.o Loading arch/arm/kernel/ftrace.c +19 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ #include <linux/ftrace.h> #include <linux/uaccess.h> #include <linux/module.h> #include <linux/stop_machine.h> #include <asm/cacheflush.h> #include <asm/opcodes.h> Loading @@ -35,6 +36,22 @@ #define OLD_NOP 0xe1a00000 /* mov r0, r0 */ static int __ftrace_modify_code(void *data) { int *command = data; set_kernel_text_rw(); ftrace_modify_all_code(*command); set_kernel_text_ro(); return 0; } void arch_ftrace_update_code(int command) { stop_machine(__ftrace_modify_code, &command, NULL); } static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec) { return rec->arch.old_mcount ? OLD_NOP : NOP; Loading Loading @@ -73,6 +90,8 @@ int ftrace_arch_code_modify_prepare(void) int ftrace_arch_code_modify_post_process(void) { set_all_modules_text_ro(); /* Make sure any TLB misses during machine stop are cleared. */ flush_tlb_all(); return 0; } Loading Loading
arch/arm/Kconfig.debug +0 −13 Original line number Diff line number Diff line Loading @@ -75,19 +75,6 @@ config DEBUG_USER 8 - SIGSEGV faults 16 - SIGBUS faults config KERNEL_TEXT_RDONLY bool "Set kernel text section pages as read only" depends on FREE_PAGES_RDONLY help The kernel text pages are always mapped in the kernel. This means that anyone can write to the page if they have the address. Enable this option to mark the kernel text pages as read only to trigger a fault if any code attempts to write to a page part of the kernel text section. This may have a performance impact. If unsure, say N. # These options are only for real kernel hackers who want to get their hands dirty. config DEBUG_LL bool "Kernel low-level debugging functions (read help!)" Loading
arch/arm/include/asm/cacheflush.h +7 −4 Original line number Diff line number Diff line Loading @@ -508,13 +508,16 @@ int set_memory_rw(unsigned long addr, int numpages); int set_memory_x(unsigned long addr, int numpages); int set_memory_nx(unsigned long addr, int numpages); void flush_uprobe_xol_access(struct page *page, unsigned long uaddr, void *kaddr, unsigned long len); #ifdef CONFIG_KERNEL_TEXT_RDONLY #ifdef CONFIG_DEBUG_RODATA void mark_rodata_ro(void); void set_kernel_text_rw(void); void set_kernel_text_ro(void); #else static inline void set_kernel_text_rw(void) { } static inline void set_kernel_text_ro(void) { } #endif void flush_uprobe_xol_access(struct page *page, unsigned long uaddr, void *kaddr, unsigned long len); #endif
arch/arm/include/asm/fixmap.h +6 −2 Original line number Diff line number Diff line Loading @@ -28,6 +28,10 @@ enum fixed_addresses { FIX_KMAP_BEGIN = __end_of_permanent_fixed_addresses, FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS) - 1, /* Support writing RO kernel text via kprobes, jump labels, etc. */ FIX_TEXT_POKE0, FIX_TEXT_POKE1, __end_of_fixed_addresses = (FIXADDR_END - FIXADDR_START) >> PAGE_SHIFT, }; Loading @@ -40,7 +44,7 @@ enum fixed_addresses { extern void __early_set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags); #define __set_fixmap __early_set_fixmap void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot); #include <asm-generic/fixmap.h> Loading
arch/arm/kernel/Makefile +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ test-kprobes-objs += kprobes-test-arm.o endif obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o obj-$(CONFIG_ARM_THUMBEE) += thumbee.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_KGDB) += kgdb.o patch.o obj-$(CONFIG_ARM_UNWIND) += unwind.o obj-$(CONFIG_HAVE_TCM) += tcm.o obj-$(CONFIG_OF) += devtree.o Loading
arch/arm/kernel/ftrace.c +19 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ #include <linux/ftrace.h> #include <linux/uaccess.h> #include <linux/module.h> #include <linux/stop_machine.h> #include <asm/cacheflush.h> #include <asm/opcodes.h> Loading @@ -35,6 +36,22 @@ #define OLD_NOP 0xe1a00000 /* mov r0, r0 */ static int __ftrace_modify_code(void *data) { int *command = data; set_kernel_text_rw(); ftrace_modify_all_code(*command); set_kernel_text_ro(); return 0; } void arch_ftrace_update_code(int command) { stop_machine(__ftrace_modify_code, &command, NULL); } static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec) { return rec->arch.old_mcount ? OLD_NOP : NOP; Loading Loading @@ -73,6 +90,8 @@ int ftrace_arch_code_modify_prepare(void) int ftrace_arch_code_modify_post_process(void) { set_all_modules_text_ro(); /* Make sure any TLB misses during machine stop are cleared. */ flush_tlb_all(); return 0; } Loading