Skip to content

Commit 75579c2

Browse files
author
Baoquan He
committed
ima: make the kexec extra memory configurable
JIRA: https://issues.redhat.com/browse/RHEL-114162 Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit 0ad9398 Author: Steven Chen <chenste@linux.microsoft.com> Date: Mon Apr 21 15:25:14 2025 -0700 ima: make the kexec extra memory configurable The extra memory allocated for carrying the IMA measurement list across kexec is hard-coded as half a PAGE. Make it configurable. Define a Kconfig option, IMA_KEXEC_EXTRA_MEMORY_KB, to configure the extra memory (in kb) to be allocated for IMA measurements added during kexec soft reboot. Ensure the default value of the option is set such that extra half a page of memory for additional measurements is allocated for the additional measurements. Update ima_add_kexec_buffer() function to allocate memory based on the Kconfig option value, rather than the currently hard-coded one. Suggested-by: Stefan Berger <stefanb@linux.ibm.com> Co-developed-by: Tushar Sugandhi <tusharsu@linux.microsoft.com> Signed-off-by: Tushar Sugandhi <tusharsu@linux.microsoft.com> 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 3abfcdf commit 75579c2

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

security/integrity/ima/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,15 @@ config IMA_DISABLE_HTABLE
321321
help
322322
This option disables htable to allow measurement of duplicate records.
323323

324+
config IMA_KEXEC_EXTRA_MEMORY_KB
325+
int "Extra memory for IMA measurements added during kexec soft reboot"
326+
range 0 40
327+
depends on IMA_KEXEC
328+
default 0
329+
help
330+
IMA_KEXEC_EXTRA_MEMORY_KB determines the extra memory to be
331+
allocated (in kb) for IMA measurements added during kexec soft reboot.
332+
If set to the default value of 0, an extra half page of memory for those
333+
additional measurements will be allocated.
334+
324335
endif

security/integrity/ima/ima_kexec.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,28 @@ void ima_add_kexec_buffer(struct kimage *image)
118118
.buf_min = 0, .buf_max = ULONG_MAX,
119119
.top_down = true };
120120
unsigned long binary_runtime_size;
121+
unsigned long extra_memory;
121122

122123
/* use more understandable variable names than defined in kbuf */
123124
size_t kexec_buffer_size = 0;
124125
void *kexec_buffer = NULL;
125126
int ret;
126127

127128
/*
128-
* Reserve an extra half page of memory for additional measurements
129-
* added during the kexec load.
129+
* Reserve extra memory for measurements added during kexec.
130130
*/
131-
binary_runtime_size = ima_get_binary_runtime_size();
131+
if (CONFIG_IMA_KEXEC_EXTRA_MEMORY_KB <= 0)
132+
extra_memory = PAGE_SIZE / 2;
133+
else
134+
extra_memory = CONFIG_IMA_KEXEC_EXTRA_MEMORY_KB * 1024;
135+
136+
binary_runtime_size = ima_get_binary_runtime_size() + extra_memory;
137+
132138
if (binary_runtime_size >= ULONG_MAX - PAGE_SIZE)
133139
kexec_segment_size = ULONG_MAX;
134140
else
135-
kexec_segment_size = ALIGN(ima_get_binary_runtime_size() +
136-
PAGE_SIZE / 2, PAGE_SIZE);
141+
kexec_segment_size = ALIGN(binary_runtime_size, PAGE_SIZE);
142+
137143
if ((kexec_segment_size == ULONG_MAX) ||
138144
((kexec_segment_size >> PAGE_SHIFT) > totalram_pages() / 2)) {
139145
pr_err("Binary measurement list too large.\n");

0 commit comments

Comments
 (0)