[PATCH] Carry forward IMA measurement log on kexec on x86_64

Jonathan McDowell noodles at fb.com
Tue Apr 26 12:08:48 UTC 2022


On Mon, Apr 25, 2022 at 12:29:17PM -0400, Mimi Zohar wrote:
> Hi Jonathan,
> 
> On Fri, 2022-04-22 at 13:50 +0000, Jonathan McDowell wrote:
> > On kexec file load Integrity Measurement Architecture (IMA) subsystem
> > may verify the IMA signature of the kernel and initramfs, and measure
> > it. The command line parameters passed to the kernel in the kexec call
> > may also be measured by IMA. A remote attestation service can verify
> > a TPM quote based on the TPM event log, the IMA measurement list, and
> > the TPM PCR data. This can be achieved only if the IMA measurement log
> > is carried over from the current kernel to the next kernel across
> > the kexec call.
> > 
> > powerpc and ARM64 both achieve this using device tree with a
> > "linux,ima-kexec-buffer" node. x86 platforms generally don't make use of
> > device tree, so the IMA infrastructure is extended to allow non device
> > tree platforms to provide a log buffer. x86 then passes the IMA buffer
> > to the new kernel via the setup_data mechanism.
> > 
> > Signed-off-by: Jonathan McDowell <noodles at fb.com>
> 
> FYI, after applying, building, and booting a kernel with this patch,
> "kexec -s -l /boot/vmlinuz-5.18.0-rc4+ --reuse-cmdline --
> initrd=/boot/initramfs-5.18.0-rc4+.img" properly loads the kernel, but
> "kexec -s -e" fails to reboot, at least on a test laptop even with only
> the "boot_aggregate" measurement record.
> 
> Without enabling CONFIG_IMA_KEXEC, kexec boots properly.

Thanks for giving it a try. At a guess your laptop is booting with
EFI, whereas for my testing I was using qemu with legacy BIOS. I've
managed to reproduce the issue with qemu+OVMF and isolated the mistake
in the setup data calculation I made when EFI is involved. If you have
time can you try with the below on top of the original patch?

diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 07625da33075..cdc73e081585 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -277,7 +277,9 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,
 #ifdef CONFIG_IMA_KEXEC
 	/* Setup IMA log buffer state */
 	setup_ima_state(image, params, params_load_addr,
-			efi_setup_data_offset + ALIGN(efi_map_sz, 16) + sizeof(struct setup_data));
+			efi_setup_data_offset +
+			sizeof(struct setup_data) +
+			sizeof(struct efi_setup_data));
 #endif
 
 	/* Setup EDD info */



More information about the Linux-security-module-archive mailing list