History

kgdb: Add NOKPROBE labels on the trap handler functions

Currently kgdb honours the kprobe blocklist but doesn't place its own trap handling code on the list. Add labels to discourage attempting to use kgdb to debug itself. Not every functions that executes from the trap handler needs to be marked up: relatively early in the trap handler execution (just after we bring the other CPUs to a halt) all breakpoints are replaced with the original opcodes. This patch marks up code in the debug_core that executes between trap entry and the breakpoints being deactivated and, also, code that executes between breakpoint activation and trap exit. To be clear these changes are not sufficient to make recursive trapping impossible since they do not include library calls made during kgdb's entry/exit logic. However going much further whilst we are sharing the kprobe blocklist risks reducing the capabilities of kprobe and this would be a bad trade off (especially so given kgdb's users are currently conditioned to avoid recursive traps).

Daniel Thompson committed 6 years ago

Commit 4c4197e1 parent f2d10ff1 file · +16 −0Browse files

Showing the changes to kernel/debug/debug_core.c (1 of 1 file). Show all

Unified · Split

kernel/debug/debug_core.c+16−0
@@ -169,12 +169,14 @@ int __weak kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) · 168 unmodified lines
169 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);169 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
170 return err;170 return err;
171}171}
172NOKPROBE_SYMBOL(kgdb_arch_set_breakpoint);
172 173
173int __weak kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)174int __weak kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
174{175{
175 return copy_to_kernel_nofault((char *)bpt->bpt_addr,176 return copy_to_kernel_nofault((char *)bpt->bpt_addr,
176 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);177 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
177}178}
179NOKPROBE_SYMBOL(kgdb_arch_remove_breakpoint);
178 180
179int __weak kgdb_validate_break_address(unsigned long addr)181int __weak kgdb_validate_break_address(unsigned long addr)
180{182{
@@ -204,6 +206,7 @@ unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs) · 23 unmodified lines
204{206{
205 return instruction_pointer(regs);207 return instruction_pointer(regs);
206}208}
209NOKPROBE_SYMBOL(kgdb_arch_pc);
207 210
208int __weak kgdb_arch_init(void)211int __weak kgdb_arch_init(void)
209{212{
@@ -214,6 +217,7 @@ int __weak kgdb_skipexception(int exception, struct pt_regs *regs) · 4 unmodified lines
214{217{
215 return 0;218 return 0;
216}219}
220NOKPROBE_SYMBOL(kgdb_skipexception);
217 221
218#ifdef CONFIG_SMP222#ifdef CONFIG_SMP
219 223
@@ -235,6 +239,7 @@ void __weak kgdb_call_nmi_hook(void *ignored) · 15 unmodified lines
235 */239 */
236 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());240 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
237}241}
242NOKPROBE_SYMBOL(kgdb_call_nmi_hook);
238 243
239void __weak kgdb_roundup_cpus(void)244void __weak kgdb_roundup_cpus(void)
240{245{
@@ -268,6 +273,7 @@ void __weak kgdb_roundup_cpus(void) · 27 unmodified lines
268 kgdb_info[cpu].rounding_up = false;273 kgdb_info[cpu].rounding_up = false;
269 }274 }
270}275}
276NOKPROBE_SYMBOL(kgdb_roundup_cpus);
271 277
272#endif278#endif
273 279
@@ -294,6 +300,7 @@ static void kgdb_flush_swbreak_addr(unsigned long addr) · 20 unmodified lines
294 /* Force flush instruction cache if it was outside the mm */300 /* Force flush instruction cache if it was outside the mm */
295 flush_icache_range(addr, addr + BREAK_INSTR_SIZE);301 flush_icache_range(addr, addr + BREAK_INSTR_SIZE);
296}302}
303NOKPROBE_SYMBOL(kgdb_flush_swbreak_addr);
297 304
298/*305/*
299 * SW breakpoint management:306 * SW breakpoint management:
@@ -321,6 +328,7 @@ int dbg_activate_sw_breakpoints(void) · 21 unmodified lines
321 }328 }
322 return ret;329 return ret;
323}330}
331NOKPROBE_SYMBOL(dbg_activate_sw_breakpoints);
324 332
325int dbg_set_sw_break(unsigned long addr)333int dbg_set_sw_break(unsigned long addr)
326{334{
@@ -384,6 +392,7 @@ int dbg_deactivate_sw_breakpoints(void) · 57 unmodified lines
384 }392 }
385 return ret;393 return ret;
386}394}
395NOKPROBE_SYMBOL(dbg_deactivate_sw_breakpoints);
387 396
388int dbg_remove_sw_break(unsigned long addr)397int dbg_remove_sw_break(unsigned long addr)
389{398{
@@ -505,6 +514,7 @@ static int kgdb_io_ready(int print_wait) · 115 unmodified lines
505 }514 }
506 return 1;515 return 1;
507}516}
517NOKPROBE_SYMBOL(kgdb_io_ready);
508 518
509static int kgdb_reenter_check(struct kgdb_state *ks)519static int kgdb_reenter_check(struct kgdb_state *ks)
510{520{
@@ -552,6 +562,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks) · 41 unmodified lines
552 562
553 return 1;563 return 1;
554}564}
565NOKPROBE_SYMBOL(kgdb_reenter_check);
555 566
556static void dbg_touch_watchdogs(void)567static void dbg_touch_watchdogs(void)
557{568{
@@ -559,6 +570,7 @@ static void dbg_touch_watchdogs(void) · 1 unmodified line
559 clocksource_touch_watchdog();570 clocksource_touch_watchdog();
560 rcu_cpu_stall_reset();571 rcu_cpu_stall_reset();
561}572}
573NOKPROBE_SYMBOL(dbg_touch_watchdogs);
562 574
563static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,575static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
564 int exception_state)576 int exception_state)
@@ -790,6 +802,7 @@ kgdb_restore: · 225 unmodified lines
790 802
791 return kgdb_info[cpu].ret_state;803 return kgdb_info[cpu].ret_state;
792}804}
805NOKPROBE_SYMBOL(kgdb_cpu_enter);
793 806
794/*807/*
795 * kgdb_handle_exception() - main entry point from a kernel exception808 * kgdb_handle_exception() - main entry point from a kernel exception
@@ -834,6 +847,7 @@ out: · 38 unmodified lines
834 arch_kgdb_ops.enable_nmi(1);847 arch_kgdb_ops.enable_nmi(1);
835 return ret;848 return ret;
836}849}
850NOKPROBE_SYMBOL(kgdb_handle_exception);
837 851
838/*852/*
839 * GDB places a breakpoint at this function to know dynamically loaded objects.853 * GDB places a breakpoint at this function to know dynamically loaded objects.
@@ -868,6 +882,7 @@ int kgdb_nmicallback(int cpu, void *regs) · 28 unmodified lines
868#endif882#endif
869 return 1;883 return 1;
870}884}
885NOKPROBE_SYMBOL(kgdb_nmicallback);
871 886
872int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code,887int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code,
873 atomic_t *send_ready)888 atomic_t *send_ready)
@@ -893,6 +908,7 @@ int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, · 19 unmodified lines
893#endif908#endif
894 return 1;909 return 1;
895}910}
911NOKPROBE_SYMBOL(kgdb_nmicallin);
896 912
897static void kgdb_console_write(struct console *co, const char *s,913static void kgdb_console_write(struct console *co, const char *s,
898 unsigned count)914 unsigned count)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t