Re: [PATCH v2 3/3] ima: clear kexec state when replacing file image

From: Mimi Zohar

Date: Mon Nov 16 2026 - 12:32:07 EST


On Thu, 2026-11-12 at 12:52 +0000, Jérémy Jean wrote:
> ima_kexec_buffer remains mapped to the IMA segment of the installed
> kexec_file_load image. KEXEC_FILE_UNLOAD and a successful normal
> kexec_load can replace and free that image without clearing the mapping.
> Executing a later kexec_load image can then write the measurement list
> into the freed pages. The new image has an IMA segment size of zero, but
> size does not establish ownership of the mapping.
>
> Record the image whose segment is mapped and verify it before the
> execute-time update. Clear the mapping and scratch state under kexec_lock
> when a normal image is removed without another file image taking its
> place.
>
> Fixes: 9f0ec4b16f2b ("ima: kexec: move IMA log copy from kexec load to execute")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jérémy Jean <Jeremy.Jean@xxxxxxxxxxxxxxxxx>
> ---
> include/linux/ima.h | 1 +
> kernel/kexec.c | 11 +++++++++++
> kernel/kexec_file.c | 7 ++++++-
> security/integrity/ima/ima_kexec.c | 24 ++++++++++++++++++++++++
> 4 files changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/ima.h b/include/linux/ima.h
> index 8e08baf16c2f..d61b7b7756b7 100644
> --- a/include/linux/ima.h
> +++ b/include/linux/ima.h
> @@ -34,6 +34,7 @@ static inline void ima_appraise_parse_cmdline(void) {}
> #ifdef CONFIG_IMA_KEXEC
> extern void ima_add_kexec_buffer(struct kimage *image);
> extern void ima_kexec_post_load(struct kimage *image);
> +void ima_kexec_cleanup(void);
> #else
> static inline void ima_kexec_post_load(struct kimage *image) {}
> #endif

Could ima_kexec_cleanup() get a stub, next to the ima_add_kexec_buffer() stub in
the !CONFIG_IMA_KEXEC block at the bottom of ima.h? That would also cover
CONFIG_IMA=n, and the callers in kexec.c and kexec_file.c wouldn't need the
#ifdefs.

thanks,

Mimi