From: Jinjie Ruan Date: Mon, 29 Jul 2024 11:52:52 +0000 (+0800) Subject: crash: fix crash memory reserve exceed system memory bug X-Git-Tag: v6.12-rc1~114^2~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=59d58189f3d96eeb31b0b4a8a8aab2cd6a6afb82;p=thirdparty%2Fkernel%2Flinux.git crash: fix crash memory reserve exceed system memory bug 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/20240729115252.1659112-1-ruanjinjie@huawei.com Signed-off-by: Jinjie Ruan Suggested-by: Mike Rapoport Acked-by: Baoquan He Cc: Albert Ou Cc: Dave Young Cc: Palmer Dabbelt Cc: Paul Walmsley Cc: Vivek Goyal Signed-off-by: Andrew Morton --- diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c index 64d44a52c0114..a620fb4b21163 100644 --- a/kernel/crash_reserve.c +++ b/kernel/crash_reserve.c @@ -335,6 +335,9 @@ int __init parse_crashkernel(char *cmdline, if (!*crash_size) ret = -EINVAL; + if (*crash_size >= system_ram) + ret = -EINVAL; + return ret; }