* [PATCH] Before adding to usablemem_rgns, check if the memory range is already included.
@ 2024-10-17 12:38 Chen Haixiang
2024-10-21 10:25 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Chen Haixiang @ 2024-10-17 12:38 UTC (permalink / raw)
To: kexec; +Cc: louhongxiang, wangbin224, yangyanchao6, chenhaixiang3
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(-)
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.41.0
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Before adding to usablemem_rgns, check if the memory range is already included.
2024-10-17 12:38 [PATCH] Before adding to usablemem_rgns, check if the memory range is already included Chen Haixiang
@ 2024-10-21 10:25 ` Simon Horman
0 siblings, 0 replies; 3+ messages in thread
From: Simon Horman @ 2024-10-21 10:25 UTC (permalink / raw)
To: Chen Haixiang; +Cc: kexec, louhongxiang, wangbin224, yangyanchao6
On Thu, Oct 17, 2024 at 08:38:59PM +0800, Chen Haixiang wrote:
> 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.
Thanks Chen Haixiang,
This looks reasonable to me, but, as per Kernel submissions,
I will need an Signed-off-by line [1] in order to apply this patch.
[1] https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Before adding to usablemem_rgns, check if the memory range is already included.
@ 2024-10-21 11:57 chenhaixiang (A)
0 siblings, 0 replies; 3+ messages in thread
From: chenhaixiang (A) @ 2024-10-21 11:57 UTC (permalink / raw)
To: Simon Horman
Cc: kexec@lists.infradead.org, Louhongxiang, wangbin (A),
yangyanchao (C)
> > 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.
>
> Thanks Chen Haixiang,
>
> This looks reasonable to me, but, as per Kernel submissions, I will need an
> Signed-off-by line [1] in order to apply this patch.
>
> [1]
> https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign
> -your-work-the-developer-s-certificate-of-origin
Thank you for your feedback, and I apologize for missing the Signed-off-by line. I'll resend the patch v2 with the required Signed-off-by line shortly.
Best regards,
Chen Haixiang
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-21 11:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17 12:38 [PATCH] Before adding to usablemem_rgns, check if the memory range is already included Chen Haixiang
2024-10-21 10:25 ` Simon Horman
-- strict thread matches above, loose matches on Subject: below --
2024-10-21 11:57 chenhaixiang (A)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox