diff options
-rw-r--r-- | include/linux/kdb.h | 1 | ||||
-rw-r--r-- | kernel/debug/kdb/kdb_main.c | 30 |
2 files changed, 30 insertions, 1 deletions
diff --git a/include/linux/kdb.h b/include/linux/kdb.h index f1fe36185c17..75ae2e2631fc 100644 --- a/include/linux/kdb.h +++ b/include/linux/kdb.h | |||
@@ -105,6 +105,7 @@ extern atomic_t kdb_event; | |||
105 | #define KDB_BADLENGTH (-19) | 105 | #define KDB_BADLENGTH (-19) |
106 | #define KDB_NOBP (-20) | 106 | #define KDB_NOBP (-20) |
107 | #define KDB_BADADDR (-21) | 107 | #define KDB_BADADDR (-21) |
108 | #define KDB_NOPERM (-22) | ||
108 | 109 | ||
109 | /* | 110 | /* |
110 | * kdb_diemsg | 111 | * kdb_diemsg |
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index fae1fc3962f8..fe1ac56b62e9 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c | |||
@@ -12,6 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/ctype.h> | 14 | #include <linux/ctype.h> |
15 | #include <linux/types.h> | ||
15 | #include <linux/string.h> | 16 | #include <linux/string.h> |
16 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
17 | #include <linux/kmsg_dump.h> | 18 | #include <linux/kmsg_dump.h> |
@@ -23,6 +24,7 @@ | |||
23 | #include <linux/vmalloc.h> | 24 | #include <linux/vmalloc.h> |
24 | #include <linux/atomic.h> | 25 | #include <linux/atomic.h> |
25 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/moduleparam.h> | ||
26 | #include <linux/mm.h> | 28 | #include <linux/mm.h> |
27 | #include <linux/init.h> | 29 | #include <linux/init.h> |
28 | #include <linux/kallsyms.h> | 30 | #include <linux/kallsyms.h> |
@@ -42,6 +44,12 @@ | |||
42 | #include <linux/slab.h> | 44 | #include <linux/slab.h> |
43 | #include "kdb_private.h" | 45 | #include "kdb_private.h" |
44 | 46 | ||
47 | #undef MODULE_PARAM_PREFIX | ||
48 | #define MODULE_PARAM_PREFIX "kdb." | ||
49 | |||
50 | static int kdb_cmd_enabled; | ||
51 | module_param_named(cmd_enable, kdb_cmd_enabled, int, 0600); | ||
52 | |||
45 | #define GREP_LEN 256 | 53 | #define GREP_LEN 256 |
46 | char kdb_grep_string[GREP_LEN]; | 54 | char kdb_grep_string[GREP_LEN]; |
47 | int kdb_grepping_flag; | 55 | int kdb_grepping_flag; |
@@ -121,6 +129,7 @@ static kdbmsg_t kdbmsgs[] = { | |||
121 | KDBMSG(BADLENGTH, "Invalid length field"), | 129 | KDBMSG(BADLENGTH, "Invalid length field"), |
122 | KDBMSG(NOBP, "No Breakpoint exists"), | 130 | KDBMSG(NOBP, "No Breakpoint exists"), |
123 | KDBMSG(BADADDR, "Invalid address"), | 131 | KDBMSG(BADADDR, "Invalid address"), |
132 | KDBMSG(NOPERM, "Permission denied"), | ||
124 | }; | 133 | }; |
125 | #undef KDBMSG | 134 | #undef KDBMSG |
126 | 135 | ||
@@ -496,6 +505,15 @@ int kdbgetaddrarg(int argc, const char **argv, int *nextarg, | |||
496 | kdb_symtab_t symtab; | 505 | kdb_symtab_t symtab; |
497 | 506 | ||
498 | /* | 507 | /* |
508 | * If the enable flags prohibit both arbitrary memory access | ||
509 | * and flow control then there are no reasonable grounds to | ||
510 | * provide symbol lookup. | ||
511 | */ | ||
512 | if (!kdb_check_flags(KDB_ENABLE_MEM_READ | KDB_ENABLE_FLOW_CTRL, | ||
513 | kdb_cmd_enabled, false)) | ||
514 | return KDB_NOPERM; | ||
515 | |||
516 | /* | ||
499 | * Process arguments which follow the following syntax: | 517 | * Process arguments which follow the following syntax: |
500 | * | 518 | * |
501 | * symbol | numeric-address [+/- numeric-offset] | 519 | * symbol | numeric-address [+/- numeric-offset] |
@@ -1028,6 +1046,10 @@ int kdb_parse(const char *cmdstr) | |||
1028 | 1046 | ||
1029 | if (i < kdb_max_commands) { | 1047 | if (i < kdb_max_commands) { |
1030 | int result; | 1048 | int result; |
1049 | |||
1050 | if (!kdb_check_flags(tp->cmd_flags, kdb_cmd_enabled, argc <= 1)) | ||
1051 | return KDB_NOPERM; | ||
1052 | |||
1031 | KDB_STATE_SET(CMD); | 1053 | KDB_STATE_SET(CMD); |
1032 | result = (*tp->cmd_func)(argc-1, (const char **)argv); | 1054 | result = (*tp->cmd_func)(argc-1, (const char **)argv); |
1033 | if (result && ignore_errors && result > KDB_CMD_GO) | 1055 | if (result && ignore_errors && result > KDB_CMD_GO) |
@@ -1939,10 +1961,14 @@ static int kdb_rm(int argc, const char **argv) | |||
1939 | */ | 1961 | */ |
1940 | static int kdb_sr(int argc, const char **argv) | 1962 | static int kdb_sr(int argc, const char **argv) |
1941 | { | 1963 | { |
1964 | bool check_mask = | ||
1965 | !kdb_check_flags(KDB_ENABLE_ALL, kdb_cmd_enabled, false); | ||
1966 | |||
1942 | if (argc != 1) | 1967 | if (argc != 1) |
1943 | return KDB_ARGCOUNT; | 1968 | return KDB_ARGCOUNT; |
1969 | |||
1944 | kdb_trap_printk++; | 1970 | kdb_trap_printk++; |
1945 | __handle_sysrq(*argv[1], false); | 1971 | __handle_sysrq(*argv[1], check_mask); |
1946 | kdb_trap_printk--; | 1972 | kdb_trap_printk--; |
1947 | 1973 | ||
1948 | return 0; | 1974 | return 0; |
@@ -2393,6 +2419,8 @@ static int kdb_help(int argc, const char **argv) | |||
2393 | return 0; | 2419 | return 0; |
2394 | if (!kt->cmd_name) | 2420 | if (!kt->cmd_name) |
2395 | continue; | 2421 | continue; |
2422 | if (!kdb_check_flags(kt->cmd_flags, kdb_cmd_enabled, true)) | ||
2423 | continue; | ||
2396 | if (strlen(kt->cmd_usage) > 20) | 2424 | if (strlen(kt->cmd_usage) > 20) |
2397 | space = "\n "; | 2425 | space = "\n "; |
2398 | kdb_printf("%-15.15s %-20s%s%s\n", kt->cmd_name, | 2426 | kdb_printf("%-15.15s %-20s%s%s\n", kt->cmd_name, |