Skip to content

Commit a37372f

Browse files
committed
kdb: Prevent kernel oops with kdb_defcmd
The kdb_defcmd can only be used to display the available command aliases while using the kernel debug shell. If you try to define a new macro while the kernel debugger is active it will oops. The debug shell macros must use pre-allocated memory set aside at the time kdb_init() is run, and the kdb_defcmd is restricted to only working at the time that the kdb_init sequence is being run, which only occurs if you actually activate the kernel debugger. Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
1 parent 1b2caa2 commit a37372f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎kernel/debug/kdb/kdb_main.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ static int kdb_defcmd(int argc, const char **argv)
681681
}
682682
if (argc != 3)
683683
return KDB_ARGCOUNT;
684+
if (in_dbg_master()) {
685+
kdb_printf("Command only available during kdb_init()\n");
686+
return KDB_NOTIMP;
687+
}
684688
defcmd_set = kmalloc((defcmd_set_count + 1) * sizeof(*defcmd_set),
685689
GFP_KDB);
686690
if (!defcmd_set)
@@ -2796,8 +2800,8 @@ static void __init kdb_inittab(void)
27962800
"Stack traceback", 1, KDB_REPEAT_NONE);
27972801
kdb_register_repeat("btp", kdb_bt, "<pid>",
27982802
"Display stack for process <pid>", 0, KDB_REPEAT_NONE);
2799-
kdb_register_repeat("bta", kdb_bt, "[DRSTCZEUIMA]",
2800-
"Display stack all processes", 0, KDB_REPEAT_NONE);
2803+
kdb_register_repeat("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]",
2804+
"Backtrace all processes matching state flag", 0, KDB_REPEAT_NONE);
28012805
kdb_register_repeat("btc", kdb_bt, "",
28022806
"Backtrace current process on each cpu", 0, KDB_REPEAT_NONE);
28032807
kdb_register_repeat("btt", kdb_bt, "<vaddr>",

0 commit comments

Comments
 (0)