Skip to content

Commit

Permalink
x86/corruption-check: Fix panic in memory_corruption_check() when boo…
Browse files Browse the repository at this point in the history
…t option without value is provided

commit ccde460 upstream.

memory_corruption_check[{_period|_size}]()'s handlers do not check input
argument before passing it to kstrtoul() or simple_strtoull(). The argument
would be a NULL pointer if each of the kernel parameters, without its
value, is set in command line and thus cause the following panic.

PANIC: early exception 0xe3 IP 10:ffffffff73587c22 error 0 cr2 0x0
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.18-rc8+ fail0verflow#2
[    0.000000] RIP: 0010:kstrtoull+0x2/0x10
...
[    0.000000] Call Trace
[    0.000000]  ? set_corruption_check+0x21/0x49
[    0.000000]  ? do_early_param+0x4d/0x82
[    0.000000]  ? parse_args+0x212/0x330
[    0.000000]  ? rdinit_setup+0x26/0x26
[    0.000000]  ? parse_early_options+0x20/0x23
[    0.000000]  ? rdinit_setup+0x26/0x26
[    0.000000]  ? parse_early_param+0x2d/0x39
[    0.000000]  ? setup_arch+0x2f7/0xbf4
[    0.000000]  ? start_kernel+0x5e/0x4c2
[    0.000000]  ? load_ucode_bsp+0x113/0x12f
[    0.000000]  ? secondary_startup_64+0xa5/0xb0

This patch adds checks to prevent the panic.

Signed-off-by: He Zhe <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
He Zhe authored and gregkh committed Nov 13, 2018
1 parent 9f775ed commit 967afd9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions arch/x86/kernel/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ static __init int set_corruption_check(char *arg)
ssize_t ret;
unsigned long val;

if (!arg) {
pr_err("memory_corruption_check config string not provided\n");
return -EINVAL;
}

ret = kstrtoul(arg, 10, &val);
if (ret)
return ret;
Expand All @@ -45,6 +50,11 @@ static __init int set_corruption_check_period(char *arg)
ssize_t ret;
unsigned long val;

if (!arg) {
pr_err("memory_corruption_check_period config string not provided\n");
return -EINVAL;
}

ret = kstrtoul(arg, 10, &val);
if (ret)
return ret;
Expand All @@ -59,6 +69,11 @@ static __init int set_corruption_check_size(char *arg)
char *end;
unsigned size;

if (!arg) {
pr_err("memory_corruption_check_size config string not provided\n");
return -EINVAL;
}

size = memparse(arg, &end);

if (*end == '\0')
Expand Down

0 comments on commit 967afd9

Please sign in to comment.