Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Steven Chen and committed by
Mimi Zohar
f18e502d 9ee8888a

+50
+3
include/linux/ima.h
··· 32 32 33 33 #ifdef CONFIG_IMA_KEXEC 34 34 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) {} 35 38 #endif 36 39 37 40 #else
+47
security/integrity/ima/ima_kexec.c
··· 12 12 #include <linux/kexec.h> 13 13 #include <linux/of.h> 14 14 #include <linux/ima.h> 15 + #include <linux/reboot.h> 16 + #include <asm/page.h> 15 17 #include "ima.h" 16 18 17 19 #ifdef CONFIG_IMA_KEXEC 20 + static bool ima_kexec_update_registered; 18 21 static struct seq_file ima_kexec_file; 22 + static void *ima_kexec_buffer; 19 23 20 24 static void ima_free_kexec_file_buf(struct seq_file *sf) 21 25 { ··· 166 162 kexec_dprintk("kexec measurement buffer for the loaded kernel at 0x%lx.\n", 167 163 kbuf.mem); 168 164 } 165 + 166 + /* 167 + * Called during kexec execute so that IMA can update the measurement list. 168 + */ 169 + static int ima_update_kexec_buffer(struct notifier_block *self, 170 + unsigned long action, void *data) 171 + { 172 + return NOTIFY_OK; 173 + } 174 + 175 + static struct notifier_block update_buffer_nb = { 176 + .notifier_call = ima_update_kexec_buffer, 177 + .priority = INT_MIN 178 + }; 179 + 180 + /* 181 + * Create a mapping for the source pages that contain the IMA buffer 182 + * so we can update it later. 183 + */ 184 + void ima_kexec_post_load(struct kimage *image) 185 + { 186 + if (ima_kexec_buffer) { 187 + kimage_unmap_segment(ima_kexec_buffer); 188 + ima_kexec_buffer = NULL; 189 + } 190 + 191 + if (!image->ima_buffer_addr) 192 + return; 193 + 194 + ima_kexec_buffer = kimage_map_segment(image, 195 + image->ima_buffer_addr, 196 + image->ima_buffer_size); 197 + if (!ima_kexec_buffer) { 198 + pr_err("Could not map measurements buffer.\n"); 199 + return; 200 + } 201 + 202 + if (!ima_kexec_update_registered) { 203 + register_reboot_notifier(&update_buffer_nb); 204 + ima_kexec_update_registered = true; 205 + } 206 + } 207 + 169 208 #endif /* IMA_KEXEC */ 170 209 171 210 /*