crash: fix crash memory reserve exceed system memory bug
authorJinjie Ruan <ruanjinjie@huawei.com>
Mon, 29 Jul 2024 11:52:52 +0000 (19:52 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 2 Sep 2024 03:43:30 +0000 (20:43 -0700)
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 <ruanjinjie@huawei.com>
Suggested-by: Mike Rapoport <rppt@kernel.org>
Acked-by: Baoquan He <bhe@redhat.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Dave Young <dyoung@redhat.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/crash_reserve.c

index 64d44a52c011474960833f0a864b15d58550bfe8..a620fb4b211631f25b7a3f7b285c3a049581c626 100644 (file)
@@ -335,6 +335,9 @@ int __init parse_crashkernel(char *cmdline,
        if (!*crash_size)
                ret = -EINVAL;
 
+       if (*crash_size >= system_ram)
+               ret = -EINVAL;
+
        return ret;
 }