diff mbox series

[v5] crash: Fix crash memory reserve exceed system memory bug

Message ID 20240723020746.3945016-1-ruanjinjie@huawei.com (mailing list archive)
State Superseded
Headers show
Series [v5] crash: Fix crash memory reserve exceed system memory bug | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR success PR summary
conchuod/patch-1-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh
conchuod/patch-1-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh
conchuod/patch-1-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh
conchuod/patch-1-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh
conchuod/patch-1-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh
conchuod/patch-1-test-6 success .github/scripts/patches/tests/checkpatch.sh
conchuod/patch-1-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh
conchuod/patch-1-test-8 success .github/scripts/patches/tests/header_inline.sh
conchuod/patch-1-test-9 success .github/scripts/patches/tests/kdoc.sh
conchuod/patch-1-test-10 success .github/scripts/patches/tests/module_param.sh
conchuod/patch-1-test-11 success .github/scripts/patches/tests/verify_fixes.sh
conchuod/patch-1-test-12 success .github/scripts/patches/tests/verify_signedoff.sh

Commit Message

Jinjie Ruan July 23, 2024, 2:07 a.m. UTC
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.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Suggested-by: Baoquan He <bhe@redhat.com>
Suggested-by: Mike Rapoport <rppt@kernel.org>
---
v5:
- Fix it in common parse_crashkernel() instead of per-arch.
- Add suggested-by.

v4:
- Update the warn info to align with parse_crashkernel_mem().
- Rebased on the "ARM: Use generic interface to simplify crashkernel
  reservation" patch.
- Also fix for riscv32.
- Update the commit message.

v3:
- Handle the check in reserve_crashkernel() Baoquan suggested.
- Split x86_32 and arm32.
- Add Suggested-by.
- Drop the wrong fix tag.

v2:
- Also fix for x86_32.
- Update the fix method.
- Peel off the other two patches.
- Update the commit message.
---
 kernel/crash_reserve.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Baoquan He July 23, 2024, 5:17 a.m. UTC | #1
On 07/23/24 at 10:07am, Jinjie Ruan wrote:
> 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.
> 
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> Suggested-by: Baoquan He <bhe@redhat.com>
> Suggested-by: Mike Rapoport <rppt@kernel.org>


My Suggested-by can be taken off because I suggested to check the parsed
value after parse_crashkernel(), Mike's suggestion is better.

For this version,

Acked-by: Baoquan He <bhe@redhat.com>

> ---
> v5:
> - Fix it in common parse_crashkernel() instead of per-arch.
> - Add suggested-by.
> 
> v4:
> - Update the warn info to align with parse_crashkernel_mem().
> - Rebased on the "ARM: Use generic interface to simplify crashkernel
>   reservation" patch.
> - Also fix for riscv32.
> - Update the commit message.
> 
> v3:
> - Handle the check in reserve_crashkernel() Baoquan suggested.
> - Split x86_32 and arm32.
> - Add Suggested-by.
> - Drop the wrong fix tag.
> 
> v2:
> - Also fix for x86_32.
> - Update the fix method.
> - Peel off the other two patches.
> - Update the commit message.
> ---
>  kernel/crash_reserve.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c
> index ad5b3f2c5487..5387269114f6 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;
>  }
>  
> -- 
> 2.34.1
>
Jinjie Ruan July 29, 2024, 3:24 a.m. UTC | #2
On 2024/7/23 13:17, Baoquan He wrote:
> On 07/23/24 at 10:07am, Jinjie Ruan wrote:
>> 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.
>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> Suggested-by: Baoquan He <bhe@redhat.com>
>> Suggested-by: Mike Rapoport <rppt@kernel.org>
> 
> 
> My Suggested-by can be taken off because I suggested to check the parsed
> value after parse_crashkernel(), Mike's suggestion is better.

Hi, Can the suggested-by be removed when this version is merged, or a
new version needs to be sent?

> 
> For this version,
> 
> Acked-by: Baoquan He <bhe@redhat.com>
> 
>> ---
>> v5:
>> - Fix it in common parse_crashkernel() instead of per-arch.
>> - Add suggested-by.
>>
>> v4:
>> - Update the warn info to align with parse_crashkernel_mem().
>> - Rebased on the "ARM: Use generic interface to simplify crashkernel
>>   reservation" patch.
>> - Also fix for riscv32.
>> - Update the commit message.
>>
>> v3:
>> - Handle the check in reserve_crashkernel() Baoquan suggested.
>> - Split x86_32 and arm32.
>> - Add Suggested-by.
>> - Drop the wrong fix tag.
>>
>> v2:
>> - Also fix for x86_32.
>> - Update the fix method.
>> - Peel off the other two patches.
>> - Update the commit message.
>> ---
>>  kernel/crash_reserve.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c
>> index ad5b3f2c5487..5387269114f6 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;
>>  }
>>  
>> -- 
>> 2.34.1
>>
> 
>
Baoquan He July 29, 2024, 3:29 a.m. UTC | #3
On 07/29/24 at 11:24am, Jinjie Ruan wrote:
> 
> 
> On 2024/7/23 13:17, Baoquan He wrote:
> > On 07/23/24 at 10:07am, Jinjie Ruan wrote:
> >> 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.
> >>
> >> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> >> Suggested-by: Baoquan He <bhe@redhat.com>
> >> Suggested-by: Mike Rapoport <rppt@kernel.org>
> > 
> > 
> > My Suggested-by can be taken off because I suggested to check the parsed
> > value after parse_crashkernel(), Mike's suggestion is better.
> 
> Hi, Can the suggested-by be removed when this version is merged, or a
> new version needs to be sent?

You can send a new one and CC Andrew.
Jinjie Ruan July 29, 2024, 11:28 a.m. UTC | #4
On 2024/7/29 11:29, Baoquan He wrote:
> On 07/29/24 at 11:24am, Jinjie Ruan wrote:
>>
>>
>> On 2024/7/23 13:17, Baoquan He wrote:
>>> On 07/23/24 at 10:07am, Jinjie Ruan wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>>>> Suggested-by: Baoquan He <bhe@redhat.com>
>>>> Suggested-by: Mike Rapoport <rppt@kernel.org>
>>>
>>>
>>> My Suggested-by can be taken off because I suggested to check the parsed
>>> value after parse_crashkernel(), Mike's suggestion is better.
>>
>> Hi, Can the suggested-by be removed when this version is merged, or a
>> new version needs to be sent?
> 
> You can send a new one and CC Andrew.

Thank you!

> 
>
diff mbox series

Patch

diff --git a/kernel/crash_reserve.c b/kernel/crash_reserve.c
index ad5b3f2c5487..5387269114f6 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;
 }