Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'kgdb-5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux

Pull kgdb updates from Daniel Thompson:
"A fairly modest set of changes for this cycle.

Of particular note are an earlycon fix from Doug Anderson and my own
changes to get kgdb/kdb to honour the kprobe blocklist. The later
creates a safety rail that strongly encourages developers not to place
breakpoints in, for example, arch specific trap handling code.

Also included are a couple of small fixes and tweaks: an API update,
eliminate a coverity dead code warning, improved handling of search
during multi-line printk and a couple of typo corrections"

* tag 'kgdb-5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/danielt/linux:
kdb: Fix pager search for multi-line strings
kernel: debug: Centralize dbg_[de]activate_sw_breakpoints
kgdb: Add NOKPROBE labels on the trap handler functions
kgdb: Honour the kprobe blocklist when setting breakpoints
kernel/debug: Fix spelling mistake in debug_core.c
kdb: Use newer api for tasklist scanning
kgdb: Make "kgdbcon" work properly with "kgdb_earlycon"
kdb: remove unnecessary null check of dbg_io_ops

+101 -34
+18
include/linux/kgdb.h
··· 16 16 #include <linux/linkage.h> 17 17 #include <linux/init.h> 18 18 #include <linux/atomic.h> 19 + #include <linux/kprobes.h> 19 20 #ifdef CONFIG_HAVE_ARCH_KGDB 20 21 #include <asm/kgdb.h> 21 22 #endif ··· 335 334 extern int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, 336 335 atomic_t *snd_rdy); 337 336 extern void gdbstub_exit(int status); 337 + 338 + /* 339 + * kgdb and kprobes both use the same (kprobe) blocklist (which makes sense 340 + * given they are both typically hooked up to the same trap meaning on most 341 + * architectures one cannot be used to debug the other) 342 + * 343 + * However on architectures where kprobes is not (yet) implemented we permit 344 + * breakpoints everywhere rather than blocking everything by default. 345 + */ 346 + static inline bool kgdb_within_blocklist(unsigned long addr) 347 + { 348 + #ifdef CONFIG_KGDB_HONOUR_BLOCKLIST 349 + return within_kprobe_blacklist(addr); 350 + #else 351 + return false; 352 + #endif 353 + } 338 354 339 355 extern int kgdb_single_step; 340 356 extern atomic_t kgdb_active;
+38 -10
kernel/debug/debug_core.c
··· 80 80 struct kgdb_io *dbg_io_ops; 81 81 static DEFINE_SPINLOCK(kgdb_registration_lock); 82 82 83 - /* Action for the reboot notifiter, a global allow kdb to change it */ 83 + /* Action for the reboot notifier, a global allow kdb to change it */ 84 84 static int kgdbreboot; 85 85 /* kgdb console driver is loaded */ 86 86 static int kgdb_con_registered; ··· 93 93 94 94 /* Use kdb or gdbserver mode */ 95 95 int dbg_kdb_mode = 1; 96 - 97 - static int __init opt_kgdb_con(char *str) 98 - { 99 - kgdb_use_con = 1; 100 - return 0; 101 - } 102 - 103 - early_param("kgdbcon", opt_kgdb_con); 104 96 105 97 module_param(kgdb_use_con, int, 0644); 106 98 module_param(kgdbreboot, int, 0644); ··· 155 163 156 164 /* 157 165 * Weak aliases for breakpoint management, 158 - * can be overriden by architectures when needed: 166 + * can be overridden by architectures when needed: 159 167 */ 160 168 int __weak kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) 161 169 { ··· 169 177 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE); 170 178 return err; 171 179 } 180 + NOKPROBE_SYMBOL(kgdb_arch_set_breakpoint); 172 181 173 182 int __weak kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) 174 183 { 175 184 return copy_to_kernel_nofault((char *)bpt->bpt_addr, 176 185 (char *)bpt->saved_instr, BREAK_INSTR_SIZE); 177 186 } 187 + NOKPROBE_SYMBOL(kgdb_arch_remove_breakpoint); 178 188 179 189 int __weak kgdb_validate_break_address(unsigned long addr) 180 190 { 181 191 struct kgdb_bkpt tmp; 182 192 int err; 193 + 194 + if (kgdb_within_blocklist(addr)) 195 + return -EINVAL; 196 + 183 197 /* Validate setting the breakpoint and then removing it. If the 184 198 * remove fails, the kernel needs to emit a bad message because we 185 199 * are deep trouble not being able to put things back the way we ··· 206 208 { 207 209 return instruction_pointer(regs); 208 210 } 211 + NOKPROBE_SYMBOL(kgdb_arch_pc); 209 212 210 213 int __weak kgdb_arch_init(void) 211 214 { ··· 217 218 { 218 219 return 0; 219 220 } 221 + NOKPROBE_SYMBOL(kgdb_skipexception); 220 222 221 223 #ifdef CONFIG_SMP 222 224 ··· 239 239 */ 240 240 kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs()); 241 241 } 242 + NOKPROBE_SYMBOL(kgdb_call_nmi_hook); 242 243 243 244 void __weak kgdb_roundup_cpus(void) 244 245 { ··· 273 272 kgdb_info[cpu].rounding_up = false; 274 273 } 275 274 } 275 + NOKPROBE_SYMBOL(kgdb_roundup_cpus); 276 276 277 277 #endif 278 278 ··· 300 298 /* Force flush instruction cache if it was outside the mm */ 301 299 flush_icache_range(addr, addr + BREAK_INSTR_SIZE); 302 300 } 301 + NOKPROBE_SYMBOL(kgdb_flush_swbreak_addr); 303 302 304 303 /* 305 304 * SW breakpoint management: ··· 328 325 } 329 326 return ret; 330 327 } 328 + NOKPROBE_SYMBOL(dbg_activate_sw_breakpoints); 331 329 332 330 int dbg_set_sw_break(unsigned long addr) 333 331 { ··· 392 388 } 393 389 return ret; 394 390 } 391 + NOKPROBE_SYMBOL(dbg_deactivate_sw_breakpoints); 395 392 396 393 int dbg_remove_sw_break(unsigned long addr) 397 394 { ··· 514 509 } 515 510 return 1; 516 511 } 512 + NOKPROBE_SYMBOL(kgdb_io_ready); 517 513 518 514 static int kgdb_reenter_check(struct kgdb_state *ks) 519 515 { ··· 562 556 563 557 return 1; 564 558 } 559 + NOKPROBE_SYMBOL(kgdb_reenter_check); 565 560 566 561 static void dbg_touch_watchdogs(void) 567 562 { ··· 570 563 clocksource_touch_watchdog(); 571 564 rcu_cpu_stall_reset(); 572 565 } 566 + NOKPROBE_SYMBOL(dbg_touch_watchdogs); 573 567 574 568 static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs, 575 569 int exception_state) ··· 760 752 } 761 753 } 762 754 755 + dbg_activate_sw_breakpoints(); 756 + 763 757 /* Call the I/O driver's post_exception routine */ 764 758 if (dbg_io_ops->post_exception) 765 759 dbg_io_ops->post_exception(); ··· 804 794 805 795 return kgdb_info[cpu].ret_state; 806 796 } 797 + NOKPROBE_SYMBOL(kgdb_cpu_enter); 807 798 808 799 /* 809 800 * kgdb_handle_exception() - main entry point from a kernel exception ··· 849 838 arch_kgdb_ops.enable_nmi(1); 850 839 return ret; 851 840 } 841 + NOKPROBE_SYMBOL(kgdb_handle_exception); 852 842 853 843 /* 854 844 * GDB places a breakpoint at this function to know dynamically loaded objects. ··· 884 872 #endif 885 873 return 1; 886 874 } 875 + NOKPROBE_SYMBOL(kgdb_nmicallback); 887 876 888 877 int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, 889 878 atomic_t *send_ready) ··· 910 897 #endif 911 898 return 1; 912 899 } 900 + NOKPROBE_SYMBOL(kgdb_nmicallin); 913 901 914 902 static void kgdb_console_write(struct console *co, const char *s, 915 903 unsigned count) ··· 933 919 .flags = CON_PRINTBUFFER | CON_ENABLED, 934 920 .index = -1, 935 921 }; 922 + 923 + static int __init opt_kgdb_con(char *str) 924 + { 925 + kgdb_use_con = 1; 926 + 927 + if (kgdb_io_module_registered && !kgdb_con_registered) { 928 + register_console(&kgdbcons); 929 + kgdb_con_registered = 1; 930 + } 931 + 932 + return 0; 933 + } 934 + 935 + early_param("kgdbcon", opt_kgdb_con); 936 936 937 937 #ifdef CONFIG_MAGIC_SYSRQ 938 938 static void sysrq_handle_dbg(int key)
+2 -3
kernel/debug/gdbstub.c
··· 725 725 } 726 726 } 727 727 728 - do_each_thread(g, p) { 728 + for_each_process_thread(g, p) { 729 729 if (i >= ks->thr_query && !finished) { 730 730 int_to_threadref(thref, p->pid); 731 731 ptr = pack_threadid(ptr, thref); ··· 735 735 finished = 1; 736 736 } 737 737 i++; 738 - } while_each_thread(g, p); 738 + } 739 739 740 740 *(--ptr) = '\0'; 741 741 break; ··· 1061 1061 error_packet(remcom_out_buffer, -EINVAL); 1062 1062 break; 1063 1063 } 1064 - dbg_activate_sw_breakpoints(); 1065 1064 fallthrough; /* to default processing */ 1066 1065 default: 1067 1066 default_handle:
+9
kernel/debug/kdb/kdb_bp.c
··· 307 307 return KDB_BADINT; 308 308 309 309 /* 310 + * This check is redundant (since the breakpoint machinery should 311 + * be doing the same check during kdb_bp_install) but gives the 312 + * user immediate feedback. 313 + */ 314 + diag = kgdb_validate_break_address(template.bp_addr); 315 + if (diag) 316 + return diag; 317 + 318 + /* 310 319 * Find an empty bp structure to allocate 311 320 */ 312 321 for (bpno = 0, bp = kdb_breakpoints; bpno < KDB_MAXBPT; bpno++, bp++) {
+2 -2
kernel/debug/kdb/kdb_bt.c
··· 149 149 return 0; 150 150 } 151 151 /* Now the inactive tasks */ 152 - kdb_do_each_thread(g, p) { 152 + for_each_process_thread(g, p) { 153 153 if (KDB_FLAG(CMD_INTERRUPT)) 154 154 return 0; 155 155 if (task_curr(p)) 156 156 continue; 157 157 if (kdb_bt1(p, mask, btaprompt)) 158 158 return 0; 159 - } kdb_while_each_thread(g, p); 159 + } 160 160 } else if (strcmp(argv[0], "btp") == 0) { 161 161 struct task_struct *p; 162 162 unsigned long pid;
-2
kernel/debug/kdb/kdb_debugger.c
··· 147 147 return DBG_PASS_EVENT; 148 148 } 149 149 kdb_bp_install(ks->linux_regs); 150 - dbg_activate_sw_breakpoints(); 151 150 /* Set the exit state to a single step or a continue */ 152 151 if (KDB_STATE(DOING_SS)) 153 152 gdbstub_state(ks, "s"); ··· 166 167 * differently vs the gdbstub 167 168 */ 168 169 kgdb_single_step = 0; 169 - dbg_deactivate_sw_breakpoints(); 170 170 return DBG_SWITCH_CPU_EVENT; 171 171 } 172 172 return kgdb_info[ks->cpu].ret_state;
+13 -9
kernel/debug/kdb/kdb_io.c
··· 545 545 static void kdb_msg_write(const char *msg, int msg_len) 546 546 { 547 547 struct console *c; 548 + const char *cp; 549 + int len; 548 550 549 551 if (msg_len == 0) 550 552 return; 551 553 552 - if (dbg_io_ops) { 553 - const char *cp = msg; 554 - int len = msg_len; 554 + cp = msg; 555 + len = msg_len; 555 556 556 - while (len--) { 557 - dbg_io_ops->write_char(*cp); 558 - cp++; 559 - } 557 + while (len--) { 558 + dbg_io_ops->write_char(*cp); 559 + cp++; 560 560 } 561 561 562 562 for_each_console(c) { ··· 706 706 size_avail = sizeof(kdb_buffer) - len; 707 707 goto kdb_print_out; 708 708 } 709 - if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH) 709 + if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH) { 710 710 /* 711 711 * This was a interactive search (using '/' at more 712 - * prompt) and it has completed. Clear the flag. 712 + * prompt) and it has completed. Replace the \0 with 713 + * its original value to ensure multi-line strings 714 + * are handled properly, and return to normal mode. 713 715 */ 716 + *cphold = replaced_byte; 714 717 kdb_grepping_flag = 0; 718 + } 715 719 /* 716 720 * at this point the string is a full line and 717 721 * should be printed, up to the null.
+4 -4
kernel/debug/kdb/kdb_main.c
··· 2299 2299 if (kdb_task_state(p, mask_I)) 2300 2300 ++idle; 2301 2301 } 2302 - kdb_do_each_thread(g, p) { 2302 + for_each_process_thread(g, p) { 2303 2303 if (kdb_task_state(p, mask_M)) 2304 2304 ++daemon; 2305 - } kdb_while_each_thread(g, p); 2305 + } 2306 2306 if (idle || daemon) { 2307 2307 if (idle) 2308 2308 kdb_printf("%d idle process%s (state I)%s\n", ··· 2370 2370 } 2371 2371 kdb_printf("\n"); 2372 2372 /* Now the real tasks */ 2373 - kdb_do_each_thread(g, p) { 2373 + for_each_process_thread(g, p) { 2374 2374 if (KDB_FLAG(CMD_INTERRUPT)) 2375 2375 return 0; 2376 2376 if (kdb_task_state(p, mask)) 2377 2377 kdb_ps1(p); 2378 - } kdb_while_each_thread(g, p); 2378 + } 2379 2379 2380 2380 return 0; 2381 2381 }
-4
kernel/debug/kdb/kdb_private.h
··· 230 230 231 231 #define kdb_task_has_cpu(p) (task_curr(p)) 232 232 233 - /* Simplify coexistence with NPTL */ 234 - #define kdb_do_each_thread(g, p) do_each_thread(g, p) 235 - #define kdb_while_each_thread(g, p) while_each_thread(g, p) 236 - 237 233 #define GFP_KDB (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL) 238 234 239 235 extern void *debug_kmalloc(size_t size, gfp_t flags);
+15
lib/Kconfig.kgdb
··· 24 24 25 25 if KGDB 26 26 27 + config KGDB_HONOUR_BLOCKLIST 28 + bool "KGDB: use kprobe blocklist to prohibit unsafe breakpoints" 29 + depends on HAVE_KPROBES 30 + depends on MODULES 31 + select KPROBES 32 + default y 33 + help 34 + If set to Y the debug core will use the kprobe blocklist to 35 + identify symbols where it is unsafe to set breakpoints. 36 + In particular this disallows instrumentation of functions 37 + called during debug trap handling and thus makes it very 38 + difficult to inadvertently provoke recursive trap handling. 39 + 40 + If unsure, say Y. 41 + 27 42 config KGDB_SERIAL_CONSOLE 28 43 tristate "KGDB: use kgdb over the serial console" 29 44 select CONSOLE_POLL