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

Mike Rapoport rppt at kernel.org
Tue Nov 3 02:15:16 PST 2026


On Fri, Oct 23, 2026 at 03:33:17PM +0800, Han Gao via B4 Relay wrote:
> From: Han Gao <gaohan at iscas.ac.cn>
> 
> 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 at iscas.ac.cn>

Reviewed-by: Mike Rapoport (Microsoft) <rppt at kernel.org>

> ---
>  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
> 
> 

-- 
Sincerely yours,
Mike.



More information about the linux-riscv mailing list