Skip to content

Commit 5450d90

Browse files
Jovi Zhangjwessel
authored andcommitted
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>
1 parent 85e76ab commit 5450d90

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

kernel/debug/kdb/kdb_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static kdbtab_t kdb_base_commands[50];
8282
#define for_each_kdbcmd(cmd, num) \
8383
for ((cmd) = kdb_base_commands, (num) = 0; \
8484
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++)
8686

8787
typedef struct _kdbmsg {
8888
int km_diag; /* kdb diagnostic */
@@ -646,7 +646,7 @@ static int kdb_defcmd2(const char *cmdstr, const char *argv0)
646646
}
647647
if (!s->usable)
648648
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);
650650
if (!s->command) {
651651
kdb_printf("Could not allocate new kdb_defcmd table for %s\n",
652652
cmdstr);
@@ -2740,13 +2740,13 @@ int kdb_register_repeat(char *cmd,
27402740
}
27412741
if (kdb_commands) {
27422742
memcpy(new, kdb_commands,
2743-
kdb_max_commands * sizeof(*new));
2743+
(kdb_max_commands - KDB_BASE_CMD_MAX) * sizeof(*new));
27442744
kfree(kdb_commands);
27452745
}
27462746
memset(new + kdb_max_commands, 0,
27472747
kdb_command_extend * sizeof(*new));
27482748
kdb_commands = new;
2749-
kp = kdb_commands + kdb_max_commands;
2749+
kp = kdb_commands + kdb_max_commands - KDB_BASE_CMD_MAX;
27502750
kdb_max_commands += kdb_command_extend;
27512751
}
27522752

0 commit comments

Comments
 (0)