On Thu, 2025-03-20 at 09:51 +0800, Baoquan He wrote: > > > > diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c > > > > index 8567619889d1..45170e283272 100644 > > > > --- a/security/integrity/ima/ima_kexec.c > > > > +++ b/security/integrity/ima/ima_kexec.c > > > > @@ -15,6 +15,48 @@ > > > > #include "ima.h" > > > > > > > > #ifdef CONFIG_IMA_KEXEC > > > > +static struct seq_file ima_kexec_file; > > > > + > > > > +static void ima_reset_kexec_file(struct seq_file *sf) > > > > +{ > > > > + sf->buf = NULL; > > > > + sf->size = 0; > > > > + sf->read_pos = 0; > > > > + sf->count = 0; > > > > +} > > > > + > > > > +static void ima_free_kexec_file_buf(struct seq_file *sf) > > > > +{ > > > > + vfree(sf->buf); > > > > + ima_reset_kexec_file(sf); > > > > +} > > > > + > > > > +static int ima_alloc_kexec_file_buf(size_t segment_size) > > > > +{ > > > > + /* > > > > + * kexec 'load' may be called multiple times. > > > > + * Free and realloc the buffer only if the segment_size is > > > > + * changed from the previous kexec 'load' call. > > > > + */ > > > > + if (ima_kexec_file.buf && ima_kexec_file.size == segment_size) > > > > + goto out; > > > > The call to ima_reset_kexec_file() in ima_add_kexec_buffer() resets > > ima_kexec_file.buf() hiding the fact that the above test always fails and falls > > through. As a result, 'buf' is always being re-allocated. Hi Steven, [Reiterating the comment in the "ima: kexec: move IMA log copy from kexec load to execute" thread, here, for completeness.] Instead of adding and then removing the ima_reset_kexec_file() call from ima_add_kexec_buffer(), defer adding the segment size test to when it is actually possible for the segment size to change. Please make the segment size test as a separate patch. ima_reset_kexec_file() will then only be called by ima_free_kexec_file_buf(). Inline the ima_reset_kexec_file() code in ima_free_kexec_file_buf(). thanks, Mimi