Skip to content

Commit 4c4197e

Browse files
author
Daniel Thompson
committed
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). Reviewed-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Thompson <[email protected]>
1 parent f2d10ff commit 4c4197e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

kernel/debug/debug_core.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ int __weak kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
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)
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)
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)
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)
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)
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)
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)
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)
505514
}
506515
return 1;
507516
}
517+
NOKPROBE_SYMBOL(kgdb_io_ready);
508518

509519
static int kgdb_reenter_check(struct kgdb_state *ks)
510520
{
@@ -552,13 +562,15 @@ static int kgdb_reenter_check(struct kgdb_state *ks)
552562

553563
return 1;
554564
}
565+
NOKPROBE_SYMBOL(kgdb_reenter_check);
555566

556567
static void dbg_touch_watchdogs(void)
557568
{
558569
touch_softlockup_watchdog_sync();
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 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs,
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 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs)
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)
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,
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)

0 commit comments

Comments
 (0)