From 0a9c3959e4ad9155a591ae3a3e501e731b28ad6e Mon Sep 17 00:00:00 2001 From: zhangjian Date: Mon, 28 Apr 2025 04:10:26 +0000 Subject: [PATCH] sync patch from SP1 Signed-off-by: zhangjian --- ...-usablemem_rgns-check-if-the-memory-.patch | 56 +++++++++++++++++++ kdump-lib.sh | 10 ++-- kdumpctl | 4 +- kexec-tools.spec | 10 +++- 4 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 Before-adding-to-usablemem_rgns-check-if-the-memory-.patch diff --git a/Before-adding-to-usablemem_rgns-check-if-the-memory-.patch b/Before-adding-to-usablemem_rgns-check-if-the-memory-.patch new file mode 100644 index 0000000..b747c0c --- /dev/null +++ b/Before-adding-to-usablemem_rgns-check-if-the-memory-.patch @@ -0,0 +1,56 @@ +From 13e0a9327a42d78b0c0d0f672e02d8013187251a Mon Sep 17 00:00:00 2001 +From: Chen Haixiang +Date: Mon, 21 Oct 2024 20:00:25 +0800 +Subject: [PATCH] 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. + +Reviewed-by: Louhongxiang +Reviewed-by: wangbin +Reviewed-by: yangyanchao +Signed-off-by: chenhaixiang +Signed-off-by: Simon Horman +--- + kexec/arch/arm64/crashdump-arm64.c | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c +index 3098315..f23b2bf 100644 +--- a/kexec/arch/arm64/crashdump-arm64.c ++++ b/kexec/arch/arm64/crashdump-arm64.c +@@ -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) { +-- +2.43.0 + diff --git a/kdump-lib.sh b/kdump-lib.sh index efc1a37..9d0779d 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -44,7 +44,7 @@ is_nfs_dump_target() return 0; fi - if is_fs_type_nfs $(get_dracut_args_fstype "$(grep "^dracut_args .*\-\-mount" /etc/kdump.conf)"); then + if is_fs_type_nfs $(get_dracut_args_fstype "$(grep "^dracut_args .*--mount" /etc/kdump.conf)"); then return 0 fi @@ -127,7 +127,7 @@ get_user_configured_dump_disk() _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw" /etc/kdump.conf 2>/dev/null |awk '{print $2}') [ -n "$_target" ] && echo $_target && return - _target=$(get_dracut_args_target "$(grep "^dracut_args .*\-\-mount" /etc/kdump.conf)") + _target=$(get_dracut_args_target "$(grep "^dracut_args .*--mount" /etc/kdump.conf)") [ -b "$_target" ] && echo $_target } @@ -448,19 +448,19 @@ is_wdt_mod_omitted() { # its correctness). is_mount_in_dracut_args() { - grep -q "^dracut_args .*\-\-mount" /etc/kdump.conf + grep -q "^dracut_args .*--mount" /etc/kdump.conf } # If $1 contains dracut_args "--mount", return get_dracut_args_fstype() { - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3 + echo $1 | grep "\--mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3 } # If $1 contains dracut_args "--mount", return get_dracut_args_target() { - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1 + echo $1 | grep "\--mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1 } check_crash_mem_reserved() diff --git a/kdumpctl b/kdumpctl index 00c0064..079c2ec 100755 --- a/kdumpctl +++ b/kdumpctl @@ -227,7 +227,7 @@ check_config() return 1 } - nr=$(grep "^dracut_args .*\-\-mount" $KDUMP_CONFIG_FILE | grep -o "\-\-mount" | wc -l) + nr=$(grep "^dracut_args .*\--mount" $KDUMP_CONFIG_FILE | grep -o "--mount" | wc -l) [ $nr -gt 1 ] && { echo "Multiple mount targets specified in one \"dracut_args\"." return 1 @@ -492,7 +492,7 @@ check_dump_fs_modified() # if --mount argument present then match old and new target, mount # point and file system. If any of them mismatches then rebuild - echo $_dracut_args | grep "\-\-mount" &> /dev/null + echo $_dracut_args | grep "--mount" &> /dev/null if [[ $? -eq 0 ]];then set -- $(echo $_dracut_args | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) _old_dev=$1 diff --git a/kexec-tools.spec b/kexec-tools.spec index aed1acc..21b4527 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,7 +4,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 8 +Release: 9 License: GPLv2 Summary: The kexec/kdump userspace component URL: https://www.kernel.org/ @@ -87,6 +87,8 @@ Patch0007: kexec-tools-fix-riscv-support.patch %ifarch loongarch64 Patch0008: Add-loongarch-iomem.h.patch %endif +Patch0009: Before-adding-to-usablemem_rgns-check-if-the-memory-.patch + %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -295,6 +297,12 @@ done %endif %changelog +* Mon Apr 28 2025 zhangjian - 2.0.26-9 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:sync SP1 patches to SP2 + * Fri Sep 20 2024 chenguokai - 2.0.26-8 - Fix multiple issues of riscv image format & initrd support -- Gitee