[PATCH 4/5] kexec_core: Clear the unused part of CMA segments

From: Han Gao via B4 Relay

Date: Fri Oct 23 2026 - 03:38:11 EST


From: Han Gao <gaohan@xxxxxxxxxxx>

kimage_load_cma_segment() copies the source data into pages that are not
cleared, but zeroes nothing after it: the final memset() runs once the
loop has consumed all of memsz. The tail of the last source page and
every page beyond bufsz keep stale data, while the purgatory digest
covers them as zeroes.

A kexec_file reboot then stops in purgatory on a digest mismatch, for
instance when the DTB lands in a reused CMA page.

Zero the remainder of each page instead.

Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation")
Signed-off-by: Han Gao <gaohan@xxxxxxxxxxx>
---
kernel/kexec_core.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index dc770b9a6d05..0d6e10bea4e4 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -780,15 +780,15 @@ static int kimage_load_cma_segment(struct kimage *image, int idx)
goto out;
}

+ /* CMA pages are not cleared: zero the part without source data */
+ memset(ptr + uchunk, 0, mchunk - uchunk);
+
ptr += mchunk;
mbytes -= mchunk;

cond_resched();
}

- /* Clear any remainder */
- memset(ptr, 0, mbytes);
-
out:
return result;
}

--
2.55.0