Carry ima measurement log for arm64 via kexec_file_load
Subsystems (3)
cover Carry ima measurement log for arm64 via kexec_file_load
The patch adds support for arm64 to carry ima measurement log to the next soft boot session triggered via kexec_file_load.
- Top of Linux 5.3-rc6
Currently during kexec the kernel file signatures are validated prior to actual load, the information(PE/ima signature) is not carried to the next session.
This lead to loss of information.
This patch addresses the same by carrying forward the ima measurement log to the next kexec'ed session. This just allows a verifying party to get the entire runtime event log since the last full reboot since that is when PCRs were last reset.
The code is in most part same as powerpc, i want to get feedback as to how/correct way to refactor the code so that cross architecture partial helpers can be put in a common place.
Prakhar Srivastava (1):
Carry ima measurement log for arm64 via kexec_file_load
arch/arm64/Kconfig | 7 + arch/arm64/include/asm/ima.h | 31 ++++ arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/ima_kexec.c | 219 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 39 +++++ 6 files changed, 301 insertions(+) create mode 100644 arch/arm64/include/asm/ima.h create mode 100644 arch/arm64/kernel/ima_kexec.c
Signature · 1 line
2.17.1
RFC PATCH 1/1 Carry ima measurement log for arm64 via kexec_file_load
Carry ima measurement log for arm64 via kexec_file_load. add support to kexec_file_load to pass the ima measurement log
This patch adds entry for the ima measurement log in the dtb which is then used in the kexec'ed session to fetch the segment and then load the ima measurement log.
--- arch/arm64/Kconfig | 7 + arch/arm64/include/asm/ima.h | 31 ++++ arch/arm64/include/asm/kexec.h | 4 + arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/ima_kexec.c | 219 +++++++++++++++++++++++++ arch/arm64/kernel/machine_kexec_file.c | 39 +++++ 6 files changed, 301 insertions(+) create mode 100644 arch/arm64/include/asm/ima.h create mode 100644 arch/arm64/kernel/ima_kexec.c
arch/arm64/Kconfig +7 -0
@@ -964,6 +964,13 @@ config KEXEC_FILE for kernel and initramfs as opposed to list of segments as accepted by previous system call. +config HAVE_IMA_KEXEC + bool "enable arch specific ima buffer pass" + depends on KEXEC_FILE + help + This adds support to carry ima log to the next kernel in case + of kexec_file_load + config KEXEC_VERIFY_SIG bool "Verify kernel signature during kexec_file_load() syscall" depends on KEXEC_FILE
arch/arm64/include/asm/ima.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ARM64_IMA_H +#define _ASM_ARM64_IMA_H + +#define FDT_PROP_KEXEC_BUFFER "linux,ima-kexec-buffer" + +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, +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 +4 -0
@@ -96,6 +96,8 @@ static inline void crash_post_resume(void) {}struct kimage_arch {void *dtb;unsigned long dtb_mem; +phys_addr_t ima_buffer_addr; +size_t ima_buffer_size; };extern const struct kexec_file_ops kexec_image_ops;
@@ -107,6 +109,8 @@ extern int load_other_segments(struct kimage *image, unsigned long kernel_load_addr, unsigned long kernel_size, char *initrd, unsigned long initrd_len, char *cmdline); +extern int delete_fdt_mem_rsv (void *fdt,unsigned long start, +unsigned long size);#endif #endif /* __ASSEMBLY__ */
arch/arm64/kernel/Makefile +1 -0
@@ -63,6 +63,7 @@ obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_SSBD) += ssbd.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o +obj-$(CONFIG_HAVE_IMA_KEXEC) += ima_kexec.o obj-y += vdso/ probes/ obj-$(CONFIG_COMPAT_VDSO) += vdso32/
arch/arm64/kernel/ima_kexec.c new file +219 -0
219 lines not on this page · raw message
arch/arm64/kernel/machine_kexec_file.c +39 -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_buffer */ + ret =setup_ima_buffer (image, dtb, off); +if (ret) + goto out; +/* add kaslr-seed */ ret =fdt_delprop (dtb, off,FDT_PROP_KASLR_SEED );if (ret == -FDT_ERR_NOTFOUND )
@@ -114,6 +120,39 @@ static int setup_dtb(struct kimage *image,*/ #define DTB_EXTRA_SPACE 0x1000 + +/** +* delete_fdt_mem_rsv - delete memory reservation with given address and size +* +* Return: 0 on success, or negative errno on error. +*/ +int delete_fdt_mem_rsv (void *fdt,unsigned long start,unsigned long size) +{ +int i, ret, num_rsvs =fdt_num_mem_rsv (fdt); + +for (i =0 ; i < num_rsvs; i++) { +uint64_t rsv_start, rsv_size; + + ret =fdt_get_mem_rsv (fdt, i, &rsv_start, &rsv_size); +if (ret) { +pr_err ("Malformed device tree.\n" ); +return -EINVAL ; + } + +if (rsv_start == start && rsv_size == size) { + ret =fdt_del_mem_rsv (fdt, i); +if (ret) { +pr_err ("Error deleting device tree reservation.\n" ); +return -EINVAL ; + } + +return 0 ; + } + } + +return -ENOENT ; +} +static int create_dtb (struct kimage *image,unsigned long initrd_load_addr,unsigned long initrd_len,char *cmdline,void **dtb)
Signature · 1 line
2.17.1