Before adding to usablemem_rgns, check if the memory range is already included.
Subsystems (2)
PATCH v2 1/1 Before adding to usablemem_rgns, check if the memory range is already included.
When kexec_iomem_for_each_line() reads from /proc/iomem, concurrent modifications to /proc/iomem may lead to usablemem_rgns recording duplicate Crash kernel segments. This can result in the number of retrieved Crash kernel segments exceeding CRASH_MAX_RESERVED_RANGES, triggering a realloc of the crash_reserved_mem in usablemem_rgns, which could crash the process. We should ensure that each range added to usablemem_rgns is unique to prevent these issues.
--- kexec/arch/arm64/crashdump-arm64.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
kexec/arch/arm64/crashdump-arm64.c +14 -2
@@ -63,10 +63,22 @@ static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr), char *str, unsigned long long base, unsigned long long length) { - if (strncmp(str, CRASH_KERNEL, strlen(CRASH_KERNEL)) == 0) + int i; + +if (strncmp (str,CRASH_KERNEL ,strlen (CRASH_KERNEL )) ==0 ) { +/* +* Checks whether the area exists in crash_reserved_mem. +*/ +for (i =0 ; i < usablemem_rgns.max_size; i++) { +if (usablemem_rgns.ranges[i].start == base) { +fprintf (stderr,"Warning, the range already exists in usablemem_rgns, base=%lx, length=%lx\n" , + base, length); +return 0 ; + } + }return mem_regions_alloc_and_add (&usablemem_rgns, base, length,RANGE_RAM ); - else if (strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)) == 0) + }else if (strncmp (str,SYSTEM_RAM ,strlen (SYSTEM_RAM )) ==0 )return mem_regions_alloc_and_add (&system_memory_rgns, base, length,RANGE_RAM );else if (strncmp (str,KERNEL_CODE ,strlen (KERNEL_CODE )) ==0 ) {
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Simon Horman
AppliedQuoted 9 lines · Chen Haixiang
When
kexec_iomem_for_each_line()reads from/proc/iomem, concurrent modifications to/proc/iomemmay lead tousablemem_rgnsrecording duplicate Crash kernel segments. This can result in the number of retrieved Crash kernel segments exceedingCRASH_MAX_RESERVED_RANGES, triggering a realloc of thecrash_reserved_meminusablemem_rgns, which could crash the process. We should ensure that each range added tousablemem_rgnsis unique to prevent these issues.
Quoted 4 lines
Reviewed-by Louhongxiang <[email protected]>Reviewed-by wangbin <[email protected]>Reviewed-by yangyanchao <[email protected]>Signed-off-by chenhaixiang <[email protected]>
Thanks, applied.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec