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 'for_linus-3.19-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/kgdb

Pull kgdb/kdb fixes from Jason Wessel:
"These have been around since 3.17 and in kgdb-next for the last 9
weeks and some will go back to -stable.

Summary of changes:

Cleanups
- kdb: Remove unused command flags, repeat flags and KDB_REPEAT_NONE

Fixes
- kgdb/kdb: Allow access on a single core, if a CPU round up is
deemed impossible, which will allow inspection of the now "trashed"
kernel
- kdb: Add enable mask for the command groups
- kdb: access controls to restrict sensitive commands"

* tag 'for_linus-3.19-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/kgdb:
kernel/debug/debug_core.c: Logging clean-up
kgdb: timeout if secondary CPUs ignore the roundup
kdb: Allow access to sensitive commands to be restricted by default
kdb: Add enable mask for groups of commands
kdb: Categorize kdb commands (similar to SysRq categorization)
kdb: Remove KDB_REPEAT_NONE flag
kdb: Use KDB_REPEAT_* values as flags
kdb: Rename kdb_register_repeat() to kdb_register_flags()
kdb: Rename kdb_repeat_t to kdb_cmdflags_t, cmd_repeat to cmd_flags
kdb: Remove currently unused kdbtab_t->cmd_flags

+304 -146
+53 -9
include/linux/kdb.h
··· 13 13 * Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com> 14 14 */ 15 15 16 + /* Shifted versions of the command enable bits are be used if the command 17 + * has no arguments (see kdb_check_flags). This allows commands, such as 18 + * go, to have different permissions depending upon whether it is called 19 + * with an argument. 20 + */ 21 + #define KDB_ENABLE_NO_ARGS_SHIFT 10 22 + 16 23 typedef enum { 17 - KDB_REPEAT_NONE = 0, /* Do not repeat this command */ 18 - KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */ 19 - KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */ 20 - } kdb_repeat_t; 24 + KDB_ENABLE_ALL = (1 << 0), /* Enable everything */ 25 + KDB_ENABLE_MEM_READ = (1 << 1), 26 + KDB_ENABLE_MEM_WRITE = (1 << 2), 27 + KDB_ENABLE_REG_READ = (1 << 3), 28 + KDB_ENABLE_REG_WRITE = (1 << 4), 29 + KDB_ENABLE_INSPECT = (1 << 5), 30 + KDB_ENABLE_FLOW_CTRL = (1 << 6), 31 + KDB_ENABLE_SIGNAL = (1 << 7), 32 + KDB_ENABLE_REBOOT = (1 << 8), 33 + /* User exposed values stop here, all remaining flags are 34 + * exclusively used to describe a commands behaviour. 35 + */ 36 + 37 + KDB_ENABLE_ALWAYS_SAFE = (1 << 9), 38 + KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1, 39 + 40 + KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT, 41 + KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ 42 + << KDB_ENABLE_NO_ARGS_SHIFT, 43 + KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE 44 + << KDB_ENABLE_NO_ARGS_SHIFT, 45 + KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ 46 + << KDB_ENABLE_NO_ARGS_SHIFT, 47 + KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE 48 + << KDB_ENABLE_NO_ARGS_SHIFT, 49 + KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT 50 + << KDB_ENABLE_NO_ARGS_SHIFT, 51 + KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL 52 + << KDB_ENABLE_NO_ARGS_SHIFT, 53 + KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL 54 + << KDB_ENABLE_NO_ARGS_SHIFT, 55 + KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT 56 + << KDB_ENABLE_NO_ARGS_SHIFT, 57 + KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE 58 + << KDB_ENABLE_NO_ARGS_SHIFT, 59 + KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT, 60 + 61 + KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */ 62 + KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */ 63 + } kdb_cmdflags_t; 21 64 22 65 typedef int (*kdb_func_t)(int, const char **); 23 66 ··· 105 62 #define KDB_BADLENGTH (-19) 106 63 #define KDB_NOBP (-20) 107 64 #define KDB_BADADDR (-21) 65 + #define KDB_NOPERM (-22) 108 66 109 67 /* 110 68 * kdb_diemsg ··· 190 146 191 147 /* Dynamic kdb shell command registration */ 192 148 extern int kdb_register(char *, kdb_func_t, char *, char *, short); 193 - extern int kdb_register_repeat(char *, kdb_func_t, char *, char *, 194 - short, kdb_repeat_t); 149 + extern int kdb_register_flags(char *, kdb_func_t, char *, char *, 150 + short, kdb_cmdflags_t); 195 151 extern int kdb_unregister(char *); 196 152 #else /* ! CONFIG_KGDB_KDB */ 197 153 static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; } 198 154 static inline void kdb_init(int level) {} 199 155 static inline int kdb_register(char *cmd, kdb_func_t func, char *usage, 200 156 char *help, short minlen) { return 0; } 201 - static inline int kdb_register_repeat(char *cmd, kdb_func_t func, char *usage, 202 - char *help, short minlen, 203 - kdb_repeat_t repeat) { return 0; } 157 + static inline int kdb_register_flags(char *cmd, kdb_func_t func, char *usage, 158 + char *help, short minlen, 159 + kdb_cmdflags_t flags) { return 0; } 204 160 static inline int kdb_unregister(char *cmd) { return 0; } 205 161 #endif /* CONFIG_KGDB_KDB */ 206 162 enum {
+28 -24
kernel/debug/debug_core.c
··· 27 27 * version 2. This program is licensed "as is" without any warranty of any 28 28 * kind, whether express or implied. 29 29 */ 30 + 31 + #define pr_fmt(fmt) "KGDB: " fmt 32 + 30 33 #include <linux/pid_namespace.h> 31 34 #include <linux/clocksource.h> 32 35 #include <linux/serial_core.h> ··· 199 196 return err; 200 197 err = kgdb_arch_remove_breakpoint(&tmp); 201 198 if (err) 202 - printk(KERN_ERR "KGDB: Critical breakpoint error, kernel " 203 - "memory destroyed at: %lx", addr); 199 + pr_err("Critical breakpoint error, kernel memory destroyed at: %lx\n", 200 + addr); 204 201 return err; 205 202 } 206 203 ··· 259 256 error = kgdb_arch_set_breakpoint(&kgdb_break[i]); 260 257 if (error) { 261 258 ret = error; 262 - printk(KERN_INFO "KGDB: BP install failed: %lx", 263 - kgdb_break[i].bpt_addr); 259 + pr_info("BP install failed: %lx\n", 260 + kgdb_break[i].bpt_addr); 264 261 continue; 265 262 } 266 263 ··· 322 319 continue; 323 320 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]); 324 321 if (error) { 325 - printk(KERN_INFO "KGDB: BP remove failed: %lx\n", 326 - kgdb_break[i].bpt_addr); 322 + pr_info("BP remove failed: %lx\n", 323 + kgdb_break[i].bpt_addr); 327 324 ret = error; 328 325 } 329 326 ··· 370 367 goto setundefined; 371 368 error = kgdb_arch_remove_breakpoint(&kgdb_break[i]); 372 369 if (error) 373 - printk(KERN_ERR "KGDB: breakpoint remove failed: %lx\n", 370 + pr_err("breakpoint remove failed: %lx\n", 374 371 kgdb_break[i].bpt_addr); 375 372 setundefined: 376 373 kgdb_break[i].state = BP_UNDEFINED; ··· 403 400 if (print_wait) { 404 401 #ifdef CONFIG_KGDB_KDB 405 402 if (!dbg_kdb_mode) 406 - printk(KERN_CRIT "KGDB: waiting... or $3#33 for KDB\n"); 403 + pr_crit("waiting... or $3#33 for KDB\n"); 407 404 #else 408 - printk(KERN_CRIT "KGDB: Waiting for remote debugger\n"); 405 + pr_crit("Waiting for remote debugger\n"); 409 406 #endif 410 407 } 411 408 return 1; ··· 433 430 exception_level = 0; 434 431 kgdb_skipexception(ks->ex_vector, ks->linux_regs); 435 432 dbg_activate_sw_breakpoints(); 436 - printk(KERN_CRIT "KGDB: re-enter error: breakpoint removed %lx\n", 437 - addr); 433 + pr_crit("re-enter error: breakpoint removed %lx\n", addr); 438 434 WARN_ON_ONCE(1); 439 435 440 436 return 1; ··· 446 444 panic("Recursive entry to debugger"); 447 445 } 448 446 449 - printk(KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n"); 447 + pr_crit("re-enter exception: ALL breakpoints killed\n"); 450 448 #ifdef CONFIG_KGDB_KDB 451 449 /* Allow kdb to debug itself one level */ 452 450 return 0; ··· 473 471 int cpu; 474 472 int trace_on = 0; 475 473 int online_cpus = num_online_cpus(); 474 + u64 time_left; 476 475 477 476 kgdb_info[ks->cpu].enter_kgdb++; 478 477 kgdb_info[ks->cpu].exception_state |= exception_state; ··· 598 595 /* 599 596 * Wait for the other CPUs to be notified and be waiting for us: 600 597 */ 601 - while (kgdb_do_roundup && (atomic_read(&masters_in_kgdb) + 602 - atomic_read(&slaves_in_kgdb)) != online_cpus) 598 + time_left = loops_per_jiffy * HZ; 599 + while (kgdb_do_roundup && --time_left && 600 + (atomic_read(&masters_in_kgdb) + atomic_read(&slaves_in_kgdb)) != 601 + online_cpus) 603 602 cpu_relax(); 603 + if (!time_left) 604 + pr_crit("KGDB: Timed out waiting for secondary CPUs.\n"); 604 605 605 606 /* 606 607 * At this point the primary processor is completely ··· 802 795 static void sysrq_handle_dbg(int key) 803 796 { 804 797 if (!dbg_io_ops) { 805 - printk(KERN_CRIT "ERROR: No KGDB I/O module available\n"); 798 + pr_crit("ERROR: No KGDB I/O module available\n"); 806 799 return; 807 800 } 808 801 if (!kgdb_connected) { 809 802 #ifdef CONFIG_KGDB_KDB 810 803 if (!dbg_kdb_mode) 811 - printk(KERN_CRIT "KGDB or $3#33 for KDB\n"); 804 + pr_crit("KGDB or $3#33 for KDB\n"); 812 805 #else 813 - printk(KERN_CRIT "Entering KGDB\n"); 806 + pr_crit("Entering KGDB\n"); 814 807 #endif 815 808 } 816 809 ··· 952 945 { 953 946 kgdb_break_asap = 0; 954 947 955 - printk(KERN_CRIT "kgdb: Waiting for connection from remote gdb...\n"); 948 + pr_crit("Waiting for connection from remote gdb...\n"); 956 949 kgdb_breakpoint(); 957 950 } 958 951 ··· 971 964 if (dbg_io_ops) { 972 965 spin_unlock(&kgdb_registration_lock); 973 966 974 - printk(KERN_ERR "kgdb: Another I/O driver is already " 975 - "registered with KGDB.\n"); 967 + pr_err("Another I/O driver is already registered with KGDB\n"); 976 968 return -EBUSY; 977 969 } 978 970 ··· 987 981 988 982 spin_unlock(&kgdb_registration_lock); 989 983 990 - printk(KERN_INFO "kgdb: Registered I/O driver %s.\n", 991 - new_dbg_io_ops->name); 984 + pr_info("Registered I/O driver %s\n", new_dbg_io_ops->name); 992 985 993 986 /* Arm KGDB now. */ 994 987 kgdb_register_callbacks(); ··· 1022 1017 1023 1018 spin_unlock(&kgdb_registration_lock); 1024 1019 1025 - printk(KERN_INFO 1026 - "kgdb: Unregistered I/O driver %s, debugger disabled.\n", 1020 + pr_info("Unregistered I/O driver %s, debugger disabled\n", 1027 1021 old_dbg_io_ops->name); 1028 1022 } 1029 1023 EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
+21 -14
kernel/debug/kdb/kdb_bp.c
··· 531 531 for (i = 0, bp = kdb_breakpoints; i < KDB_MAXBPT; i++, bp++) 532 532 bp->bp_free = 1; 533 533 534 - kdb_register_repeat("bp", kdb_bp, "[<vaddr>]", 535 - "Set/Display breakpoints", 0, KDB_REPEAT_NO_ARGS); 536 - kdb_register_repeat("bl", kdb_bp, "[<vaddr>]", 537 - "Display breakpoints", 0, KDB_REPEAT_NO_ARGS); 534 + kdb_register_flags("bp", kdb_bp, "[<vaddr>]", 535 + "Set/Display breakpoints", 0, 536 + KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS); 537 + kdb_register_flags("bl", kdb_bp, "[<vaddr>]", 538 + "Display breakpoints", 0, 539 + KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS); 538 540 if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) 539 - kdb_register_repeat("bph", kdb_bp, "[<vaddr>]", 540 - "[datar [length]|dataw [length]] Set hw brk", 0, KDB_REPEAT_NO_ARGS); 541 - kdb_register_repeat("bc", kdb_bc, "<bpnum>", 542 - "Clear Breakpoint", 0, KDB_REPEAT_NONE); 543 - kdb_register_repeat("be", kdb_bc, "<bpnum>", 544 - "Enable Breakpoint", 0, KDB_REPEAT_NONE); 545 - kdb_register_repeat("bd", kdb_bc, "<bpnum>", 546 - "Disable Breakpoint", 0, KDB_REPEAT_NONE); 541 + kdb_register_flags("bph", kdb_bp, "[<vaddr>]", 542 + "[datar [length]|dataw [length]] Set hw brk", 0, 543 + KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS); 544 + kdb_register_flags("bc", kdb_bc, "<bpnum>", 545 + "Clear Breakpoint", 0, 546 + KDB_ENABLE_FLOW_CTRL); 547 + kdb_register_flags("be", kdb_bc, "<bpnum>", 548 + "Enable Breakpoint", 0, 549 + KDB_ENABLE_FLOW_CTRL); 550 + kdb_register_flags("bd", kdb_bc, "<bpnum>", 551 + "Disable Breakpoint", 0, 552 + KDB_ENABLE_FLOW_CTRL); 547 553 548 - kdb_register_repeat("ss", kdb_ss, "", 549 - "Single Step", 1, KDB_REPEAT_NO_ARGS); 554 + kdb_register_flags("ss", kdb_ss, "", 555 + "Single Step", 1, 556 + KDB_ENABLE_FLOW_CTRL | KDB_REPEAT_NO_ARGS); 550 557 /* 551 558 * Architecture dependent initialization. 552 559 */
+4
kernel/debug/kdb/kdb_debugger.c
··· 129 129 ks->pass_exception = 1; 130 130 KDB_FLAG_SET(CATASTROPHIC); 131 131 } 132 + /* set CATASTROPHIC if the system contains unresponsive processors */ 133 + for_each_online_cpu(i) 134 + if (!kgdb_info[i].enter_kgdb) 135 + KDB_FLAG_SET(CATASTROPHIC); 132 136 if (KDB_STATE(SSBPT) && reason == KDB_REASON_SSTEP) { 133 137 KDB_STATE_CLEAR(SSBPT); 134 138 KDB_STATE_CLEAR(DOING_SS);
+170 -95
kernel/debug/kdb/kdb_main.c
··· 12 12 */ 13 13 14 14 #include <linux/ctype.h> 15 + #include <linux/types.h> 15 16 #include <linux/string.h> 16 17 #include <linux/kernel.h> 17 18 #include <linux/kmsg_dump.h> ··· 24 23 #include <linux/vmalloc.h> 25 24 #include <linux/atomic.h> 26 25 #include <linux/module.h> 26 + #include <linux/moduleparam.h> 27 27 #include <linux/mm.h> 28 28 #include <linux/init.h> 29 29 #include <linux/kallsyms.h> ··· 43 41 #include <linux/uaccess.h> 44 42 #include <linux/slab.h> 45 43 #include "kdb_private.h" 44 + 45 + #undef MODULE_PARAM_PREFIX 46 + #define MODULE_PARAM_PREFIX "kdb." 47 + 48 + static int kdb_cmd_enabled = CONFIG_KDB_DEFAULT_ENABLE; 49 + module_param_named(cmd_enable, kdb_cmd_enabled, int, 0600); 46 50 47 51 #define GREP_LEN 256 48 52 char kdb_grep_string[GREP_LEN]; ··· 129 121 KDBMSG(BADLENGTH, "Invalid length field"), 130 122 KDBMSG(NOBP, "No Breakpoint exists"), 131 123 KDBMSG(BADADDR, "Invalid address"), 124 + KDBMSG(NOPERM, "Permission denied"), 132 125 }; 133 126 #undef KDBMSG 134 127 ··· 194 185 p = krp->p; 195 186 #endif 196 187 return p; 188 + } 189 + 190 + /* 191 + * Check whether the flags of the current command and the permissions 192 + * of the kdb console has allow a command to be run. 193 + */ 194 + static inline bool kdb_check_flags(kdb_cmdflags_t flags, int permissions, 195 + bool no_args) 196 + { 197 + /* permissions comes from userspace so needs massaging slightly */ 198 + permissions &= KDB_ENABLE_MASK; 199 + permissions |= KDB_ENABLE_ALWAYS_SAFE; 200 + 201 + /* some commands change group when launched with no arguments */ 202 + if (no_args) 203 + permissions |= permissions << KDB_ENABLE_NO_ARGS_SHIFT; 204 + 205 + flags |= KDB_ENABLE_ALL; 206 + 207 + return permissions & flags; 197 208 } 198 209 199 210 /* ··· 505 476 kdb_symtab_t symtab; 506 477 507 478 /* 479 + * If the enable flags prohibit both arbitrary memory access 480 + * and flow control then there are no reasonable grounds to 481 + * provide symbol lookup. 482 + */ 483 + if (!kdb_check_flags(KDB_ENABLE_MEM_READ | KDB_ENABLE_FLOW_CTRL, 484 + kdb_cmd_enabled, false)) 485 + return KDB_NOPERM; 486 + 487 + /* 508 488 * Process arguments which follow the following syntax: 509 489 * 510 490 * symbol | numeric-address [+/- numeric-offset] ··· 679 641 if (!s->count) 680 642 s->usable = 0; 681 643 if (s->usable) 682 - kdb_register(s->name, kdb_exec_defcmd, 683 - s->usage, s->help, 0); 644 + /* macros are always safe because when executed each 645 + * internal command re-enters kdb_parse() and is 646 + * safety checked individually. 647 + */ 648 + kdb_register_flags(s->name, kdb_exec_defcmd, s->usage, 649 + s->help, 0, 650 + KDB_ENABLE_ALWAYS_SAFE); 684 651 return 0; 685 652 } 686 653 if (!s->usable) ··· 1046 1003 1047 1004 if (i < kdb_max_commands) { 1048 1005 int result; 1006 + 1007 + if (!kdb_check_flags(tp->cmd_flags, kdb_cmd_enabled, argc <= 1)) 1008 + return KDB_NOPERM; 1009 + 1049 1010 KDB_STATE_SET(CMD); 1050 1011 result = (*tp->cmd_func)(argc-1, (const char **)argv); 1051 1012 if (result && ignore_errors && result > KDB_CMD_GO) 1052 1013 result = 0; 1053 1014 KDB_STATE_CLEAR(CMD); 1054 - switch (tp->cmd_repeat) { 1055 - case KDB_REPEAT_NONE: 1056 - argc = 0; 1057 - if (argv[0]) 1058 - *(argv[0]) = '\0'; 1059 - break; 1060 - case KDB_REPEAT_NO_ARGS: 1061 - argc = 1; 1062 - if (argv[1]) 1063 - *(argv[1]) = '\0'; 1064 - break; 1065 - case KDB_REPEAT_WITH_ARGS: 1066 - break; 1067 - } 1015 + 1016 + if (tp->cmd_flags & KDB_REPEAT_WITH_ARGS) 1017 + return result; 1018 + 1019 + argc = tp->cmd_flags & KDB_REPEAT_NO_ARGS ? 1 : 0; 1020 + if (argv[argc]) 1021 + *(argv[argc]) = '\0'; 1068 1022 return result; 1069 1023 } 1070 1024 ··· 1961 1921 */ 1962 1922 static int kdb_sr(int argc, const char **argv) 1963 1923 { 1924 + bool check_mask = 1925 + !kdb_check_flags(KDB_ENABLE_ALL, kdb_cmd_enabled, false); 1926 + 1964 1927 if (argc != 1) 1965 1928 return KDB_ARGCOUNT; 1929 + 1966 1930 kdb_trap_printk++; 1967 - __handle_sysrq(*argv[1], false); 1931 + __handle_sysrq(*argv[1], check_mask); 1968 1932 kdb_trap_printk--; 1969 1933 1970 1934 return 0; ··· 2201 2157 for (start_cpu = -1, i = 0; i < NR_CPUS; i++) { 2202 2158 if (!cpu_online(i)) { 2203 2159 state = 'F'; /* cpu is offline */ 2160 + } else if (!kgdb_info[i].enter_kgdb) { 2161 + state = 'D'; /* cpu is online but unresponsive */ 2204 2162 } else { 2205 2163 state = ' '; /* cpu is responding to kdb */ 2206 2164 if (kdb_task_state_char(KDB_TSK(i)) == 'I') ··· 2256 2210 /* 2257 2211 * Validate cpunum 2258 2212 */ 2259 - if ((cpunum > NR_CPUS) || !cpu_online(cpunum)) 2213 + if ((cpunum > NR_CPUS) || !kgdb_info[cpunum].enter_kgdb) 2260 2214 return KDB_BADCPUNUM; 2261 2215 2262 2216 dbg_switch_cpu = cpunum; ··· 2420 2374 if (KDB_FLAG(CMD_INTERRUPT)) 2421 2375 return 0; 2422 2376 if (!kt->cmd_name) 2377 + continue; 2378 + if (!kdb_check_flags(kt->cmd_flags, kdb_cmd_enabled, true)) 2423 2379 continue; 2424 2380 if (strlen(kt->cmd_usage) > 20) 2425 2381 space = "\n "; ··· 2677 2629 } 2678 2630 2679 2631 /* 2680 - * kdb_register_repeat - This function is used to register a kernel 2632 + * kdb_register_flags - This function is used to register a kernel 2681 2633 * debugger command. 2682 2634 * Inputs: 2683 2635 * cmd Command name ··· 2689 2641 * zero for success, one if a duplicate command. 2690 2642 */ 2691 2643 #define kdb_command_extend 50 /* arbitrary */ 2692 - int kdb_register_repeat(char *cmd, 2693 - kdb_func_t func, 2694 - char *usage, 2695 - char *help, 2696 - short minlen, 2697 - kdb_repeat_t repeat) 2644 + int kdb_register_flags(char *cmd, 2645 + kdb_func_t func, 2646 + char *usage, 2647 + char *help, 2648 + short minlen, 2649 + kdb_cmdflags_t flags) 2698 2650 { 2699 2651 int i; 2700 2652 kdbtab_t *kp; ··· 2742 2694 kp->cmd_func = func; 2743 2695 kp->cmd_usage = usage; 2744 2696 kp->cmd_help = help; 2745 - kp->cmd_flags = 0; 2746 2697 kp->cmd_minlen = minlen; 2747 - kp->cmd_repeat = repeat; 2698 + kp->cmd_flags = flags; 2748 2699 2749 2700 return 0; 2750 2701 } 2751 - EXPORT_SYMBOL_GPL(kdb_register_repeat); 2702 + EXPORT_SYMBOL_GPL(kdb_register_flags); 2752 2703 2753 2704 2754 2705 /* 2755 2706 * kdb_register - Compatibility register function for commands that do 2756 2707 * not need to specify a repeat state. Equivalent to 2757 - * kdb_register_repeat with KDB_REPEAT_NONE. 2708 + * kdb_register_flags with flags set to 0. 2758 2709 * Inputs: 2759 2710 * cmd Command name 2760 2711 * func Function to execute the command ··· 2768 2721 char *help, 2769 2722 short minlen) 2770 2723 { 2771 - return kdb_register_repeat(cmd, func, usage, help, minlen, 2772 - KDB_REPEAT_NONE); 2724 + return kdb_register_flags(cmd, func, usage, help, minlen, 0); 2773 2725 } 2774 2726 EXPORT_SYMBOL_GPL(kdb_register); 2775 2727 ··· 2810 2764 for_each_kdbcmd(kp, i) 2811 2765 kp->cmd_name = NULL; 2812 2766 2813 - kdb_register_repeat("md", kdb_md, "<vaddr>", 2767 + kdb_register_flags("md", kdb_md, "<vaddr>", 2814 2768 "Display Memory Contents, also mdWcN, e.g. md8c1", 1, 2815 - KDB_REPEAT_NO_ARGS); 2816 - kdb_register_repeat("mdr", kdb_md, "<vaddr> <bytes>", 2817 - "Display Raw Memory", 0, KDB_REPEAT_NO_ARGS); 2818 - kdb_register_repeat("mdp", kdb_md, "<paddr> <bytes>", 2819 - "Display Physical Memory", 0, KDB_REPEAT_NO_ARGS); 2820 - kdb_register_repeat("mds", kdb_md, "<vaddr>", 2821 - "Display Memory Symbolically", 0, KDB_REPEAT_NO_ARGS); 2822 - kdb_register_repeat("mm", kdb_mm, "<vaddr> <contents>", 2823 - "Modify Memory Contents", 0, KDB_REPEAT_NO_ARGS); 2824 - kdb_register_repeat("go", kdb_go, "[<vaddr>]", 2825 - "Continue Execution", 1, KDB_REPEAT_NONE); 2826 - kdb_register_repeat("rd", kdb_rd, "", 2827 - "Display Registers", 0, KDB_REPEAT_NONE); 2828 - kdb_register_repeat("rm", kdb_rm, "<reg> <contents>", 2829 - "Modify Registers", 0, KDB_REPEAT_NONE); 2830 - kdb_register_repeat("ef", kdb_ef, "<vaddr>", 2831 - "Display exception frame", 0, KDB_REPEAT_NONE); 2832 - kdb_register_repeat("bt", kdb_bt, "[<vaddr>]", 2833 - "Stack traceback", 1, KDB_REPEAT_NONE); 2834 - kdb_register_repeat("btp", kdb_bt, "<pid>", 2835 - "Display stack for process <pid>", 0, KDB_REPEAT_NONE); 2836 - kdb_register_repeat("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]", 2837 - "Backtrace all processes matching state flag", 0, KDB_REPEAT_NONE); 2838 - kdb_register_repeat("btc", kdb_bt, "", 2839 - "Backtrace current process on each cpu", 0, KDB_REPEAT_NONE); 2840 - kdb_register_repeat("btt", kdb_bt, "<vaddr>", 2769 + KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS); 2770 + kdb_register_flags("mdr", kdb_md, "<vaddr> <bytes>", 2771 + "Display Raw Memory", 0, 2772 + KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS); 2773 + kdb_register_flags("mdp", kdb_md, "<paddr> <bytes>", 2774 + "Display Physical Memory", 0, 2775 + KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS); 2776 + kdb_register_flags("mds", kdb_md, "<vaddr>", 2777 + "Display Memory Symbolically", 0, 2778 + KDB_ENABLE_MEM_READ | KDB_REPEAT_NO_ARGS); 2779 + kdb_register_flags("mm", kdb_mm, "<vaddr> <contents>", 2780 + "Modify Memory Contents", 0, 2781 + KDB_ENABLE_MEM_WRITE | KDB_REPEAT_NO_ARGS); 2782 + kdb_register_flags("go", kdb_go, "[<vaddr>]", 2783 + "Continue Execution", 1, 2784 + KDB_ENABLE_REG_WRITE | KDB_ENABLE_ALWAYS_SAFE_NO_ARGS); 2785 + kdb_register_flags("rd", kdb_rd, "", 2786 + "Display Registers", 0, 2787 + KDB_ENABLE_REG_READ); 2788 + kdb_register_flags("rm", kdb_rm, "<reg> <contents>", 2789 + "Modify Registers", 0, 2790 + KDB_ENABLE_REG_WRITE); 2791 + kdb_register_flags("ef", kdb_ef, "<vaddr>", 2792 + "Display exception frame", 0, 2793 + KDB_ENABLE_MEM_READ); 2794 + kdb_register_flags("bt", kdb_bt, "[<vaddr>]", 2795 + "Stack traceback", 1, 2796 + KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS); 2797 + kdb_register_flags("btp", kdb_bt, "<pid>", 2798 + "Display stack for process <pid>", 0, 2799 + KDB_ENABLE_INSPECT); 2800 + kdb_register_flags("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]", 2801 + "Backtrace all processes matching state flag", 0, 2802 + KDB_ENABLE_INSPECT); 2803 + kdb_register_flags("btc", kdb_bt, "", 2804 + "Backtrace current process on each cpu", 0, 2805 + KDB_ENABLE_INSPECT); 2806 + kdb_register_flags("btt", kdb_bt, "<vaddr>", 2841 2807 "Backtrace process given its struct task address", 0, 2842 - KDB_REPEAT_NONE); 2843 - kdb_register_repeat("env", kdb_env, "", 2844 - "Show environment variables", 0, KDB_REPEAT_NONE); 2845 - kdb_register_repeat("set", kdb_set, "", 2846 - "Set environment variables", 0, KDB_REPEAT_NONE); 2847 - kdb_register_repeat("help", kdb_help, "", 2848 - "Display Help Message", 1, KDB_REPEAT_NONE); 2849 - kdb_register_repeat("?", kdb_help, "", 2850 - "Display Help Message", 0, KDB_REPEAT_NONE); 2851 - kdb_register_repeat("cpu", kdb_cpu, "<cpunum>", 2852 - "Switch to new cpu", 0, KDB_REPEAT_NONE); 2853 - kdb_register_repeat("kgdb", kdb_kgdb, "", 2854 - "Enter kgdb mode", 0, KDB_REPEAT_NONE); 2855 - kdb_register_repeat("ps", kdb_ps, "[<flags>|A]", 2856 - "Display active task list", 0, KDB_REPEAT_NONE); 2857 - kdb_register_repeat("pid", kdb_pid, "<pidnum>", 2858 - "Switch to another task", 0, KDB_REPEAT_NONE); 2859 - kdb_register_repeat("reboot", kdb_reboot, "", 2860 - "Reboot the machine immediately", 0, KDB_REPEAT_NONE); 2808 + KDB_ENABLE_MEM_READ | KDB_ENABLE_INSPECT_NO_ARGS); 2809 + kdb_register_flags("env", kdb_env, "", 2810 + "Show environment variables", 0, 2811 + KDB_ENABLE_ALWAYS_SAFE); 2812 + kdb_register_flags("set", kdb_set, "", 2813 + "Set environment variables", 0, 2814 + KDB_ENABLE_ALWAYS_SAFE); 2815 + kdb_register_flags("help", kdb_help, "", 2816 + "Display Help Message", 1, 2817 + KDB_ENABLE_ALWAYS_SAFE); 2818 + kdb_register_flags("?", kdb_help, "", 2819 + "Display Help Message", 0, 2820 + KDB_ENABLE_ALWAYS_SAFE); 2821 + kdb_register_flags("cpu", kdb_cpu, "<cpunum>", 2822 + "Switch to new cpu", 0, 2823 + KDB_ENABLE_ALWAYS_SAFE_NO_ARGS); 2824 + kdb_register_flags("kgdb", kdb_kgdb, "", 2825 + "Enter kgdb mode", 0, 0); 2826 + kdb_register_flags("ps", kdb_ps, "[<flags>|A]", 2827 + "Display active task list", 0, 2828 + KDB_ENABLE_INSPECT); 2829 + kdb_register_flags("pid", kdb_pid, "<pidnum>", 2830 + "Switch to another task", 0, 2831 + KDB_ENABLE_INSPECT); 2832 + kdb_register_flags("reboot", kdb_reboot, "", 2833 + "Reboot the machine immediately", 0, 2834 + KDB_ENABLE_REBOOT); 2861 2835 #if defined(CONFIG_MODULES) 2862 - kdb_register_repeat("lsmod", kdb_lsmod, "", 2863 - "List loaded kernel modules", 0, KDB_REPEAT_NONE); 2836 + kdb_register_flags("lsmod", kdb_lsmod, "", 2837 + "List loaded kernel modules", 0, 2838 + KDB_ENABLE_INSPECT); 2864 2839 #endif 2865 2840 #if defined(CONFIG_MAGIC_SYSRQ) 2866 - kdb_register_repeat("sr", kdb_sr, "<key>", 2867 - "Magic SysRq key", 0, KDB_REPEAT_NONE); 2841 + kdb_register_flags("sr", kdb_sr, "<key>", 2842 + "Magic SysRq key", 0, 2843 + KDB_ENABLE_ALWAYS_SAFE); 2868 2844 #endif 2869 2845 #if defined(CONFIG_PRINTK) 2870 - kdb_register_repeat("dmesg", kdb_dmesg, "[lines]", 2871 - "Display syslog buffer", 0, KDB_REPEAT_NONE); 2846 + kdb_register_flags("dmesg", kdb_dmesg, "[lines]", 2847 + "Display syslog buffer", 0, 2848 + KDB_ENABLE_ALWAYS_SAFE); 2872 2849 #endif 2873 2850 if (arch_kgdb_ops.enable_nmi) { 2874 - kdb_register_repeat("disable_nmi", kdb_disable_nmi, "", 2875 - "Disable NMI entry to KDB", 0, KDB_REPEAT_NONE); 2851 + kdb_register_flags("disable_nmi", kdb_disable_nmi, "", 2852 + "Disable NMI entry to KDB", 0, 2853 + KDB_ENABLE_ALWAYS_SAFE); 2876 2854 } 2877 - kdb_register_repeat("defcmd", kdb_defcmd, "name \"usage\" \"help\"", 2878 - "Define a set of commands, down to endefcmd", 0, KDB_REPEAT_NONE); 2879 - kdb_register_repeat("kill", kdb_kill, "<-signal> <pid>", 2880 - "Send a signal to a process", 0, KDB_REPEAT_NONE); 2881 - kdb_register_repeat("summary", kdb_summary, "", 2882 - "Summarize the system", 4, KDB_REPEAT_NONE); 2883 - kdb_register_repeat("per_cpu", kdb_per_cpu, "<sym> [<bytes>] [<cpu>]", 2884 - "Display per_cpu variables", 3, KDB_REPEAT_NONE); 2885 - kdb_register_repeat("grephelp", kdb_grep_help, "", 2886 - "Display help on | grep", 0, KDB_REPEAT_NONE); 2855 + kdb_register_flags("defcmd", kdb_defcmd, "name \"usage\" \"help\"", 2856 + "Define a set of commands, down to endefcmd", 0, 2857 + KDB_ENABLE_ALWAYS_SAFE); 2858 + kdb_register_flags("kill", kdb_kill, "<-signal> <pid>", 2859 + "Send a signal to a process", 0, 2860 + KDB_ENABLE_SIGNAL); 2861 + kdb_register_flags("summary", kdb_summary, "", 2862 + "Summarize the system", 4, 2863 + KDB_ENABLE_ALWAYS_SAFE); 2864 + kdb_register_flags("per_cpu", kdb_per_cpu, "<sym> [<bytes>] [<cpu>]", 2865 + "Display per_cpu variables", 3, 2866 + KDB_ENABLE_MEM_READ); 2867 + kdb_register_flags("grephelp", kdb_grep_help, "", 2868 + "Display help on | grep", 0, 2869 + KDB_ENABLE_ALWAYS_SAFE); 2887 2870 } 2888 2871 2889 2872 /* Execute any commands defined in kdb_cmds. */
+1 -2
kernel/debug/kdb/kdb_private.h
··· 172 172 kdb_func_t cmd_func; /* Function to execute command */ 173 173 char *cmd_usage; /* Usage String for this command */ 174 174 char *cmd_help; /* Help message for this command */ 175 - short cmd_flags; /* Parsing flags */ 176 175 short cmd_minlen; /* Minimum legal # command 177 176 * chars required */ 178 - kdb_repeat_t cmd_repeat; /* Does command auto repeat on enter? */ 177 + kdb_cmdflags_t cmd_flags; /* Command behaviour flags */ 179 178 } kdbtab_t; 180 179 181 180 extern int kdb_bt(int, const char **); /* KDB display back trace */
+2 -2
kernel/trace/trace_kdb.c
··· 132 132 133 133 static __init int kdb_ftrace_register(void) 134 134 { 135 - kdb_register_repeat("ftdump", kdb_ftdump, "[skip_#lines] [cpu]", 136 - "Dump ftrace log", 0, KDB_REPEAT_NONE); 135 + kdb_register_flags("ftdump", kdb_ftdump, "[skip_#lines] [cpu]", 136 + "Dump ftrace log", 0, KDB_ENABLE_ALWAYS_SAFE); 137 137 return 0; 138 138 } 139 139
+25
lib/Kconfig.kgdb
··· 73 73 help 74 74 KDB frontend for kernel 75 75 76 + config KDB_DEFAULT_ENABLE 77 + hex "KDB: Select kdb command functions to be enabled by default" 78 + depends on KGDB_KDB 79 + default 0x1 80 + help 81 + Specifiers which kdb commands are enabled by default. This may 82 + be set to 1 or 0 to enable all commands or disable almost all 83 + commands. 84 + 85 + Alternatively the following bitmask applies: 86 + 87 + 0x0002 - allow arbitrary reads from memory and symbol lookup 88 + 0x0004 - allow arbitrary writes to memory 89 + 0x0008 - allow current register state to be inspected 90 + 0x0010 - allow current register state to be modified 91 + 0x0020 - allow passive inspection (backtrace, process list, lsmod) 92 + 0x0040 - allow flow control management (breakpoint, single step) 93 + 0x0080 - enable signalling of processes 94 + 0x0100 - allow machine to be rebooted 95 + 96 + The config option merely sets the default at boot time. Both 97 + issuing 'echo X > /sys/module/kdb/parameters/cmd_enable' or 98 + setting with kdb.cmd_enable=X kernel command line option will 99 + override the default settings. 100 + 76 101 config KDB_KEYBOARD 77 102 bool "KGDB_KDB: keyboard as input device" 78 103 depends on VT && KGDB_KDB