Skip to content

Commit 696bd14

Browse files
author
Baoquan He
committed
ima: kexec: define functions to copy IMA log at soft boot
JIRA: https://issues.redhat.com/browse/RHEL-114162 Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit f18e502 Author: Steven Chen <chenste@linux.microsoft.com> Date: Mon Apr 21 15:25:11 2025 -0700 ima: kexec: define functions to copy IMA log at soft boot The IMA log is currently copied to the new kernel during kexec 'load' using ima_dump_measurement_list(). However, the log copied at kexec 'load' may result in loss of IMA measurements that only occurred after kexec "load'. Setup the needed infrastructure to move the IMA log copy from kexec 'load' to 'execute'. Define a new IMA hook ima_update_kexec_buffer() as a stub function. It will be used to call ima_dump_measurement_list() during kexec 'execute'. Implement ima_kexec_post_load() function to be invoked after the new Kernel image has been loaded for kexec. ima_kexec_post_load() maps the IMA buffer to a segment in the newly loaded Kernel. It also registers the reboot notifier_block to trigger ima_update_kexec_buffer() at kexec 'execute'. Set the priority of register_reboot_notifier to INT_MIN to ensure that the IMA log copy operation will happen at the end of the operation chain, so that all the IMA measurement records extended into the TPM are copied Co-developed-by: Tushar Sugandhi <tusharsu@linux.microsoft.com> Signed-off-by: Tushar Sugandhi <tusharsu@linux.microsoft.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Baoquan He <bhe@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Dave Young <dyoung@redhat.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 9d7ef88 commit 696bd14

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

include/linux/ima.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ static inline void ima_appraise_parse_cmdline(void) {}
3232

3333
#ifdef CONFIG_IMA_KEXEC
3434
extern void ima_add_kexec_buffer(struct kimage *image);
35+
extern void ima_kexec_post_load(struct kimage *image);
36+
#else
37+
static inline void ima_kexec_post_load(struct kimage *image) {}
3538
#endif
3639

3740
#else

security/integrity/ima/ima_kexec.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
#include <linux/kexec.h>
1313
#include <linux/of.h>
1414
#include <linux/ima.h>
15+
#include <linux/reboot.h>
16+
#include <asm/page.h>
1517
#include "ima.h"
1618

1719
#ifdef CONFIG_IMA_KEXEC
20+
static bool ima_kexec_update_registered;
1821
static struct seq_file ima_kexec_file;
22+
static void *ima_kexec_buffer;
1923

2024
static void ima_free_kexec_file_buf(struct seq_file *sf)
2125
{
@@ -162,6 +166,49 @@ void ima_add_kexec_buffer(struct kimage *image)
162166
kexec_dprintk("kexec measurement buffer for the loaded kernel at 0x%lx.\n",
163167
kbuf.mem);
164168
}
169+
170+
/*
171+
* Called during kexec execute so that IMA can update the measurement list.
172+
*/
173+
static int ima_update_kexec_buffer(struct notifier_block *self,
174+
unsigned long action, void *data)
175+
{
176+
return NOTIFY_OK;
177+
}
178+
179+
static struct notifier_block update_buffer_nb = {
180+
.notifier_call = ima_update_kexec_buffer,
181+
.priority = INT_MIN
182+
};
183+
184+
/*
185+
* Create a mapping for the source pages that contain the IMA buffer
186+
* so we can update it later.
187+
*/
188+
void ima_kexec_post_load(struct kimage *image)
189+
{
190+
if (ima_kexec_buffer) {
191+
kimage_unmap_segment(ima_kexec_buffer);
192+
ima_kexec_buffer = NULL;
193+
}
194+
195+
if (!image->ima_buffer_addr)
196+
return;
197+
198+
ima_kexec_buffer = kimage_map_segment(image,
199+
image->ima_buffer_addr,
200+
image->ima_buffer_size);
201+
if (!ima_kexec_buffer) {
202+
pr_err("Could not map measurements buffer.\n");
203+
return;
204+
}
205+
206+
if (!ima_kexec_update_registered) {
207+
register_reboot_notifier(&update_buffer_nb);
208+
ima_kexec_update_registered = true;
209+
}
210+
}
211+
165212
#endif /* IMA_KEXEC */
166213

167214
/*

0 commit comments

Comments
 (0)