kprobes related bugfix
Subsystems (7)
v9 cover kprobes related bugfix
Hi,
Here are the 9th version of the series to fix kprobes not to optimize on the functions in irqentry text ([5/5]). To check the irqentry text always, [4/5] makes irqentry text section unconditional.
This involves some other cleanups on h8300, xtensa, and cris ports, because those sources declare section start/end symbol as single characters, but generic sections.h declares it as character arrays. So it leads build errors if we apply [4/5].
Changes in v9
- Add cris cleanup patch (3/5).
BTW, in this series I just give a minimum fix for arch dependent code, since this is a series to fix a bug in x86 optprobe. However, IMHO, we should revisit these "local _stext/_etext references" and replace it with just including asm/sections.h. And also, I would like to expose is_kernel_text() as a generic routine for arch dependent code so that they can use it.
Thank you,
---
Masami Hiramatsu (5):
h8300: mark _stext and _etext as char-arrays, not single char
xtensa: mark _stext and _end as char-arrays, not single char
cris: mark _stext and _end as char-arrays, not single char
irq: Make irqentry text section unconditional
[BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code
arch/arm/include/asm/traps.h | 7 ------- arch/arm64/include/asm/traps.h | 7 ------- arch/cris/arch-v32/mach-a3/arbiter.c | 4 ++-- arch/cris/arch-v32/mach-fs/arbiter.c | 4 ++-- arch/cris/kernel/traps.c | 6 +++--- arch/h8300/include/asm/traps.h | 6 +++--- arch/x86/entry/entry_64.S | 9 ++------- arch/x86/kernel/kprobes/opt.c | 9 ++++++--- arch/x86/kernel/unwind_frame.c | 2 -- arch/xtensa/kernel/setup.c | 6 +++--- include/asm-generic/sections.h | 4 ++++ include/asm-generic/vmlinux.lds.h | 8 -------- include/linux/interrupt.h | 14 +------------- 13 files changed, 26 insertions(+), 60 deletions(-)
PATCH v9 1/5 h8300: mark _stext and _etext as char-arrays, not single char
Mark _stext and _etext as character arrays instead of single character, as same as include/asm-generic/sections.h does.
--- arch/h8300/include/asm/traps.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/h8300/include/asm/traps.h +3 -3
@@ -33,9 +33,9 @@ extern unsigned long *_interrupt_redirect_table;#define TRAP2_VEC 10#define TRAP3_VEC 11 -extern char _start, _etext; +extern char _start[], _etext[];#define check_kernel_text (addr) \ - ((addr >= (unsigned long)(&_start)) && \ - (addr < (unsigned long)(&_etext)) && !(addr & 1)) + ((addr >= (unsigned long)(_start)) && \ + (addr < (unsigned long)(_etext)) && !(addr & 1))#endif /* _H8300_TRAPS_H */
PATCH v9 2/5 xtensa: mark _stext and _end as char-arrays, not single char
In reply to Masami HiramatsuMark _stext and _end as character arrays instead of single character, as same as include/asm-generic/sections.h does.
--- arch/xtensa/kernel/setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/xtensa/kernel/setup.c +3 -3
@@ -273,8 +273,8 @@ void __init init_arch(bp_tag_t *bp_start)* Initialize system. Setup memory and reserve regions. */ -extern char _end; -extern char _stext; +extern char _end[]; +extern char _stext[];extern char _WindowVectors_text_start;extern char _WindowVectors_text_end;extern char _DebugInterruptVector_literal_start;
@@ -333,7 +333,7 @@ void __init setup_arch(char **cmdline_p) }#endif -mem_reserve (__pa (&_stext),__pa (&_end)); +mem_reserve (__pa (_stext),__pa (_end));#ifdef CONFIG_VECTORS_OFFSET mem_reserve(__pa(&_WindowVectors_text_start),
PATCH v9 3/5 cris: mark _stext and _end as char-arrays, not single char
In reply to Masami HiramatsuMark _stext and _end as character arrays instead of single character, as same as include/asm-generic/sections.h does.
--- arch/cris/arch-v32/mach-a3/arbiter.c | 4 ++-- arch/cris/arch-v32/mach-fs/arbiter.c | 4 ++-- arch/cris/kernel/traps.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
arch/cris/arch-v32/mach-a3/arbiter.c +2 -2
@@ -227,7 +227,7 @@ static void crisv32_arbiter_config(int arbiter, int region, int unused_slots) } } -extern char _stext, _etext; +extern char _stext[], _etext[];static void crisv32_arbiter_init (void ) {
@@ -265,7 +265,7 @@ static void crisv32_arbiter_init(void)#ifndef CONFIG_ETRAX_KGDB /* Global watch for writes to kernel text segment. */ -crisv32_arbiter_watch (virt_to_phys (&_stext), &_etext - &_stext, +crisv32_arbiter_watch (virt_to_phys (_stext), _etext - _stext,MARB_CLIENTS (arbiter_all_clients, arbiter_bar_all_clients), arbiter_all_write,NULL );#endif
arch/cris/arch-v32/mach-fs/arbiter.c +2 -2
@@ -158,7 +158,7 @@ static void crisv32_arbiter_config(int region, int unused_slots) } } -extern char _stext, _etext; +extern char _stext[], _etext[];static void crisv32_arbiter_init (void ) {
@@ -190,7 +190,7 @@ static void crisv32_arbiter_init(void)#ifndef CONFIG_ETRAX_KGDB /* Global watch for writes to kernel text segment. */ -crisv32_arbiter_watch (virt_to_phys (&_stext), &_etext - &_stext, +crisv32_arbiter_watch (virt_to_phys (_stext), _etext - _stext, arbiter_all_clients, arbiter_all_write,NULL );#endif }
arch/cris/kernel/traps.c +3 -3
@@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);void show_trace (unsigned long *stack) {unsigned long addr, module_start, module_end; -extern char _stext, _etext; +extern char _stext[], _etext[];int i;pr_err ("\nCall Trace: " );
@@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)* down the cause of the crash will be able to figure * out the call path that was taken. */ -if (((addr >= (unsigned long )&_stext) && - (addr <= (unsigned long )&_etext)) || +if (((addr >= (unsigned long )_stext) && + (addr <= (unsigned long )_etext)) || ((addr >= module_start) && (addr <= module_end))) {#ifdef CONFIG_KALLSYMS print_ip_sym (addr);
PATCH v9 4/5 irq: Make irqentry text section unconditional
In reply to Masami HiramatsuGenerate irqentry and softirqentry text sections without any configs. This will add above extra sections, but no performace impact.
--- arch/arm/include/asm/traps.h | 7 ------- arch/arm64/include/asm/traps.h | 7 ------- arch/x86/entry/entry_64.S | 9 ++------- arch/x86/kernel/unwind_frame.c | 2 -- include/asm-generic/sections.h | 4 ++++ include/asm-generic/vmlinux.lds.h | 8 -------- include/linux/interrupt.h | 14 +------------- 7 files changed, 7 insertions(+), 44 deletions(-)
arch/arm/include/asm/traps.h +0 -7
@@ -18,7 +18,6 @@ struct undef_hook {void register_undef_hook (struct undef_hook *hook);void unregister_undef_hook (struct undef_hook *hook); -#ifdef CONFIG_FUNCTION_GRAPH_TRACER static inline int __in_irqentry_text (unsigned long ptr) {extern char __irqentry_text_start[];
@@ -27,12 +26,6 @@ static inline int __in_irqentry_text(unsigned long ptr)return ptr >= (unsigned long )&__irqentry_text_start && ptr < (unsigned long )&__irqentry_text_end; } -#else -static inline int __in_irqentry_text (unsigned long ptr) -{ -return 0 ; -} -#endif static inline int in_exception_text (unsigned long ptr) {
arch/arm64/include/asm/traps.h +0 -7
@@ -37,18 +37,11 @@ void unregister_undef_hook(struct undef_hook *hook);void arm64_notify_segfault (struct pt_regs *regs,unsigned long addr); -#ifdef CONFIG_FUNCTION_GRAPH_TRACER static inline int __in_irqentry_text (unsigned long ptr) {return ptr >= (unsigned long )&__irqentry_text_start && ptr < (unsigned long )&__irqentry_text_end; } -#else -static inline int __in_irqentry_text (unsigned long ptr) -{ -return 0 ; -} -#endif static inline int in_exception_text (unsigned long ptr) {
arch/x86/entry/entry_64.S +2 -7
@@ -766,13 +766,8 @@ apicinterrupt3 \num trace(\sym) smp_trace(\sym) #endif /* Make sure APIC interrupt handlers end up in the irqentry section: */ -#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN) -# define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax" -# define POP_SECTION_IRQENTRY .popsection -#else -# define PUSH_SECTION_IRQENTRY -# define POP_SECTION_IRQENTRY -#endif +#define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax" +#define POP_SECTION_IRQENTRY .popsection .macro apicinterrupt num sym do_sym PUSH_SECTION_IRQENTRY
arch/x86/kernel/unwind_frame.c +0 -2
@@ -84,10 +84,8 @@ static bool in_entry_code(unsigned long ip)if (addr >= __entry_text_start && addr < __entry_text_end)return true; -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )if (addr >= __irqentry_text_start && addr < __irqentry_text_end)return true; -#endif return false; }
include/asm-generic/sections.h +4 -0
@@ -27,6 +27,8 @@* __kprobes_text_start, __kprobes_text_end * __entry_text_start, __entry_text_end * __ctors_start, __ctors_end +* __irqentry_text_start, __irqentry_text_end +* __softirqentry_text_start, __softirqentry_text_end */ extern char _text[], _stext[], _etext[];extern char _data[], _sdata[], _edata[];
@@ -39,6 +41,8 @@ extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];extern char __kprobes_text_start[], __kprobes_text_end[];extern char __entry_text_start[], __entry_text_end[];extern char __start_rodata[], __end_rodata[]; +extern char __irqentry_text_start[], __irqentry_text_end[]; +extern char __softirqentry_text_start[], __softirqentry_text_end[];/* Start and end of .ctors section - used for constructor calls. */ extern char __ctors_start[], __ctors_end[];
include/asm-generic/vmlinux.lds.h +0 -8
@@ -483,25 +483,17 @@ *(.entry.text) \ VMLINUX_SYMBOL(__entry_text_end) = .; -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )#define IRQENTRY_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__irqentry_text_start) = .; \ *(.irqentry.text) \ VMLINUX_SYMBOL(__irqentry_text_end) = .; -#else -#define IRQENTRY_TEXT -#endif -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )#define SOFTIRQENTRY_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__softirqentry_text_start) = .; \ *(.softirqentry.text) \ VMLINUX_SYMBOL(__softirqentry_text_end) = .; -#else -#define SOFTIRQENTRY_TEXT -#endif /* Section used for early init (in .S files) */ #define HEAD_TEXT *(.head.text)
include/linux/interrupt.h +1 -13
@@ -18,6 +18,7 @@#include <linux/atomic.h> #include <asm/ptrace.h> #include <asm/irq.h> +#include <asm/sections.h> /* * These correspond to the IORESOURCE_IRQ_* defines in
@@ -726,7 +727,6 @@ extern int early_irq_init(void);extern int arch_probe_nr_irqs (void );extern int arch_early_irq_init (void ); -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )/* * We want to know which function is an entrypoint of a hardirq or a softirq. */
@@ -734,16 +734,4 @@ extern int arch_early_irq_init(void);#define __softirq_entry \ __attribute__((__section__(".softirqentry.text"))) -/* Limits of hardirq entrypoints */ -extern char __irqentry_text_start[]; -extern char __irqentry_text_end[]; -/* Limits of softirq entrypoints */ -extern char __softirqentry_text_start[]; -extern char __softirqentry_text_end[]; - -#else -#define __irq_entry -#define __softirq_entry -#endif -#endif
PATCH v9 5/5 kprobes/x86: Do not jump-optimize kprobes on irq entry code
In reply to Masami HiramatsuSince the kernel segment registers are not prepared at the entry of irq-entry code, if a kprobe on such code is jump-optimized, accessing per-cpu variables may cause kernel panic.
However, if the kprobe is not optimized, it kicks int3 exception and set segment registers correctly.
This checks probe-address and if it is in irq-entry code, it prohibits optimizing such kprobes. This means we can continuously probing such interrupt handlers by kprobes but it is not optimized anymore.
--- arch/x86/kernel/kprobes/opt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/kprobes/opt.c +6 -3
@@ -39,6 +39,7 @@#include <asm/insn.h> #include <asm/debugreg.h> #include <asm/set_memory.h> +#include <asm/sections.h> #include "common.h"
@@ -251,10 +252,12 @@ static int can_optimize(unsigned long paddr)/* * Do not optimize in the entry code due to the unstable -* stack handling. +* stack handling and registers setup. */ -if ((paddr >= (unsigned long )__entry_text_start) && - (paddr < (unsigned long )__entry_text_end)) +if (((paddr >= (unsigned long )__entry_text_start) && + (paddr < (unsigned long )__entry_text_end)) || + ((paddr >= (unsigned long )__irqentry_text_start) && + (paddr < (unsigned long )__irqentry_text_end)))return 0 ;/* Check there is enough space for a relative jump. */
tip-bot for Masami Hiramatsu
merge bot[tip:perf/core] xtensa: Mark _stext and _end as char-arrays, not single char variables
In reply to Masami Hiramatsuxtensa: Mark _stext and _end as char-arrays, not single char variables
Commit-ID: 1824436262b2f43a46051a4958e2dd58a9d9aadf Gitweb: http://git.kernel.org/tip/1824436262b2f43a46051a4958e2dd58a9d9aadf Author: Masami Hiramatsu <[email protected]> AuthorDate: Thu, 3 Aug 2017 11:36:09 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 10 Aug 2017 16:28:52 +0200
xtensa: Mark _stext and _end as char-arrays, not single char variables
Mark _stext and _end as character arrays instead of single character variables, like include/asm-generic/sections.h does.
--- arch/xtensa/kernel/setup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/xtensa/kernel/setup.c +3 -3
@@ -273,8 +273,8 @@ void __init init_arch(bp_tag_t *bp_start)* Initialize system. Setup memory and reserve regions. */ -extern char _end; -extern char _stext; +extern char _end[]; +extern char _stext[];extern char _WindowVectors_text_start;extern char _WindowVectors_text_end;extern char _DebugInterruptVector_literal_start;
@@ -333,7 +333,7 @@ void __init setup_arch(char **cmdline_p) }#endif -mem_reserve (__pa (&_stext),__pa (&_end)); +mem_reserve (__pa (_stext),__pa (_end));#ifdef CONFIG_VECTORS_OFFSET mem_reserve(__pa(&_WindowVectors_text_start),
tip-bot for Masami Hiramatsu
merge bot[tip:perf/core] h8300: Mark _stext and _etext as char-arrays, not single char variables
In reply to Masami Hiramatsuh8300: Mark _stext and _etext as char-arrays, not single char variables
Commit-ID: b4464bf977004832f63f31c015751c049bc47dde Gitweb: http://git.kernel.org/tip/b4464bf977004832f63f31c015751c049bc47dde Author: Masami Hiramatsu <[email protected]> AuthorDate: Thu, 3 Aug 2017 11:35:04 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 10 Aug 2017 16:28:52 +0200
h8300: Mark _stext and _etext as char-arrays, not single char variables
Mark _stext and _etext as character arrays instead of single character variables, like include/asm-generic/sections.h does.
--- arch/h8300/include/asm/traps.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/h8300/include/asm/traps.h +3 -3
@@ -33,9 +33,9 @@ extern unsigned long *_interrupt_redirect_table;#define TRAP2_VEC 10#define TRAP3_VEC 11 -extern char _start, _etext; +extern char _start[], _etext[];#define check_kernel_text (addr) \ - ((addr >= (unsigned long)(&_start)) && \ - (addr < (unsigned long)(&_etext)) && !(addr & 1)) + ((addr >= (unsigned long)(_start)) && \ + (addr < (unsigned long)(_etext)) && !(addr & 1))#endif /* _H8300_TRAPS_H */
tip-bot for Masami Hiramatsu
merge bot[tip:perf/core] cris: Mark _stext and _end as char-arrays, not single char variables
In reply to Masami Hiramatsucris: Mark _stext and _end as char-arrays, not single char variables
Commit-ID: c2579fee22483b0f156099abd9996d900634562c Gitweb: http://git.kernel.org/tip/c2579fee22483b0f156099abd9996d900634562c Author: Masami Hiramatsu <[email protected]> AuthorDate: Thu, 3 Aug 2017 11:37:15 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 10 Aug 2017 16:28:53 +0200
cris: Mark _stext and _end as char-arrays, not single char variables
Mark _stext and _end as character arrays instead of single character variable, like include/asm-generic/sections.h does.
--- arch/cris/arch-v32/mach-a3/arbiter.c | 4 ++-- arch/cris/arch-v32/mach-fs/arbiter.c | 4 ++-- arch/cris/kernel/traps.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
arch/cris/arch-v32/mach-a3/arbiter.c +2 -2
@@ -227,7 +227,7 @@ static void crisv32_arbiter_config(int arbiter, int region, int unused_slots) } } -extern char _stext, _etext; +extern char _stext[], _etext[];static void crisv32_arbiter_init (void ) {
@@ -265,7 +265,7 @@ static void crisv32_arbiter_init(void)#ifndef CONFIG_ETRAX_KGDB /* Global watch for writes to kernel text segment. */ -crisv32_arbiter_watch (virt_to_phys (&_stext), &_etext - &_stext, +crisv32_arbiter_watch (virt_to_phys (_stext), _etext - _stext,MARB_CLIENTS (arbiter_all_clients, arbiter_bar_all_clients), arbiter_all_write,NULL );#endif
arch/cris/arch-v32/mach-fs/arbiter.c +2 -2
@@ -158,7 +158,7 @@ static void crisv32_arbiter_config(int region, int unused_slots) } } -extern char _stext, _etext; +extern char _stext[], _etext[];static void crisv32_arbiter_init (void ) {
@@ -190,7 +190,7 @@ static void crisv32_arbiter_init(void)#ifndef CONFIG_ETRAX_KGDB /* Global watch for writes to kernel text segment. */ -crisv32_arbiter_watch (virt_to_phys (&_stext), &_etext - &_stext, +crisv32_arbiter_watch (virt_to_phys (_stext), _etext - _stext, arbiter_all_clients, arbiter_all_write,NULL );#endif }
arch/cris/kernel/traps.c +3 -3
@@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);void show_trace (unsigned long *stack) {unsigned long addr, module_start, module_end; -extern char _stext, _etext; +extern char _stext[], _etext[];int i;pr_err ("\nCall Trace: " );
@@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)* down the cause of the crash will be able to figure * out the call path that was taken. */ -if (((addr >= (unsigned long )&_stext) && - (addr <= (unsigned long )&_etext)) || +if (((addr >= (unsigned long )_stext) && + (addr <= (unsigned long )_etext)) || ((addr >= module_start) && (addr <= module_end))) {#ifdef CONFIG_KALLSYMS print_ip_sym (addr);
tip-bot for Masami Hiramatsu
merge bot[tip:perf/core] irq: Make the irqentry text section unconditional
In reply to Masami Hiramatsuirq: Make the irqentry text section unconditional
Commit-ID: 229a71860547ec856b156179a9c6bef2de426f66 Gitweb: http://git.kernel.org/tip/229a71860547ec856b156179a9c6bef2de426f66 Author: Masami Hiramatsu <[email protected]> AuthorDate: Thu, 3 Aug 2017 11:38:21 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 10 Aug 2017 16:28:53 +0200
irq: Make the irqentry text section unconditional
Generate irqentry and softirqentry text sections without any Kconfig dependencies. This will add extra sections, but there should be no performace impact.
--- arch/arm/include/asm/traps.h | 7 ------- arch/arm64/include/asm/traps.h | 7 ------- arch/x86/entry/entry_64.S | 9 ++------- arch/x86/kernel/unwind_frame.c | 2 -- include/asm-generic/sections.h | 4 ++++ include/asm-generic/vmlinux.lds.h | 8 -------- include/linux/interrupt.h | 14 +------------- 7 files changed, 7 insertions(+), 44 deletions(-)
arch/arm/include/asm/traps.h +0 -7
@@ -18,7 +18,6 @@ struct undef_hook {void register_undef_hook (struct undef_hook *hook);void unregister_undef_hook (struct undef_hook *hook); -#ifdef CONFIG_FUNCTION_GRAPH_TRACER static inline int __in_irqentry_text (unsigned long ptr) {extern char __irqentry_text_start[];
@@ -27,12 +26,6 @@ static inline int __in_irqentry_text(unsigned long ptr)return ptr >= (unsigned long )&__irqentry_text_start && ptr < (unsigned long )&__irqentry_text_end; } -#else -static inline int __in_irqentry_text (unsigned long ptr) -{ -return 0 ; -} -#endif static inline int in_exception_text (unsigned long ptr) {
arch/arm64/include/asm/traps.h +0 -7
@@ -37,18 +37,11 @@ void unregister_undef_hook(struct undef_hook *hook);void arm64_notify_segfault (struct pt_regs *regs,unsigned long addr); -#ifdef CONFIG_FUNCTION_GRAPH_TRACER static inline int __in_irqentry_text (unsigned long ptr) {return ptr >= (unsigned long )&__irqentry_text_start && ptr < (unsigned long )&__irqentry_text_end; } -#else -static inline int __in_irqentry_text (unsigned long ptr) -{ -return 0 ; -} -#endif static inline int in_exception_text (unsigned long ptr) {
arch/x86/entry/entry_64.S +2 -7
@@ -675,13 +675,8 @@ apicinterrupt3 \num trace(\sym) smp_trace(\sym) #endif /* Make sure APIC interrupt handlers end up in the irqentry section: */ -#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN) -# define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax" -# define POP_SECTION_IRQENTRY .popsection -#else -# define PUSH_SECTION_IRQENTRY -# define POP_SECTION_IRQENTRY -#endif +#define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax" +#define POP_SECTION_IRQENTRY .popsection .macro apicinterrupt num sym do_sym PUSH_SECTION_IRQENTRY
arch/x86/kernel/unwind_frame.c +0 -2
@@ -91,10 +91,8 @@ static bool in_entry_code(unsigned long ip)if (addr >= __entry_text_start && addr < __entry_text_end)return true; -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )if (addr >= __irqentry_text_start && addr < __irqentry_text_end)return true; -#endif return false; }
include/asm-generic/sections.h +4 -0
@@ -27,6 +27,8 @@* __kprobes_text_start, __kprobes_text_end * __entry_text_start, __entry_text_end * __ctors_start, __ctors_end +* __irqentry_text_start, __irqentry_text_end +* __softirqentry_text_start, __softirqentry_text_end */ extern char _text[], _stext[], _etext[];extern char _data[], _sdata[], _edata[];
@@ -39,6 +41,8 @@ extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];extern char __kprobes_text_start[], __kprobes_text_end[];extern char __entry_text_start[], __entry_text_end[];extern char __start_rodata[], __end_rodata[]; +extern char __irqentry_text_start[], __irqentry_text_end[]; +extern char __softirqentry_text_start[], __softirqentry_text_end[];/* Start and end of .ctors section - used for constructor calls. */ extern char __ctors_start[], __ctors_end[];
include/asm-generic/vmlinux.lds.h +0 -8
@@ -483,25 +483,17 @@ *(.entry.text) \ VMLINUX_SYMBOL(__entry_text_end) = .; -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )#define IRQENTRY_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__irqentry_text_start) = .; \ *(.irqentry.text) \ VMLINUX_SYMBOL(__irqentry_text_end) = .; -#else -#define IRQENTRY_TEXT -#endif -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )#define SOFTIRQENTRY_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__softirqentry_text_start) = .; \ *(.softirqentry.text) \ VMLINUX_SYMBOL(__softirqentry_text_end) = .; -#else -#define SOFTIRQENTRY_TEXT -#endif /* Section used for early init (in .S files) */ #define HEAD_TEXT *(.head.text)
include/linux/interrupt.h +1 -13
@@ -18,6 +18,7 @@#include <linux/atomic.h> #include <asm/ptrace.h> #include <asm/irq.h> +#include <asm/sections.h> /* * These correspond to the IORESOURCE_IRQ_* defines in
@@ -726,7 +727,6 @@ extern int early_irq_init(void);extern int arch_probe_nr_irqs (void );extern int arch_early_irq_init (void ); -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) || defined(CONFIG_KASAN )/* * We want to know which function is an entrypoint of a hardirq or a softirq. */
@@ -734,16 +734,4 @@ extern int arch_early_irq_init(void);#define __softirq_entry \ __attribute__((__section__(".softirqentry.text"))) -/* Limits of hardirq entrypoints */ -extern char __irqentry_text_start[]; -extern char __irqentry_text_end[]; -/* Limits of softirq entrypoints */ -extern char __softirqentry_text_start[]; -extern char __softirqentry_text_end[]; - -#else -#define __irq_entry -#define __softirq_entry -#endif -#endif
tip-bot for Masami Hiramatsu
merge bot[tip:perf/core] kprobes/x86: Do not jump-optimize kprobes on irq entry code
In reply to Masami Hiramatsukprobes/x86: Do not jump-optimize kprobes on irq entry code
Commit-ID: d9f5f32a7d17f4906a21ad59589853639a1328a0 Gitweb: http://git.kernel.org/tip/d9f5f32a7d17f4906a21ad59589853639a1328a0 Author: Masami Hiramatsu <[email protected]> AuthorDate: Thu, 3 Aug 2017 11:39:26 +0900 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 10 Aug 2017 16:28:53 +0200
kprobes/x86: Do not jump-optimize kprobes on irq entry code
Since the kernel segment registers are not prepared at the entry of irq-entry code, if a kprobe on such code is jump-optimized, accessing per-CPU variables may cause a kernel panic.
However, if the kprobe is not optimized, it triggers an int3 exception and sets segment registers correctly.
With this patch we check the probe-address and if it is in the irq-entry code, it prohibits optimizing such kprobes.
This means we can continue probing such interrupt handlers by kprobes but it is not optimized anymore.
--- arch/x86/kernel/kprobes/opt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/kprobes/opt.c +6 -3
@@ -39,6 +39,7 @@#include <asm/insn.h> #include <asm/debugreg.h> #include <asm/set_memory.h> +#include <asm/sections.h> #include "common.h"
@@ -251,10 +252,12 @@ static int can_optimize(unsigned long paddr)/* * Do not optimize in the entry code due to the unstable -* stack handling. +* stack handling and registers setup. */ -if ((paddr >= (unsigned long )__entry_text_start) && - (paddr < (unsigned long )__entry_text_end)) +if (((paddr >= (unsigned long )__entry_text_start) && + (paddr < (unsigned long )__entry_text_end)) || + ((paddr >= (unsigned long )__irqentry_text_start) && + (paddr < (unsigned long )__irqentry_text_end)))return 0 ;/* Check there is enough space for a relative jump. */
Re: [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char
In reply to Masami HiramatsuQuoted 14 lines · On Thu, 3 Aug 2017 11:37:15 +0900 Masami Hiramatsu <[email protected]> wrote:
arch/cris/kernel/traps.c +1
-1@@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);void show_trace (unsigned long *stack) {unsigned long addr, module_start, module_end; -extern char _stext, _etext; +extern char _stext[], _etext[];int i;pr_err ("\nCall Trace: " );
arch/cris/kernel/traps.c void show_trace(unsigned long *stack) · line 74
Quoted 8 lines
arch/cris/kernel/traps.c +2
-2@@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)* down the cause of the crash will be able to figure * out the call path that was taken. */ -if (((addr >= (unsigned long )&_stext) && - (addr <= (unsigned long )&_etext)) || +if (((addr >= (unsigned long )_stext) && + (addr <= (unsigned long )_etext)) || ((addr >= module_start) && (addr <= module_end))) {
BTW, I would like to ask cris people, this seems to check over 1 byte, since _etext and module_end will be placed at the next byte of the real address area.
As same as other arch, Should it be
(addr < (unsigned long)_etext)
or are there any other reason?
Thank you,
Quoted 3 lines
arch/cris/kernel/traps.c +0
-0#ifdef CONFIG_KALLSYMS print_ip_sym (addr);
Signature · 1 line
Masami Hiramatsu <[email protected]>
Re: [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char
In reply to Masami HiramatsuQuoted 2 lines · Masami Hiramatsu
Mark
_stextand_endas character arrays instead of single character, as same asinclude/asm-generic/sections.hdoes.
Looks good.
Quoted 65 lines
Signed-off-by Masami Hiramatsu <[email protected]>--- arch/cris/arch-v32/mach-a3/arbiter.c | 4 ++-- arch/cris/arch-v32/mach-fs/arbiter.c | 4 ++-- arch/cris/kernel/traps.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)arch/cris/arch-v32/mach-a3/arbiter.c +2
-2@@ -227,7 +227,7 @@ static void crisv32_arbiter_config(int arbiter, int region, int unused_slots) } } -extern char _stext, _etext; +extern char _stext[], _etext[];static void crisv32_arbiter_init (void ) {@@ -265,7 +265,7 @@ static void crisv32_arbiter_init(void)#ifndef CONFIG_ETRAX_KGDB /* Global watch for writes to kernel text segment. */ -crisv32_arbiter_watch (virt_to_phys (&_stext), &_etext - &_stext, +crisv32_arbiter_watch (virt_to_phys (_stext), _etext - _stext,MARB_CLIENTS (arbiter_all_clients, arbiter_bar_all_clients), arbiter_all_write,NULL );#endif arch/cris/arch-v32/mach-fs/arbiter.c +2
-2@@ -158,7 +158,7 @@ static void crisv32_arbiter_config(int region, int unused_slots) } } -extern char _stext, _etext; +extern char _stext[], _etext[];static void crisv32_arbiter_init (void ) {@@ -190,7 +190,7 @@ static void crisv32_arbiter_init(void)#ifndef CONFIG_ETRAX_KGDB /* Global watch for writes to kernel text segment. */ -crisv32_arbiter_watch (virt_to_phys (&_stext), &_etext - &_stext, +crisv32_arbiter_watch (virt_to_phys (_stext), _etext - _stext, arbiter_all_clients, arbiter_all_write,NULL );#endif }arch/cris/kernel/traps.c +1
-1@@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);void show_trace (unsigned long *stack) {unsigned long addr, module_start, module_end; -extern char _stext, _etext; +extern char _stext[], _etext[];int i;pr_err ("\nCall Trace: " );
arch/cris/kernel/traps.c void show_trace(unsigned long *stack) · line 76
Quoted 10 lines
arch/cris/kernel/traps.c +2
-2@@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)* down the cause of the crash will be able to figure * out the call path that was taken. */ -if (((addr >= (unsigned long )&_stext) && - (addr <= (unsigned long )&_etext)) || +if (((addr >= (unsigned long )_stext) && + (addr <= (unsigned long )_etext)) || ((addr >= module_start) && (addr <= module_end))) {#ifdef CONFIG_KALLSYMS print_ip_sym (addr);
/^JN - Jesper Nilsson
Signature · 1 line
Jesper Nilsson -- [email protected]
Re: [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char
In reply to Masami HiramatsuQuoted 31 lines · Masami Hiramatsu
Quoted 14 lines · On Thu, 3 Aug 2017 11:37:15 +0900 Masami Hiramatsu <[email protected]> wrote:
arch/cris/kernel/traps.c +1
-1@@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);void show_trace (unsigned long *stack) {unsigned long addr, module_start, module_end; -extern char _stext, _etext; +extern char _stext[], _etext[];int i;pr_err ("\nCall Trace: " );arch/cris/kernel/traps.c void show_trace(unsigned long *stack) · line 74
Quoted 8 lines
arch/cris/kernel/traps.c +2
-2@@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)* down the cause of the crash will be able to figure * out the call path that was taken. */ -if (((addr >= (unsigned long )&_stext) && - (addr <= (unsigned long )&_etext)) || +if (((addr >= (unsigned long )_stext) && + (addr <= (unsigned long )_etext)) || ((addr >= module_start) && (addr <= module_end))) {BTW, I would like to ask cris people, this seems to check over 1 byte, since
_etextandmodule_endwill be placed at the next byte of the real address area.
As same as other arch, Should it be
Quoted 3 lines
(addr < (unsigned long)_etext)
or are there any other reason?
As far as I can tell, this is non-intentional.
Quoted 3 lines
Thank you,
Masami Hiramatsu <[email protected]>
/^JN - Jesper Nilsson
Signature · 1 line
Jesper Nilsson -- [email protected]