aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJovi Zhang <bookjovi@gmail.com>2010-11-10 08:22:18 -0500
committerJason Wessel <jason.wessel@windriver.com>2010-11-17 14:54:57 -0500
commit5450d904054b4ed582793ad6ecb5469f03cc4c46 (patch)
tree025a63a774f56b02e001cd49ead0c26f428cbb9b
parent85e76ab50aecbdc9011806f2f8943450ccb0d93c (diff)
kdb: fix crash when KDB_BASE_CMD_MAX is exceeded
When the number of dyanmic kdb commands exceeds KDB_BASE_CMD_MAX, the kernel will fault. Signed-off-by: Jovi Zhang <bookjovi@gmail.com> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
-rw-r--r--kernel/debug/kdb/kdb_main.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 3ab3feee7840..a6e729766821 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -82,7 +82,7 @@ static kdbtab_t kdb_base_commands[50];
82#define for_each_kdbcmd(cmd, num) \ 82#define for_each_kdbcmd(cmd, num) \
83 for ((cmd) = kdb_base_commands, (num) = 0; \ 83 for ((cmd) = kdb_base_commands, (num) = 0; \
84 num < kdb_max_commands; \ 84 num < kdb_max_commands; \
85 num == KDB_BASE_CMD_MAX ? cmd = kdb_commands : cmd++, num++) 85 num++, num == KDB_BASE_CMD_MAX ? cmd = kdb_commands : cmd++)
86 86
87typedef struct _kdbmsg { 87typedef struct _kdbmsg {
88 int km_diag; /* kdb diagnostic */ 88 int km_diag; /* kdb diagnostic */
@@ -646,7 +646,7 @@ static int kdb_defcmd2(const char *cmdstr, const char *argv0)
646 } 646 }
647 if (!s->usable) 647 if (!s->usable)
648 return KDB_NOTIMP; 648 return KDB_NOTIMP;
649 s->command = kmalloc((s->count + 1) * sizeof(*(s->command)), GFP_KDB); 649 s->command = kzalloc((s->count + 1) * sizeof(*(s->command)), GFP_KDB);
650 if (!s->command) { 650 if (!s->command) {
651 kdb_printf("Could not allocate new kdb_defcmd table for %s\n", 651 kdb_printf("Could not allocate new kdb_defcmd table for %s\n",
652 cmdstr); 652 cmdstr);
@@ -2740,13 +2740,13 @@ int kdb_register_repeat(char *cmd,
2740 } 2740 }
2741 if (kdb_commands) { 2741 if (kdb_commands) {
2742 memcpy(new, kdb_commands, 2742 memcpy(new, kdb_commands,
2743 kdb_max_commands * sizeof(*new)); 2743 (kdb_max_commands - KDB_BASE_CMD_MAX) * sizeof(*new));
2744 kfree(kdb_commands); 2744 kfree(kdb_commands);
2745 } 2745 }
2746 memset(new + kdb_max_commands, 0, 2746 memset(new + kdb_max_commands, 0,
2747 kdb_command_extend * sizeof(*new)); 2747 kdb_command_extend * sizeof(*new));
2748 kdb_commands = new; 2748 kdb_commands = new;
2749 kp = kdb_commands + kdb_max_commands; 2749 kp = kdb_commands + kdb_max_commands - KDB_BASE_CMD_MAX;
2750 kdb_max_commands += kdb_command_extend; 2750 kdb_max_commands += kdb_command_extend;
2751 } 2751 }
2752 2752