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
169169 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
170170 return err;
171171 }
172+NOKPROBE_SYMBOL(kgdb_arch_set_breakpoint);
172173
173174 int __weak kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
174175 {
175176 return copy_to_kernel_nofault((char *)bpt->bpt_addr,
176177 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
177178 }
179+NOKPROBE_SYMBOL(kgdb_arch_remove_breakpoint);
178180
179181 int __weak kgdb_validate_break_address(unsigned long addr)
180182 {
@@ -204,6 +206,7 @@ unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs) · 23 unmodified lines
204206 {
205207 return instruction_pointer(regs);
206208 }
209+NOKPROBE_SYMBOL(kgdb_arch_pc);
207210
208211 int __weak kgdb_arch_init(void)
209212 {
@@ -214,6 +217,7 @@ int __weak kgdb_skipexception(int exception, struct pt_regs *regs) · 4 unmodified lines
214217 {
215218 return 0;
216219 }
220+NOKPROBE_SYMBOL(kgdb_skipexception);
217221
218222 #ifdef CONFIG_SMP
219223
@@ -235,6 +239,7 @@ void __weak kgdb_call_nmi_hook(void *ignored) · 15 unmodified lines
235239 */
236240 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
237241 }
242+NOKPROBE_SYMBOL(kgdb_call_nmi_hook);
238243
239244 void __weak kgdb_roundup_cpus(void)
240245 {
@@ -268,6 +273,7 @@ void __weak kgdb_roundup_cpus(void) · 27 unmodified lines
268273 kgdb_info[cpu].rounding_up = false;
269274 }
270275 }
276+NOKPROBE_SYMBOL(kgdb_roundup_cpus);
271277
272278 #endif
273279
@@ -294,6 +300,7 @@ static void kgdb_flush_swbreak_addr(unsigned long addr) · 20 unmodified lines
294300 /* Force flush instruction cache if it was outside the mm */
295301 flush_icache_range(addr, addr + BREAK_INSTR_SIZE);
296302 }
303+NOKPROBE_SYMBOL(kgdb_flush_swbreak_addr);
297304
298305 /*
299306 * SW breakpoint management:
@@ -321,6 +328,7 @@ int dbg_activate_sw_breakpoints(void) · 21 unmodified lines
321328 }
322329 return ret;
323330 }
331+NOKPROBE_SYMBOL(dbg_activate_sw_breakpoints);
324332
325333 int dbg_set_sw_break(unsigned long addr)
326334 {
@@ -384,6 +392,7 @@ int dbg_deactivate_sw_breakpoints(void) · 57 unmodified lines
384392 }
385393 return ret;
386394 }
395+NOKPROBE_SYMBOL(dbg_deactivate_sw_breakpoints);
387396
388397 int dbg_remove_sw_break(unsigned long addr)
389398 {
@@ -505,6 +514,7 @@ static int kgdb_io_ready(int print_wait) · 115 unmodified lines
505514 }
506515 return 1;
507516 }
517+NOKPROBE_SYMBOL(kgdb_io_ready);
508518
509519 static int kgdb_reenter_check(struct kgdb_state *ks)
510520 {
@@ -552,6 +562,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks) · 41 unmodified lines
552562
553563 return 1;
554564 }
565+NOKPROBE_SYMBOL(kgdb_reenter_check);
555566
556567 static void dbg_touch_watchdogs(void)
557568 {
@@ -559,6 +570,7 @@ static void dbg_touch_watchdogs(void) · 1 unmodified line
559570 clocksource_touch_watchdog();
560571 rcu_cpu_stall_reset();
561572 }
573+NOKPROBE_SYMBOL(dbg_touch_watchdogs);
562574
563575 static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
564576 int exception_state)
@@ -790,6 +802,7 @@ kgdb_restore: · 225 unmodified lines
790802
791803 return kgdb_info[cpu].ret_state;
792804 }
805+NOKPROBE_SYMBOL(kgdb_cpu_enter);
793806
794807 /*
795808 * kgdb_handle_exception() - main entry point from a kernel exception
@@ -834,6 +847,7 @@ out: · 38 unmodified lines
834847 arch_kgdb_ops.enable_nmi(1);
835848 return ret;
836849 }
850+NOKPROBE_SYMBOL(kgdb_handle_exception);
837851
838852 /*
839853 * 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
868882 #endif
869883 return 1;
870884 }
885+NOKPROBE_SYMBOL(kgdb_nmicallback);
871886
872887 int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code,
873888 atomic_t *send_ready)
@@ -893,6 +908,7 @@ int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, · 19 unmodified lines
893908 #endif
894909 return 1;
895910 }
911+NOKPROBE_SYMBOL(kgdb_nmicallin);
896912
897913 static void kgdb_console_write(struct console *co, const char *s,
898914 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