Add support to carry ima measurement log in kexec_file_load
Subsystems (6)
v2 cover Add support 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
Changelog:
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/Kconfig | 6 +- 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/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 ++++ 13 files changed, 378 insertions(+), 170 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 v2 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/Kconfig | 6 +- 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 + drivers/of/Kconfig | 6 + drivers/of/Makefile | 1 + drivers/of/of_ima.c | 204 +++++++++++++++++++++++++ include/linux/of.h | 31 ++++ 10 files changed, 362 insertions(+), 2 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
arch/Kconfig +5 -1
@@ -19,7 +19,11 @@ config KEXEC_CORE bool config HAVE_IMA_KEXEC - bool + 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 HOTPLUG_SMT bool
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 )
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 -ENOTSUPP ; +}; + +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 v2 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
Re: [PATCH v2 1/2] Add support for arm64 to carry ima measurement log in kexec_file_load
In reply to Prakhar SrivastavaQuoted 29 lines · Prakhar Srivastava
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.Signed-off-by Prakhar Srivastava <[email protected]>---
arch/Kconfig | 6 +- 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 + drivers/of/Kconfig | 6 + drivers/of/Makefile | 1 + drivers/of/of_ima.c | 204 +++++++++++++++++++++++++ include/linux/of.h | 31 ++++ 10 files changed, 362 insertions(+), 2 deletions(-)create mode 100644
arch/arm64/include/asm/ima.h
create mode 100644arch/arm64/kernel/ima_kexec.c
create mode 100644drivers/of/of_ima.carch/Kconfig +0
-0@@ -19,7 +19,11 @@ config KEXEC_CORE boolconfig
HAVE_IMA_KEXEC
arch/Kconfig config KEXEC_CORE · line 26
Quoted 6 lines
arch/Kconfig +5
-1- bool + 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.
This change looks very wrong: HAVE_* config symbols are used to indicate the availability of certain arch specific capability, rather than act as a config option. How does this work with CONFIG_IMA_KEXEC ?
Also, please, at the very least verify that basic functionality works on the architectures we have access to. Trying it on x86:
$ make allmodconfig
scripts/kconfig/conf --allmodconfig Kconfig
#
# No change to .config
#
$ make
CALL scripts/checksyscalls.sh
CALL scripts/atomic/check-atomics.sh
DESCEND objtool
CC security/integrity/ima/ima_fs.o
In file included from security/integrity/ima/ima_fs.c:26:
security/integrity/ima/ima.h:28:10: fatal error: asm/ima.h: No such file or directory
#include <asm/ima.h>
^~~~~~~~~~~
compilation terminated.
make[3]: *** [scripts/Makefile.build:266: security/integrity/ima/ima_fs.o] Error 1
make[2]: *** [scripts/Makefile.build:509: security/integrity/ima] Error 2
make[1]: *** [scripts/Makefile.build:509: security/integrity] Error 2
make: *** [Makefile:1649: security] Error 2--
Thanks,
Sasha
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v2 1/2] Add support for arm64 to carry ima measurement log in kexec_file_load
Quoted 29 lines · Sasha Levin
Quoted 28 lines · Prakhar Srivastava
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.Signed-off-by Prakhar Srivastava <[email protected]>---
arch/Kconfig | 6 +- 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 + drivers/of/Kconfig | 6 + drivers/of/Makefile | 1 + drivers/of/of_ima.c | 204 +++++++++++++++++++++++++ include/linux/of.h | 31 ++++10 files changed, 362 insertions(+), 2 deletions(-)create mode 100644
arch/arm64/include/asm/ima.h
create mode 100644arch/arm64/kernel/ima_kexec.c
create mode 100644drivers/of/of_ima.carch/Kconfig +0
-0@@ -19,7 +19,11 @@ config KEXEC_COREbool
Quoted 13 lines
Quoted 8 lines
config
HAVE_IMA_KEXEC
- bool
+ bool "Carry over IMA measurement log duringkexec_file_load()syscall"
+ depends onKEXEC_FILE
+ help
+ Select this option to carry over IMA measurement log during +kexec_file_load.This change looks very wrong: HAVE_* config symbols are used to indicate the availability of certain arch specific capability, rather than act as a config option. How does this work with
CONFIG_IMA_KEXEC?
Thanks for pointing this out. My attempt was to move this out of arch dependent config. I will fix the CONFIG.
Quoted 3 lines
Also, please, at the very least verify that basic functionality works on the architectures we have access to. Trying it on x86:
Let me fix the build issues for other archs.
I have tested these changes for arm64.
Quoted 11 lines
$ make allmodconfig scripts/kconfig/conf --allmodconfig Kconfig # # No change to .config # $ make CALL scripts/checksyscalls.sh CALL scripts/atomic/check-atomics.sh DESCEND objtool CC security/integrity/ima/ima_fs.o In file included from security/integrity/ima/ima_fs.c:26:
Quoted 12 lines
security/integrity/ima/ima.h:28:10: fatal error: asm/ima.h: No such file or directory #include <asm/ima.h> ^~~~~~~~~~~ compilation terminated. make[3]: *** [scripts/Makefile.build:266: security/integrity/ima/ima_fs.o] Error 1 make[2]: *** [scripts/Makefile.build:509: security/integrity/ima] Error 2 make[1]: *** [scripts/Makefile.build:509: security/integrity] Error 2 make: *** [Makefile:1649: security] Error 2Signature · 2 lines
Thanks, Sasha
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec