Skip to content

Commit

Permalink
crash: fix crash memory reserve exceed system memory bug
Browse files Browse the repository at this point in the history
On x86_32 Qemu machine with 1GB memory, the cmdline "crashkernel=4G" is ok
as below:
	crashkernel reserved: 0x0000000020000000 - 0x0000000120000000 (4096 MB)

It's similar on other architectures, such as ARM32 and RISCV32.

The cause is that the crash_size is parsed and printed with "unsigned long
long" data type which is 8 bytes but allocated used with "phys_addr_t"
which is 4 bytes in memblock_phys_alloc_range().

Fix it by checking if crash_size is greater than system RAM size and
return error if so.

After this patch, there is no above confusing reserve success info.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Jinjie Ruan <[email protected]>
Suggested-by: Mike Rapoport <[email protected]>
Acked-by: Baoquan He <[email protected]>
Cc: Albert Ou <[email protected]>
Cc: Dave Young <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
Cc: Paul Walmsley <[email protected]>
Cc: Vivek Goyal <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Jinjie Ruan authored and akpm00 committed Sep 2, 2024
1 parent 00bd8ec commit 59d5818
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kernel/crash_reserve.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ int __init parse_crashkernel(char *cmdline,
if (!*crash_size)
ret = -EINVAL;

if (*crash_size >= system_ram)
ret = -EINVAL;

return ret;
}

Expand Down

0 comments on commit 59d5818

Please sign in to comment.