Commit 5450d904054b4ed582793ad6ecb5469f03cc4c46
Committed by
Jason Wessel
1 parent
85e76ab50a
Exists in
master
and in
4 other branches
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>
Showing 1 changed file with 4 additions and 4 deletions Side-by-side Diff
kernel/debug/kdb/kdb_main.c
... | ... | @@ -82,7 +82,7 @@ |
82 | 82 | #define for_each_kdbcmd(cmd, num) \ |
83 | 83 | for ((cmd) = kdb_base_commands, (num) = 0; \ |
84 | 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 | |
87 | 87 | typedef struct _kdbmsg { |
88 | 88 | int km_diag; /* kdb diagnostic */ |
... | ... | @@ -646,7 +646,7 @@ |
646 | 646 | } |
647 | 647 | if (!s->usable) |
648 | 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 | 650 | if (!s->command) { |
651 | 651 | kdb_printf("Could not allocate new kdb_defcmd table for %s\n", |
652 | 652 | cmdstr); |
653 | 653 | |
... | ... | @@ -2740,13 +2740,13 @@ |
2740 | 2740 | } |
2741 | 2741 | if (kdb_commands) { |
2742 | 2742 | memcpy(new, kdb_commands, |
2743 | - kdb_max_commands * sizeof(*new)); | |
2743 | + (kdb_max_commands - KDB_BASE_CMD_MAX) * sizeof(*new)); | |
2744 | 2744 | kfree(kdb_commands); |
2745 | 2745 | } |
2746 | 2746 | memset(new + kdb_max_commands, 0, |
2747 | 2747 | kdb_command_extend * sizeof(*new)); |
2748 | 2748 | kdb_commands = new; |
2749 | - kp = kdb_commands + kdb_max_commands; | |
2749 | + kp = kdb_commands + kdb_max_commands - KDB_BASE_CMD_MAX; | |
2750 | 2750 | kdb_max_commands += kdb_command_extend; |
2751 | 2751 | } |
2752 | 2752 |