Skip to content

Commit 3abfcdf

Browse files
author
Baoquan He
committed
ima: verify if the segment size has changed
JIRA: https://issues.redhat.com/browse/RHEL-114162 Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit d0a00ce Author: Steven Chen <chenste@linux.microsoft.com> Date: Mon Apr 21 15:25:13 2025 -0700 ima: verify if the segment size has changed 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. Signed-off-by: Steven Chen <chenste@linux.microsoft.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Acked-by: Baoquan He <bhe@redhat.com> Tested-by: Stefan Berger <stefanb@linux.ibm.com> # ppc64/kvm Signed-off-by: Mimi Zohar <zohar@linux.ibm.com> Signed-off-by: Baoquan He <bhe@redhat.com>
1 parent 9ecd08c commit 3abfcdf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

security/integrity/ima/ima_kexec.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ static void ima_free_kexec_file_buf(struct seq_file *sf)
3333

3434
static int ima_alloc_kexec_file_buf(size_t segment_size)
3535
{
36+
/*
37+
* kexec 'load' may be called multiple times.
38+
* Free and realloc the buffer only if the segment_size is
39+
* changed from the previous kexec 'load' call.
40+
*/
41+
if (ima_kexec_file.buf && ima_kexec_file.size == segment_size)
42+
goto out;
43+
3644
ima_free_kexec_file_buf(&ima_kexec_file);
3745

3846
/* segment size can't change between kexec load and execute */
@@ -41,6 +49,8 @@ static int ima_alloc_kexec_file_buf(size_t segment_size)
4149
return -ENOMEM;
4250

4351
ima_kexec_file.size = segment_size;
52+
53+
out:
4454
ima_kexec_file.read_pos = 0;
4555
ima_kexec_file.count = sizeof(struct ima_kexec_hdr); /* reserved space */
4656

0 commit comments

Comments
 (0)