From a98063a1a172df9304df8b35b03ca3cd0e596056 Mon Sep 17 00:00:00 2001 From: chenhaixiang Date: Mon, 10 Feb 2025 08:27:44 +0000 Subject: [PATCH] Before adding to usablemem_rgns, check if the memory range is already included. Signed-off-by: chenhaixiang --- ...-usablemem_rgns-check-if-the-memory-.patch | 56 +++++++++++++++++++ kexec-tools.spec | 6 +- 2 files changed, 61 insertions(+), 1 deletion(-) 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/kexec-tools.spec b/kexec-tools.spec index e1db2b5..81ce631 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,7 +4,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 9 +Release: 10 License: GPLv2 Summary: The kexec/kdump userspace component URL: https://www.kernel.org/ @@ -87,6 +87,7 @@ 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 +296,9 @@ done %endif %changelog +* Mon Feb 10 2025 chenhaixiang - 2.0.26-10 +- Before adding to usablemem_rgns, check if the memory range is already included. + * Fri Sep 20 2024 chenguokai - 2.0.26-9 - Fix multiple issues of riscv image format & initrd support - Rebase and test by Mingzheng Xing -- Gitee