Add support for arm64 to carry ima measurement log in kexec_file_load
Subsystems (6)
v3 cover Add support for arm64 to carry ima measurement log in kexec_file_load
Add support to carry ima measurement log
to the next kexec'ed session triggered via kexec_file_load.
- Top of Linux 5.3-rc6
Currently during kexec the kernel file signatures are/can be validated prior to actual load, the information(PE/ima signature) is not carried to the next session. This lead to loss of information.
Carrying forward the ima measurement log to the next kexec'ed session allows a verifying party to get the entire runtime event log since the last full reboot, since that is when PCRs were last reset.
Tested for arm64 qemu and real hardware.
I have not been unable to test the patch for powerpc 64bit. Any testing is greatly appretiated.
TODO: Add support for 32 bit in the of_ima.c
v3:
- Fix build breaks due to bad config.
v2:
- move common code to drivers/of/of_ima.c.
- point arm64 to use of_ima implementation.
- point powerpc to use of_ima implementation
v1:
- add new fdt porperties to mark start and end for ima measurement log.
- use fdt_* functions to add/remove fdt properties and memory allocations.
- remove additional check for endian-ness as they are checked in fdt_* functions.
v0:
- Add support to carry ima measurement log in arm64,
uses same code as powerpc.
Prakhar Srivastava (2):
Add support for arm64 to carry ima measurement log in kexec_file_load update powerpc implementation to call into of_ima*
arch/arm64/Kconfig | 7 + arch/arm64/include/asm/ima.h | 24 +++ arch/arm64/include/asm/kexec.h | 5 + arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/ima_kexec.c | 78 ++++++++++ arch/arm64/kernel/machine_kexec_file.c | 6 + arch/powerpc/Kconfig | 6 + arch/powerpc/include/asm/ima.h | 6 - arch/powerpc/kernel/Makefile | 8 +- arch/powerpc/kernel/ima_kexec.c | 170 ++------------------- drivers/of/Kconfig | 6 + drivers/of/Makefile | 1 + drivers/of/of_ima.c | 204 +++++++++++++++++++++++++ include/linux/of.h | 31 ++++ 14 files changed, 386 insertions(+), 169 deletions(-) create mode 100644 arch/arm64/include/asm/ima.h create mode 100644 arch/arm64/kernel/ima_kexec.c create mode 100644 drivers/of/of_ima.c
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 1/2 Add support for arm64 to carry ima measurement log in kexec_file_load
During kexec_file_load, carrying forward the ima measurement log allows a verifying party to get the entire runtime event log since the last full reboot since that is when PCRs were last reset.
--- arch/arm64/Kconfig | 7 + arch/arm64/include/asm/ima.h | 24 +++ arch/arm64/include/asm/kexec.h | 5 + arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/ima_kexec.c | 78 ++++++++++ arch/arm64/kernel/machine_kexec_file.c | 6 + arch/powerpc/Kconfig | 6 + drivers/of/Kconfig | 6 + drivers/of/Makefile | 1 + drivers/of/of_ima.c | 204 +++++++++++++++++++++++++ include/linux/of.h | 31 ++++ 11 files changed, 370 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/ima.h create mode 100644 arch/arm64/kernel/ima_kexec.c create mode 100644 drivers/of/of_ima.c
arch/arm64/Kconfig +7 -0
@@ -988,6 +988,13 @@ comment "Support for PE file signature verification disabled" depends on KEXEC_VERIFY_SIG depends on !EFI || !SIGNED_PE_FILE_VERIFICATION +config HAVE_IMA_KEXEC + bool "Carry over IMA measurement log during kexec_file_load() syscall" + depends on KEXEC_FILE + help + Select this option to carry over IMA measurement log during + kexec_file_load + config CRASH_DUMP bool "Build kdump crash kernel" help
arch/arm64/include/asm/ima.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ARM64_IMA_H +#define _ASM_ARM64_IMA_H + +struct kimage ; + +int ima_get_kexec_buffer (void **addr,size_t *size); +int ima_free_kexec_buffer (void ); +void remove_ima_buffer (void *fdt,int chosen_node); + +#ifdef CONFIG_IMA_KEXEC +int arch_ima_add_kexec_buffer (struct kimage *image,unsigned long load_addr, +size_t size); + +int setup_ima_buffer (const struct kimage *image,void *fdt,int chosen_node); +#else +static inline int setup_ima_buffer (const struct kimage *image,void *fdt, +int chosen_node) +{ +remove_ima_buffer (fdt, chosen_node); +return 0 ; +} +#endif /* CONFIG_IMA_KEXEC */ +#endif /* _ASM_ARM64_IMA_H */
arch/arm64/include/asm/kexec.h +5 -0
@@ -96,6 +96,11 @@ static inline void crash_post_resume(void) {}struct kimage_arch {void *dtb;unsigned long dtb_mem; + +#ifdef CONFIG_IMA_KEXEC +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; +#endif };extern const struct kexec_file_ops kexec_image_ops;
arch/arm64/kernel/Makefile +2 -1
@@ -55,7 +55,8 @@ obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o -obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o +obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o \ + ima_kexec.o obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
arch/arm64/kernel/ima_kexec.c new file +78 -0
78 lines not on this page · raw message
arch/arm64/kernel/machine_kexec_file.c +6 -0
@@ -21,6 +21,7 @@#include <linux/types.h> #include <linux/vmalloc.h> #include <asm/byteorder.h> +#include <asm/ima.h> /* relevant device tree properties */ #define FDT_PROP_INITRD_START "linux,initrd-start"
@@ -85,6 +86,11 @@ static int setup_dtb(struct kimage *image, goto out; } +/* add ima measuremnet log buffer */ + ret =setup_ima_buffer (image, dtb, off); +if (ret <0 ) + goto out; +/* add kaslr-seed */ ret =fdt_delprop (dtb, off,FDT_PROP_KASLR_SEED );if (ret == -FDT_ERR_NOTFOUND )
arch/powerpc/Kconfig +6 -0
@@ -506,6 +506,12 @@ config KEXEC interface is strongly in flux, so no good recommendation can be made. +config HAVE_IMA_KEXEC + bool "Carry over IMA measurement log during kexec_file_load() syscall" + help + Select this option to carry over IMA measurement log during + kexec_file_load. + config KEXEC_FILE bool "kexec file based system call" select KEXEC_CORE
drivers/of/Kconfig +6 -0
@@ -103,4 +103,10 @@ config OF_OVERLAY config OF_NUMA bool +config OF_IMA + def_bool y + help + IMA related wrapper functions to add/remove ima measurement logs during + kexec_file_load call. + endif # OF
drivers/of/Makefile +1 -0
@@ -14,5 +14,6 @@ obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o obj-$(CONFIG_OF_RESOLVE) += resolver.o obj-$(CONFIG_OF_OVERLAY) += overlay.o obj-$(CONFIG_OF_NUMA) += of_numa.o +obj-$(CONFIG_OF_IMA) += of_ima.o obj-$(CONFIG_OF_UNITTEST) += unittest-data/
drivers/of/of_ima.c new file +204 -0
204 lines not on this page · raw message
include/linux/of.h +31 -0
@@ -1477,4 +1477,35 @@ static inline int of_overlay_notifier_unregister(struct notifier_block *nb)#endif +#ifdef CONFIG_OF_IMA +int of_remove_ima_buffer (void ); +int of_get_ima_buffer (void **addr,size_t *size); +void fdt_remove_ima_buffer (void *fdt,int chosen_node); +int fdt_setup_ima_buffer (const phys_addr_t ima_buffer_addr, +const size_t ima_buffer_size, +void *fdt,int chosen_node); +#else +static inline int of_remove_ima_buffer (void ) +{ +return -ENOTSUPP ; +}; + +static inline int of_get_ima_buffer (void **addr,size_t *size) +{ +return -ENOTSUPP ; +}; + +static inline void fdt_remove_ima_buffer (void *fdt,int chosen_node) +{ +return ; +}; + +static inline int fdt_setup_ima_buffer (const phys_addr_t ima_buffer_addr, +const size_t ima_buffer_size,void *fdt,int chosen_node) +{ +return -ENOTSUPP ; +}; + +#endif +#endif /* _LINUX_OF_H */
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v3 2/2 update powerpc implementation to call into of_ima*
In reply to Prakhar Srivastavaupdate powerpc ima buffer pass implementationt to call into of_ima* for a cross architecture support.
--- arch/powerpc/include/asm/ima.h | 6 -- arch/powerpc/kernel/Makefile | 8 +- arch/powerpc/kernel/ima_kexec.c | 170 +++----------------------------- 3 files changed, 16 insertions(+), 168 deletions(-)
arch/powerpc/include/asm/ima.h +0 -6
@@ -6,12 +6,7 @@ struct kimage;int ima_get_kexec_buffer (void **addr,size_t *size);int ima_free_kexec_buffer (void ); - -#ifdef CONFIG_IMA void remove_ima_buffer (void *fdt,int chosen_node); -#else -static inline void remove_ima_buffer (void *fdt,int chosen_node) {} -#endif #ifdef CONFIG_IMA_KEXEC int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr,
@@ -26,5 +21,4 @@ static inline int setup_ima_buffer(const struct kimage *image, void *fdt,return 0 ; }#endif /* CONFIG_IMA_KEXEC */ -#endif /* _ASM_POWERPC_IMA_H */
arch/powerpc/kernel/Makefile +2 -6
@@ -126,12 +126,8 @@ obj-$(CONFIG_PCI) += pci_$(BITS).o $(pci64-y) \ obj-$(CONFIG_PCI_MSI) += msi.o obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o crash.o \ machine_kexec_$(BITS).o -obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file_$(BITS).o kexec_elf_$(BITS).o -ifdef CONFIG_HAVE_IMA_KEXEC -ifdef CONFIG_IMA -obj-y += ima_kexec.o -endif -endif +obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file_$(BITS).o kexec_elf_$(BITS).o \ + ima_kexec.o obj-$(CONFIG_AUDIT) += audit.o obj64-$(CONFIG_AUDIT) += compat_audit.o
arch/powerpc/kernel/ima_kexec.c +14 -156
205 lines not on this page · raw message
Signature · 7 lines
2.17.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec