Skip to contentSkip to conversation

Add support for using reserved memory for ima buffer pass

RFC PATCH In review Prakhar Srivastava 5 participants 13 messages May 4, 2020 – Jun 1, 2020

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover Add support for using reserved memory for ima buffer pass

IMA during kexec(kexec file load) verifies the kernel signature and measures the signature of the kernel. The signature in the logs can be used to verfiy the authenticity of the kernel. The logs don not get carried over kexec and thus remote attesation cannot verify the signature of the running kernel.

Introduce an ABI to carry forward the ima logs over kexec. Memory reserved via device tree reservation can be used to store and read via the of_* functions.

Reserved memory stores the size(sizeof(size_t)) of the buffer in the starting address, followed by the IMA log contents.

Tested on:
arm64 with Uboot

Prakhar Srivastava (2):
Add a layer of abstraction to use the memory reserved by device tree
for ima buffer pass.
Add support for ima buffer pass using reserved memory for arm64 kexec.
Update the arch sepcific code path in kexec file load to store the ima buffer in the reserved memory. The same reserved memory is read on kexec or cold boot.

 arch/arm64/Kconfig                     |   1 +
 arch/arm64/include/asm/ima.h           |  22 ++++
 arch/arm64/include/asm/kexec.h         |   5 +
 arch/arm64/kernel/Makefile             |   1 +
 arch/arm64/kernel/ima_kexec.c          |  64 ++++++++++
 arch/arm64/kernel/machine_kexec_file.c |   1 +
 arch/powerpc/include/asm/ima.h         |   3 +-
 arch/powerpc/kexec/ima.c               |  14 ++-
 drivers/of/Kconfig                     |   6 +
 drivers/of/Makefile                    |   1 +
 drivers/of/of_ima.c                    | 165 +++++++++++++++++++++++++
 include/linux/of.h                     |  34 +++++
 security/integrity/ima/ima_kexec.c     |  15 ++-
 13 files changed, 325 insertions(+), 7 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 · 1 line
2.25.1
#1 lore raw

RFC PATCH 1/2 Add a layer of abstraction to use the memory reserved by device tree for ima buffer pass.

Introduce a device tree layer for to read and store ima buffer from the reserved memory section of a device tree.

---
 drivers/of/Kconfig  |   6 ++
 drivers/of/Makefile |   1 +
 drivers/of/of_ima.c | 165 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h  |  34 +++++++++
 4 files changed, 206 insertions(+)
 create mode 100644 drivers/of/of_ima.c
drivers/of/Kconfig +6 -0
index d91618641be6..edb3c39740fb 100644
@@ -107,4 +107,10 @@ config OF_DMA_DEFAULT_COHERENT
 	# arches should select this if DMA is coherent by default for OF devices
 	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
index 663a4af0cccd..b4caf083df4e 100644
@@ -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 +165 -0

165 lines not on this page · raw message

include/linux/of.h +34 -0
index c669c0a4732f..85ce2f24024f 100644
@@ -1485,4 +1485,38 @@ static inline int of_overlay_notifier_unregister(struct notifier_block *nb)
 
 #endif
 
+#ifdef CONFIG_OF_IMA
+int of_is_ima_memory_reserved(void);
+int of_remove_ima_buffer(void);
+int of_get_ima_buffer(void **addr, size_t *size);
+size_t of_ima_get_size_allocated(void);
+int of_ima_write_buffer(void *ima_buffer,
+		size_t ima_buffer_size);
+#else
+static inline int of_is_ima_memory_reserved(void)
+{
+	return -ENOTSUPP;
+};
+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 size_t of_ima_get_size_allocated(void)
+{
+	return 0;
+};
+
+static inline int of_ima_write_buffer(void *ima_buffer,
+				      size_t ima_buffer_size)
+{
+	return -ENOTSUPP;
+};
+#endif
+
 #endif /* _LINUX_OF_H */
Signature · 1 line
2.25.1
#6 lore raw

RFC PATCH 2/2 Add support for ima buffer pass using reserved memory arm64

In reply to Prakhar Srivastava

Add support for ima buffer pass using reserved memory for
arm64 kexec. Update the arch sepcific code path in kexec file load to store the ima buffer in the reserved memory. The same reserved memory is read on kexec or cold boot.

---
 arch/arm64/Kconfig                     |  1 +
 arch/arm64/include/asm/ima.h           | 22 +++++++++
 arch/arm64/include/asm/kexec.h         |  5 ++
 arch/arm64/kernel/Makefile             |  1 +
 arch/arm64/kernel/ima_kexec.c          | 64 ++++++++++++++++++++++++++
 arch/arm64/kernel/machine_kexec_file.c |  1 +
 arch/powerpc/include/asm/ima.h         |  3 +-
 arch/powerpc/kexec/ima.c               | 14 +++++-
 security/integrity/ima/ima_kexec.c     | 15 ++++--
 9 files changed, 119 insertions(+), 7 deletions(-)
 create mode 100644 arch/arm64/include/asm/ima.h
 create mode 100644 arch/arm64/kernel/ima_kexec.c
arch/arm64/Kconfig +1 -0
index 40fb05d96c60..bc9e1a91686b 100644
@@ -1069,6 +1069,7 @@ config KEXEC
 config KEXEC_FILE
 	bool "kexec file based system call"
 	select KEXEC_CORE
+	select HAVE_IMA_KEXEC
 	help
 	  This is new version of kexec system call. This system call is
 	  file based and takes file descriptors as system call argument
arch/arm64/include/asm/ima.h new file +22 -0
new file mode 100644
index 000000000000..58033b427e59
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_ARM64_IMA_H
+#define _ASM_ARM64_IMA_H
+
+struct kimage;
+
+int is_ima_memory_reserved(void);
+int ima_get_kexec_buffer(void **addr, size_t *size);
+int ima_free_kexec_buffer(void);
+
+#ifdef CONFIG_IMA_KEXEC
+int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr,
+			      void *buffer, size_t size);
+
+#else
+int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr,
+			      void *buffer, size_t size)
+{
+	return 0;
+}
+#endif /* CONFIG_IMA_KEXEC */
+#endif /* _ASM_ARM64_IMA_H */
arch/arm64/include/asm/kexec.h +5 -0
index d24b527e8c00..2bd19ccb6c43 100644
@@ -100,6 +100,11 @@ struct kimage_arch {
 	void *elf_headers;
 	unsigned long elf_headers_mem;
 	unsigned long elf_headers_sz;
+
+#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 +1 -0
index 4e5b8ee31442..cd3cb7690d51 100644
@@ -55,6 +55,7 @@ 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_HAVE_IMA_KEXEC)		+= ima_kexec.o
 obj-$(CONFIG_KEXEC_FILE)		+= machine_kexec_file.o kexec_image.o
 obj-$(CONFIG_ARM64_RELOC_TEST)		+= arm64-reloc-test.o
 arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o
arch/arm64/kernel/ima_kexec.c new file +64 -0

64 lines not on this page · raw message

arch/arm64/kernel/machine_kexec_file.c +1 -0
index b40c3b0def92..8dc25511142d 100644
@@ -22,6 +22,7 @@
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <asm/byteorder.h>
+#include <asm/ima.h>
 
 /* relevant device tree properties */
 #define FDT_PROP_KEXEC_ELFHDR	"linux,elfcorehdr"
arch/powerpc/include/asm/ima.h +2 -1
index ead488cf3981..a8febc620b42 100644
@@ -4,6 +4,7 @@
 
 struct kimage;
 
+int is_ima_memory_reserved(void);
 int ima_get_kexec_buffer(void **addr, size_t *size);
 int ima_free_kexec_buffer(void);
 
@@ -15,7 +16,7 @@ static inline 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);
+			      void *buffer, size_t size);
 
 int setup_ima_buffer(const struct kimage *image, void *fdt, int chosen_node);
 #else
arch/powerpc/kexec/ima.c +13 -1
index 720e50e490b6..3823539d4e07 100644
@@ -46,6 +46,18 @@ static int do_get_kexec_buffer(const void *prop, int len, unsigned long *addr,
 	return 0;
 }
 
+/**
+ * is_ima_memory_reserved - check if memory is reserved via device
+ *			    tree.
+ *	Return: negative or zero when memory is not reserved.
+ *	positive number on success.
+ *
+ */
+int is_ima_memory_reserved(void)
+{
+	return -EOPNOTSUPP;
+}
+
 /**
  * ima_get_kexec_buffer - get IMA buffer from the previous kernel
  * @addr:	On successful return, set to point to the buffer contents.
@@ -137,7 +149,7 @@ void remove_ima_buffer(void *fdt, int chosen_node)
  * Return: 0 on success, negative errno on error.
  */
 int arch_ima_add_kexec_buffer(struct kimage *image, unsigned long load_addr,
-			      size_t size)
+			      void *buffer, size_t size)
 {
 	image->arch.ima_buffer_addr = load_addr;
 	image->arch.ima_buffer_size = size;
security/integrity/ima/ima_kexec.c +10 -5
index 121de3e04af2..3749472c7e18 100644
@@ -116,13 +116,18 @@ void ima_add_kexec_buffer(struct kimage *image)
 	kbuf.buffer = kexec_buffer;
 	kbuf.bufsz = kexec_buffer_size;
 	kbuf.memsz = kexec_segment_size;
-	ret = kexec_add_buffer(&kbuf);
-	if (ret) {
-		pr_err("Error passing over kexec measurement buffer.\n");
-		return;
+
+	if (!is_ima_memory_reserved()) {
+
+		ret = kexec_add_buffer(&kbuf);
+		if (ret) {
+			pr_err("Error passing over kexec measurement buffer.\n");
+			return;
+		}
 	}
 
-	ret = arch_ima_add_kexec_buffer(image, kbuf.mem, kexec_segment_size);
+	ret = arch_ima_add_kexec_buffer(image, kbuf.mem, kexec_buffer,
+					kexec_segment_size);
 	if (ret) {
 		pr_err("Error passing over kexec measurement buffer.\n");
 		return;
Signature · 1 line
2.25.1
reviewer
#7 lore raw
In reply to Prakhar Srivastava

Hi Prakhar,

Quoted 8 lines · Prakhar Srivastava

IMA during kexec(kexec file load) verifies the kernel signature and measures the signature of the kernel. The signature in the logs can be used to verfiy the authenticity of the kernel. The logs don not get carried over kexec and thus remote attesation cannot verify the signature of the running kernel.

Introduce an ABI to carry forward the ima logs over kexec. Memory reserved via device tree reservation can be used to store and read via the of_* functions.

This flow needs to work for:

1) Pure DT
2) DT + EFI memory map
3) ACPI + EFI memory map

... and if this is just for transiently passing the log, I don't think that a reserved memory region is the right thing to use, since they're supposed to be more permanent.

This sounds analogous to passing the initrd, and should probably use properties under the chosen node (which can be used for all three boot flows above).

For reference, how big is the IMA log likely to be? Does it need physically contiguous space?

Thanks,
Mark.

Quoted 36 lines

Reserved memory stores the size(sizeof(size_t)) of the buffer in the starting address, followed by the IMA log contents.

Tested on:
arm64 with Uboot

Prakhar Srivastava (2):
Add a layer of abstraction to use the memory reserved by device tree
for ima buffer pass.
Add support for ima buffer pass using reserved memory for arm64 kexec.
Update the arch sepcific code path in kexec file load to store the ima buffer in the reserved memory. The same reserved memory is read on kexec or cold boot.

 arch/arm64/Kconfig                     |   1 +
 arch/arm64/include/asm/ima.h           |  22 ++++
 arch/arm64/include/asm/kexec.h         |   5 +
 arch/arm64/kernel/Makefile             |   1 +
 arch/arm64/kernel/ima_kexec.c          |  64 ++++++++++
 arch/arm64/kernel/machine_kexec_file.c |   1 +
 arch/powerpc/include/asm/ima.h         |   3 +-
 arch/powerpc/kexec/ima.c               |  14 ++-
 drivers/of/Kconfig                     |   6 +
 drivers/of/Makefile                    |   1 +
 drivers/of/of_ima.c                    | 165 +++++++++++++++++++++++++
 include/linux/of.h                     |  34 +++++
 security/integrity/ima/ima_kexec.c     |  15 ++-
 13 files changed, 325 insertions(+), 7 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 · 1 line
2.25.1
#2 lore raw

Re: [RFC][PATCH 1/2] Add a layer of abstraction to use the memory reserved by device tree for ima buffer pass.

In reply to Prakhar Srivastava
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Prakhar,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on robh/for-next powerpc/next v5.7-rc4 next-20200505] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Prakhar-Srivastava/Add-support-for-using-reserved-memory-for-ima-buffer-pass/20200505-184302
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: mips-pic32mzda_defconfig (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 9e3549804672c79d64eececab39019f4dfd2b7ea)

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

>> drivers/of/of_ima.c:133:1: warning: declaration specifier missing, defaulting to 'int'
   MODULE_DEVICE_TABLE(of, ima_buffer_pass_match);
   ^
   int
>> drivers/of/of_ima.c:133:21: error: a parameter list without types is only allowed in a function definition
   MODULE_DEVICE_TABLE(of, ima_buffer_pass_match);
                       ^
   drivers/of/of_ima.c:164:1: warning: declaration specifier missing, defaulting to 'int'
   module_init(ima_buffer_pass_init);
   ^
   int
   drivers/of/of_ima.c:164:13: error: a parameter list without types is only allowed in a function definition
   module_init(ima_buffer_pass_init);
               ^
   drivers/of/of_ima.c:165:1: warning: declaration specifier missing, defaulting to 'int'
   module_exit(ima_buffer_pass_exit);
   ^
   int
   drivers/of/of_ima.c:165:13: error: a parameter list without types is only allowed in a function definition
   module_exit(ima_buffer_pass_exit);
               ^

3 warnings and 3 errors generated.

vim +133 drivers/of/of_ima.c

127
128 static const struct of_device_id ima_buffer_pass_match[] = {
129 {
130 .name = "ima_buffer_pass",
131 },
132 };

 > 133	MODULE_DEVICE_TABLE(of, ima_buffer_pass_match);

134

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw

Re: [RFC][PATCH 1/2] Add a layer of abstraction to use the memory reserved by device tree for ima buffer pass.

In reply to Prakhar Srivastava
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Prakhar,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on robh/for-next powerpc/next v5.7-rc4 next-20200505] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Prakhar-Srivastava/Add-support-for-using-reserved-memory-for-ima-buffer-pass/20200505-184302
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: h8300-h8s-sim_defconfig (attached as .config)
compiler: h8300-linux-gcc (GCC) 9.3.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=h8300

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

In file included from include/linux/kernel.h:15,

                    from include/asm-generic/bug.h:19,
                    from arch/h8300/include/asm/bug.h:8,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/gfp.h:5,
                    from include/linux/slab.h:15,
                    from drivers/of/of_ima.c:6:
   drivers/of/of_ima.c: In function 'of_ima_write_buffer':
>> drivers/of/of_ima.c:47:2: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
      47 |  (u64)vaddr, mem_res.start, resource_size(&mem_res));
         |  ^
   include/linux/printk.h:305:34: note: in definition of macro 'pr_info'
     305 |  printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |                                  ^~~~~~~~~~~
   In file included from include/linux/printk.h:7,
                    from include/linux/kernel.h:15,
                    from include/asm-generic/bug.h:19,
                    from arch/h8300/include/asm/bug.h:8,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/gfp.h:5,
                    from include/linux/slab.h:15,
                    from drivers/of/of_ima.c:6:
>> include/linux/kern_levels.h:5:18: warning: format '%llX' expects argument of type 'long long unsigned int', but argument 3 has type 'resource_size_t' {aka 'unsigned int'} [-Wformat=]
       5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
         |                  ^~~~~~
   include/linux/kern_levels.h:14:19: note: in expansion of macro 'KERN_SOH'
      14 | #define KERN_INFO KERN_SOH "6" /* informational */
         |                   ^~~~~~~~
   include/linux/printk.h:305:9: note: in expansion of macro 'KERN_INFO'
     305 |  printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~
>> drivers/of/of_ima.c:46:2: note: in expansion of macro 'pr_info'
      46 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX\n , size : %lld",
         |  ^~~~~~~
   drivers/of/of_ima.c:46:64: note: format string is defined here
      46 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX\n , size : %lld",
         |                                                            ~~~~^
         |                                                                |
         |                                                                long long unsigned int
         |                                                            %0X
   In file included from include/linux/printk.h:7,
                    from include/linux/kernel.h:15,
                    from include/asm-generic/bug.h:19,
                    from arch/h8300/include/asm/bug.h:8,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/gfp.h:5,
                    from include/linux/slab.h:15,
                    from drivers/of/of_ima.c:6:
>> include/linux/kern_levels.h:5:18: warning: format '%lld' expects argument of type 'long long int', but argument 4 has type 'resource_size_t' {aka 'unsigned int'} [-Wformat=]
       5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
         |                  ^~~~~~
   include/linux/kern_levels.h:14:19: note: in expansion of macro 'KERN_SOH'
      14 | #define KERN_INFO KERN_SOH "6" /* informational */
         |                   ^~~~~~~~
   include/linux/printk.h:305:9: note: in expansion of macro 'KERN_INFO'
     305 |  printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~
>> drivers/of/of_ima.c:46:2: note: in expansion of macro 'pr_info'
      46 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX\n , size : %lld",
         |  ^~~~~~~
   drivers/of/of_ima.c:46:80: note: format string is defined here
      46 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX\n , size : %lld",
         |                                                                             ~~~^
         |                                                                                |
         |                                                                                long long int
         |                                                                             %d
   In file included from include/linux/kernel.h:15,
                    from include/asm-generic/bug.h:19,
                    from arch/h8300/include/asm/bug.h:8,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/gfp.h:5,
                    from include/linux/slab.h:15,
                    from drivers/of/of_ima.c:6:
   drivers/of/of_ima.c: In function 'of_get_ima_buffer':
   drivers/of/of_ima.c:114:2: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     114 |  (u64)vaddr, mem_res.start, resource_size(&mem_res), *(size_t *)vaddr);
         |  ^
   include/linux/printk.h:305:34: note: in definition of macro 'pr_info'
     305 |  printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |                                  ^~~~~~~~~~~
   In file included from include/linux/printk.h:7,
                    from include/linux/kernel.h:15,
                    from include/asm-generic/bug.h:19,
                    from arch/h8300/include/asm/bug.h:8,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/gfp.h:5,
                    from include/linux/slab.h:15,
                    from drivers/of/of_ima.c:6:
>> include/linux/kern_levels.h:5:18: warning: format '%llX' expects argument of type 'long long unsigned int', but argument 3 has type 'resource_size_t' {aka 'unsigned int'} [-Wformat=]
       5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
         |                  ^~~~~~
   include/linux/kern_levels.h:14:19: note: in expansion of macro 'KERN_SOH'
      14 | #define KERN_INFO KERN_SOH "6" /* informational */
         |                   ^~~~~~~~
   include/linux/printk.h:305:9: note: in expansion of macro 'KERN_INFO'
     305 |  printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~
   drivers/of/of_ima.c:113:2: note: in expansion of macro 'pr_info'
     113 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX,\n allocated size : %lld, ima_buffer_size: %ld ",
         |  ^~~~~~~
   drivers/of/of_ima.c:113:64: note: format string is defined here
     113 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX,\n allocated size : %lld, ima_buffer_size: %ld ",
         |                                                            ~~~~^
         |                                                                |
         |                                                                long long unsigned int
         |                                                            %0X
   In file included from include/linux/printk.h:7,
                    from include/linux/kernel.h:15,
                    from include/asm-generic/bug.h:19,
                    from arch/h8300/include/asm/bug.h:8,
                    from include/linux/bug.h:5,
                    from include/linux/mmdebug.h:5,
                    from include/linux/gfp.h:5,
                    from include/linux/slab.h:15,
                    from drivers/of/of_ima.c:6:
>> include/linux/kern_levels.h:5:18: warning: format '%lld' expects argument of type 'long long int', but argument 4 has type 'resource_size_t' {aka 'unsigned int'} [-Wformat=]
       5 | #define KERN_SOH "\001"  /* ASCII Start Of Header */
         |                  ^~~~~~
   include/linux/kern_levels.h:14:19: note: in expansion of macro 'KERN_SOH'
      14 | #define KERN_INFO KERN_SOH "6" /* informational */
         |                   ^~~~~~~~
   include/linux/printk.h:305:9: note: in expansion of macro 'KERN_INFO'
     305 |  printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~
   drivers/of/of_ima.c:113:2: note: in expansion of macro 'pr_info'
     113 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX,\n allocated size : %lld, ima_buffer_size: %ld ",
         |  ^~~~~~~
   drivers/of/of_ima.c:113:89: note: format string is defined here
     113 |  pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX,\n allocated size : %lld, ima_buffer_size: %ld ",
         |                                                                                      ~~~^
         |                                                                                         |
         |                                                                                         long long int
         |                                                                                      %d
   drivers/of/of_ima.c: At top level:
>> drivers/of/of_ima.c:133:1: warning: data definition has no type or storage class
     133 | MODULE_DEVICE_TABLE(of, ima_buffer_pass_match);
         | ^~~~~~~~~~~~~~~~~~~
>> drivers/of/of_ima.c:133:1: error: type defaults to 'int' in declaration of 'MODULE_DEVICE_TABLE' [-Werror=implicit-int]
>> drivers/of/of_ima.c:133:1: warning: parameter names (without types) in function declaration
   drivers/of/of_ima.c:164:1: warning: data definition has no type or storage class
     164 | module_init(ima_buffer_pass_init);
         | ^~~~~~~~~~~
>> drivers/of/of_ima.c:164:1: error: type defaults to 'int' in declaration of 'module_init' [-Werror=implicit-int]
   drivers/of/of_ima.c:164:1: warning: parameter names (without types) in function declaration
   drivers/of/of_ima.c:165:1: warning: data definition has no type or storage class
     165 | module_exit(ima_buffer_pass_exit);
         | ^~~~~~~~~~~
>> drivers/of/of_ima.c:165:1: error: type defaults to 'int' in declaration of 'module_exit' [-Werror=implicit-int]

drivers/of/of_ima.c:165:1: warning: parameter names (without types) in function declaration drivers/of/of_ima.c:135:19: warning: 'ima_buffer_pass_init' defined but not used [-Wunused-function]
135 | static int __init ima_buffer_pass_init(void)
| ^~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

vim +133 drivers/of/of_ima.c

    29	
    30	/**
    31	 * of_ima_write_buffer - Write the ima buffer into the reserved memory.
    32	 *
    33	 * ima_buffer - buffer starting address.
    34	 * ima_buffer_size - size of segment.
    35	 *
    36	 * Return: 0 on success, negative errno on error.
    37	 */
    38	int of_ima_write_buffer(void *ima_buffer, size_t ima_buffer_size)
    39	{
    40		void *addr;
    41	
    42		if (!dtb_status_enabled)
    43			return -EOPNOTSUPP;
    44	
    45		vaddr = memremap(mem_res.start, resource_size(&mem_res), MEMREMAP_WB);
  > 46		pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX\n , size : %lld",
  > 47		(u64)vaddr, mem_res.start, resource_size(&mem_res));
    48	
    49		if (vaddr) {
    50			memcpy(vaddr, &ima_buffer_size, sizeof(size_t));
    51			addr =  vaddr + sizeof(size_t);
    52			memcpy(addr, ima_buffer, ima_buffer_size);
    53			memunmap(vaddr);
    54			vaddr = NULL;
    55		}
    56	
    57		return 0;
    58	}
    59	
    60	/**
    61	 * of_remove_ima_buffer - Write 0(Zero length buffer to read)to the
    62	 *                        size location of the buffer.
    63	 *
    64	 * Return: 0 on success, negative errno on error.
    65	 */
    66	int of_remove_ima_buffer(void)
    67	{
    68		size_t empty_buffer_size = 0;
    69	
    70		if (!dtb_status_enabled)
    71			return -ENOTSUPP;
    72	
    73		if (vaddr) {
    74			memcpy(vaddr, &empty_buffer_size, sizeof(size_t));
    75			memunmap(vaddr);
    76			vaddr = NULL;
    77		}
    78	
    79		return 0;
    80	}
    81	
    82	/**
    83	 * of_ima_get_size_allocated - Get the usable buffer size thats allocated in
    84	 *                             the device-tree.
    85	 *
    86	 * Return: 0 on unavailable node, size of the memory block - (size_t)
    87	 */
    88	size_t of_ima_get_size_allocated(void)
    89	{
    90		size_t size = 0;
    91	
    92		if (!dtb_status_enabled)
    93			return size;
    94	
    95		size = resource_size(&mem_res) - sizeof(size_t);
    96		return size;
    97	}
    98	
    99	/**
   100	 * of_get_ima_buffer - Get IMA buffer address.
   101	 *
   102	 * @addr:       On successful return, set to point to the buffer contents.
   103	 * @size:       On successful return, set to the buffer size.
   104	 *
   105	 * Return: 0 on success, negative errno on error.
   106	 */
   107	int of_get_ima_buffer(void **addr, size_t *size)
   108	{
   109		if (!dtb_status_enabled)
   110			return -ENOTSUPP;
   111	
   112		vaddr = memremap(mem_res.start, resource_size(&mem_res), MEMREMAP_WB);
   113		pr_info("Mapped reserved memory, vaddr: 0x%0llX, paddr: 0x%0llX,\n allocated size : %lld, ima_buffer_size: %ld ",
   114		(u64)vaddr, mem_res.start, resource_size(&mem_res), *(size_t *)vaddr);
   115	
   116		*size = *(size_t *)vaddr;
   117		*addr = vaddr + sizeof(size_t);
   118		return 0;
   119	}
   120	
   121	static const struct of_device_id ima_buffer_pass_ids[] = {
   122		{
   123			.compatible = "linux,ima_buffer_pass",
   124		},
   125		{}
   126	};
   127	
   128	static const struct of_device_id ima_buffer_pass_match[] = {
   129		{
   130			.name = "ima_buffer_pass",
   131		},
   132	};
 > 133	MODULE_DEVICE_TABLE(of, ima_buffer_pass_match);
   134	
   135	static int __init ima_buffer_pass_init(void)
   136	{
   137		int ret = 0;
   138		struct device_node *memnp;
   139		struct device_node *ima_buffer_pass_node;
   140	
   141		ima_buffer_pass_node = of_find_matching_node(NULL, ima_buffer_pass_ids);
   142		if (!ima_buffer_pass_node)
   143			return -ENOENT;
   144	
   145		memnp = of_parse_phandle(ima_buffer_pass_node, "memory-region", 0);
   146		if (!memnp)
   147			return -ENXIO;
   148	
   149		ret = of_address_to_resource(memnp, 0, &mem_res);
   150		if (ret < 0)
   151			return -ENOENT;
   152	
   153		of_node_put(memnp);
   154		dtb_status_enabled = true;
   155	
   156		return ret;
   157	}
   158	
   159	static void __exit ima_buffer_pass_exit(void)
   160	{
   161		pr_info("trying to exit the ima driver\n");
   162	}
   163	
 > 164	module_init(ima_buffer_pass_init);
 > 165	module_exit(ima_buffer_pass_exit);

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#8 lore raw
In reply to Mark Rutland

Hi Mark,

This patch set currently only address the Pure DT implementation. EFI and ACPI implementations will be posted in subsequent patchsets.

The logs are intended to be carried over the kexec and once read the
logs are no longer needed and in prior conversation with James(
https://lore.kernel.org/linux-arm-kernel/[email protected]/) the apporach of using a chosen node doesn't support the case.

The DT entries make the reservation permanent and thus doesnt need kernel segments to be used for this, however using a chosen-node with reserved memory only changes the node information but memory still is
reserved via reserved-memory section.

Quoted 22 lines · Mark Rutland

Hi Prakhar,

Quoted 8 lines · Prakhar Srivastava

IMA during kexec(kexec file load) verifies the kernel signature and measures the signature of the kernel. The signature in the logs can be used to verfiy the authenticity of the kernel. The logs don not get carried over kexec and thus remote attesation cannot verify the signature of the running kernel.

Introduce an ABI to carry forward the ima logs over kexec. Memory reserved via device tree reservation can be used to store and read via the of_* functions.

This flow needs to work for:

1) Pure DT
2) DT + EFI memory map
3) ACPI + EFI memory map

... and if this is just for transiently passing the log, I don't think that a reserved memory region is the right thing to use, since they're supposed to be more permanent.

Quoted 6 lines

This sounds analogous to passing the initrd, and should probably use properties under the chosen node (which can be used for all three boot flows above).

For reference, how big is the IMA log likely to be? Does it need physically contiguous space?

It purely depends on the policy used and the modules/files that are accessed for my local testing over a kexec session the log in about 30KB.

Current implementation expects enough contiguous memory to allocated to carry forward the logs. If the log size exceeds the reserved memory the call will fail.

Thanks,
Prakhar Srivastava

Quoted 40 lines

Thanks,
Mark.

Quoted 36 lines

Reserved memory stores the size(sizeof(size_t)) of the buffer in the starting address, followed by the IMA log contents.

Tested on:
arm64 with Uboot

Prakhar Srivastava (2):
Add a layer of abstraction to use the memory reserved by device tree
for ima buffer pass.
Add support for ima buffer pass using reserved memory for arm64 kexec.
Update the arch sepcific code path in kexec file load to store the ima buffer in the reserved memory. The same reserved memory is read on kexec or cold boot.

  arch/arm64/Kconfig                     |   1 +
  arch/arm64/include/asm/ima.h           |  22 ++++
  arch/arm64/include/asm/kexec.h         |   5 +
  arch/arm64/kernel/Makefile             |   1 +
  arch/arm64/kernel/ima_kexec.c          |  64 ++++++++++
  arch/arm64/kernel/machine_kexec_file.c |   1 +
  arch/powerpc/include/asm/ima.h         |   3 +-
  arch/powerpc/kexec/ima.c               |  14 ++-
  drivers/of/Kconfig                     |   6 +
  drivers/of/Makefile                    |   1 +
  drivers/of/of_ima.c                    | 165 +++++++++++++++++++++++++
  include/linux/of.h                     |  34 +++++
  security/integrity/ima/ima_kexec.c     |  15 ++-
  13 files changed, 325 insertions(+), 7 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 · 1 line
2.25.1
maintainer
#9 lore raw
Quoted 1 line · Prakhar Srivastava

Hi Mark,

Please don't top post.

Quoted 9 lines

This patch set currently only address the Pure DT implementation. EFI and ACPI implementations will be posted in subsequent patchsets.

The logs are intended to be carried over the kexec and once read the logs are no longer needed and in prior conversation with James(
https://lore.kernel.org/linux-arm-kernel/[email protected]/)
the apporach of using a chosen node doesn't
support the case.

Quoted 4 lines

The DT entries make the reservation permanent and thus doesnt need kernel segments to be used for this, however using a chosen-node with reserved memory only changes the node information but memory still is reserved via reserved-memory section.

I think Mark's point was whether it needs to be permanent. We don't hardcode the initrd address for example.

Quoted 5 lines · Mark Rutland
Quoted 4 lines

Hi Prakhar,

Quoted 1 line · Prakhar Srivastava

IMA during kexec(kexec file load) verifies the kernel signature and measures

What's IMA?

Quoted 75 lines
Quoted 18 lines
Quoted 7 lines

the signature of the kernel. The signature in the logs can be used to verfiy the authenticity of the kernel. The logs don not get carried over kexec and thus remote attesation cannot verify the signature of the running kernel.

Introduce an ABI to carry forward the ima logs over kexec. Memory reserved via device tree reservation can be used to store and read via the of_* functions.

This flow needs to work for:

1) Pure DT
2) DT + EFI memory map
3) ACPI + EFI memory map

... and if this is just for transiently passing the log, I don't think that a reserved memory region is the right thing to use, since they're supposed to be more permanent.

Quoted 6 lines

This sounds analogous to passing the initrd, and should probably use properties under the chosen node (which can be used for all three boot flows above).

For reference, how big is the IMA log likely to be? Does it need physically contiguous space?

It purely depends on the policy used and the modules/files that are accessed for my local testing over a kexec session the log in
about 30KB.

Current implementation expects enough contiguous memory to allocated to carry forward the logs. If the log size exceeds the reserved memory the call will fail.

Thanks,
Prakhar Srivastava

Quoted 40 lines

Thanks,
Mark.

Quoted 36 lines

Reserved memory stores the size(sizeof(size_t)) of the buffer in the starting address, followed by the IMA log contents.

Tested on:
arm64 with Uboot

Prakhar Srivastava (2):
Add a layer of abstraction to use the memory reserved by device tree
for ima buffer pass.
Add support for ima buffer pass using reserved memory for arm64 kexec.
Update the arch sepcific code path in kexec file load to store the ima buffer in the reserved memory. The same reserved memory is read on kexec or cold boot.

  arch/arm64/Kconfig                     |   1 +
  arch/arm64/include/asm/ima.h           |  22 ++++
  arch/arm64/include/asm/kexec.h         |   5 +
  arch/arm64/kernel/Makefile             |   1 +
  arch/arm64/kernel/ima_kexec.c          |  64 ++++++++++
  arch/arm64/kernel/machine_kexec_file.c |   1 +
  arch/powerpc/include/asm/ima.h         |   3 +-
  arch/powerpc/kexec/ima.c               |  14 ++-
  drivers/of/Kconfig                     |   6 +
  drivers/of/Makefile                    |   1 +
  drivers/of/of_ima.c                    | 165 +++++++++++++++++++++++++
  include/linux/of.h                     |  34 +++++
  security/integrity/ima/ima_kexec.c     |  15 ++-
  13 files changed, 325 insertions(+), 7 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 · 1 line
2.25.1
maintainer
#4 lore raw

Re: [RFC][PATCH 1/2] Add a layer of abstraction to use the memory reserved by device tree for ima buffer pass.

In reply to Prakhar Srivastava
Quoted 2 lines · Prakhar Srivastava

Introduce a device tree layer for to read and store ima buffer from the reserved memory section of a device tree.

But why do I need 'a layer of abstraction'? I don't like them.

Quoted 5 lines
---
 drivers/of/Kconfig  |   6 ++
 drivers/of/Makefile |   1 +
 drivers/of/of_ima.c | 165 ++++++++++++++++++++++++++++++++++++++++++++

Who are the users of this code and why does it need to be here? Most code for specific bindings are not in drivers/of/ but with the user. It doesn't sound like there's more than 1 user.

Quoted 3 lines
 include/linux/of.h  |  34 +++++++++
 4 files changed, 206 insertions(+)
 create mode 100644 drivers/of/of_ima.c
#10 lore raw
In reply to Rob Herring
Quoted 14 lines · Rob Herring
Quoted 1 line · Prakhar Srivastava

Hi Mark,

Please don't top post.

Quoted 9 lines

This patch set currently only address the Pure DT implementation. EFI and ACPI implementations will be posted in subsequent patchsets.

The logs are intended to be carried over the kexec and once read the logs are no longer needed and in prior conversation with James(
https://lore.kernel.org/linux-arm-kernel/[email protected]/)
the apporach of using a chosen node doesn't
support the case.

Quoted 8 lines
Quoted 4 lines

The DT entries make the reservation permanent and thus doesnt need kernel segments to be used for this, however using a chosen-node with reserved memory only changes the node information but memory still is reserved via reserved-memory section.

I think Mark's point was whether it needs to be permanent. We don't hardcode the initrd address for example.

Thankyou for clarifying my misunderstanding, i am modelling this keeping to the TPM log implementation that uses a reserved memory. I will rev up the version with chosen-node support. That will make the memory reservation free after use.

Quoted 7 lines
Quoted 5 lines · Mark Rutland
Quoted 4 lines

Hi Prakhar,

Quoted 1 line · Prakhar Srivastava

IMA during kexec(kexec file load) verifies the kernel signature and measures

What's IMAIMA is a LSM attempting to detect if files have been accidentally or

maliciously altered, both remotely and locally, it can also be used
to appraise a file's measurement against a "good" value stored as an extended attribute, and enforce local file integrity.

IMA also validates and measures the signers of the kernel and initrd
during kexec. The measurements are extended to PCR 10(configurable) and the logs stored in memory, however once kexec'd the logs are lost. Kexec is used as secondary boot loader in may use cases and loosing the signer creates a security hole.

This patch is an implementation to carry over the logs and making it
possible to remotely validate the signers of the kernel and initrd. Such a support exits only in powerpc. This patch makes the carry over of logs architecture independent and puts the complexity in a driver.

Thanks,
Prakhar

Quoted 76 lines
Quoted 76 lines
Quoted 19 lines
Quoted 8 lines

the signature of the kernel. The signature in the logs can be used to verfiy the authenticity of the kernel. The logs don not get carried over kexec and thus remote attesation cannot verify the signature of the running kernel.

Introduce an ABI to carry forward the ima logs over kexec. Memory reserved via device tree reservation can be used to store and read via the of_* functions.

This flow needs to work for:

1) Pure DT
2) DT + EFI memory map
3) ACPI + EFI memory map

... and if this is just for transiently passing the log, I don't think that a reserved memory region is the right thing to use, since they're supposed to be more permanent.

Quoted 6 lines

This sounds analogous to passing the initrd, and should probably use properties under the chosen node (which can be used for all three boot flows above).

For reference, how big is the IMA log likely to be? Does it need physically contiguous space?

It purely depends on the policy used and the modules/files that are accessed for my local testing over a kexec session the log in
about 30KB.

Current implementation expects enough contiguous memory to allocated to carry forward the logs. If the log size exceeds the reserved memory the call will fail.

Thanks,
Prakhar Srivastava

Quoted 40 lines

Thanks,
Mark.

Quoted 36 lines

Reserved memory stores the size(sizeof(size_t)) of the buffer in the starting address, followed by the IMA log contents.

Tested on:
arm64 with Uboot

Prakhar Srivastava (2):
Add a layer of abstraction to use the memory reserved by device tree
for ima buffer pass.
Add support for ima buffer pass using reserved memory for arm64 kexec.
Update the arch sepcific code path in kexec file load to store the ima buffer in the reserved memory. The same reserved memory is read on kexec or cold boot.

   arch/arm64/Kconfig                     |   1 +
   arch/arm64/include/asm/ima.h           |  22 ++++
   arch/arm64/include/asm/kexec.h         |   5 +
   arch/arm64/kernel/Makefile             |   1 +
   arch/arm64/kernel/ima_kexec.c          |  64 ++++++++++
   arch/arm64/kernel/machine_kexec_file.c |   1 +
   arch/powerpc/include/asm/ima.h         |   3 +-
   arch/powerpc/kexec/ima.c               |  14 ++-
   drivers/of/Kconfig                     |   6 +
   drivers/of/Makefile                    |   1 +
   drivers/of/of_ima.c                    | 165 +++++++++++++++++++++++++
   include/linux/of.h                     |  34 +++++
   security/integrity/ima/ima_kexec.c     |  15 ++-
   13 files changed, 325 insertions(+), 7 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 · 1 line
2.25.1
#5 lore raw

Re: [RFC][PATCH 1/2] Add a layer of abstraction to use the memory reserved by device tree for ima buffer pass.

In reply to Rob Herring
Quoted 6 lines · Rob Herring
Quoted 2 lines · Prakhar Srivastava

Introduce a device tree layer for to read and store ima buffer from the reserved memory section of a device tree.

But why do I need 'a layer of abstraction'? I don't like them.

This is a common path for the all architectures to carry over the IMA measurement logs. A single layer will avoid any code duplication.

Quoted 10 lines
Quoted 5 lines
---
  drivers/of/Kconfig  |   6 ++
  drivers/of/Makefile |   1 +
  drivers/of/of_ima.c | 165 ++++++++++++++++++++++++++++++++++++++++++++

Who are the users of this code and why does it need to be here? Most code for specific bindings are not in drivers/of/ but with the user. It doesn't sound like there's more than 1 user.

Currently the path is exercised by arm64 kexec_file_load path. A slight
restructuring is needed on the powerpc side to use the same code path and other architectures can follow to add carrying over IMA logs over kexec with just a few function calls.

I have attempted to bring the code path down to the highest common layer, however please do suggest if i can move this some where else.

Thanks,
Prakhar

Quoted 3 lines
Quoted 3 lines
  include/linux/of.h  |  34 +++++++++
  4 files changed, 206 insertions(+)

create mode 100644 drivers/of/of_ima.c

#11 lore raw
In reply to Prakhar Srivastava

Hello Prakhar,

Quoted 20 lines · Prakhar Srivastava
Quoted 19 lines · Rob Herring
Quoted 1 line · Prakhar Srivastava

Hi Mark,

Please don't top post.

Quoted 13 lines

This patch set currently only address the Pure DT implementation. EFI and ACPI implementations will be posted in subsequent patchsets.

The logs are intended to be carried over the kexec and once read the logs are no longer needed and in prior conversation with James(
https://lore.kernel.org/linux-arm-kernel/[email protected]/)
the apporach of using a chosen node doesn't
support the case.

The DT entries make the reservation permanent and thus doesnt need kernel segments to be used for this, however using a chosen-node with reserved memory only changes the node information but memory still is reserved via reserved-memory section.

Quoted 7 lines
Quoted 3 lines

I think Mark's point was whether it needs to be permanent. We don't hardcode the initrd address for example.

Thankyou for clarifying my misunderstanding, i am modelling this keeping to the TPM log implementation that uses a reserved memory. I will rev up the version with chosen-node support.
That will make the memory reservation free after use.

Nice. Do you intend to use the same property that powerpc uses (linux,ima-kexec-buffer)?

Quoted 17 lines
Quoted 7 lines
Quoted 5 lines · Mark Rutland
Quoted 4 lines

Hi Prakhar,

Quoted 1 line · Prakhar Srivastava

IMA during kexec(kexec file load) verifies the kernel signature and measures

What's IMAIMA is a LSM attempting to detect if files have been accidentally or

maliciously altered, both remotely and locally, it can also be used to appraise a file's measurement against a "good" value stored as an extended attribute, and enforce local file integrity.

IMA also validates and measures the signers of the kernel and initrd during kexec. The measurements are extended to PCR 10(configurable) and the logs stored in memory, however once kexec'd the logs are lost. Kexec is used as secondary boot loader in may use cases and loosing the signer creates a security hole.

Quoted 5 lines

This patch is an implementation to carry over the logs and making it possible to remotely validate the signers of the kernel and initrd. Such a support exits only in powerpc.
This patch makes the carry over of logs architecture independent and puts the complexity in a driver.

If I'm not mistaken, the code at arch/powerpc/kexec/ima.c isn't actually powerpc-specific. It could be moved to an arch-independent directory and used by any other architecture which supports device trees.

I think that's the simplest way forward. And to be honest I'm still trying to understand why you didn't take that approach. Did you try it and hit some obstacle or noticed a disadvantage for your use case?

--
Thiago Jung Bauermann
IBM Linux Technology Center

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#12 lore raw
Quoted 28 lines · Thiago Jung Bauermann

Hello Prakhar,

Quoted 23 lines · Prakhar Srivastava
Quoted 22 lines · Rob Herring
Quoted 1 line · Prakhar Srivastava

Hi Mark,

Please don't top post.

Quoted 9 lines

This patch set currently only address the Pure DT implementation. EFI and ACPI implementations will be posted in subsequent patchsets.

The logs are intended to be carried over the kexec and once read the logs are no longer needed and in prior conversation with James(
https://lore.kernel.org/linux-arm-kernel/[email protected]/)
the apporach of using a chosen node doesn't
support the case.

Quoted 4 lines

The DT entries make the reservation permanent and thus doesnt need kernel segments to be used for this, however using a chosen-node with reserved memory only changes the node information but memory still is reserved via reserved-memory section.

I think Mark's point was whether it needs to be permanent. We don't hardcode the initrd address for example.

Quoted 8 lines
Quoted 4 lines

Thankyou for clarifying my misunderstanding, i am modelling this keeping to the TPM log implementation that uses a reserved memory. I will rev up the version with chosen-node support.
That will make the memory reservation free after use.

Nice. Do you intend to use the same property that powerpc uses (linux,ima-kexec-buffer)?

I was naming it ima-buffer, but naming is not a huge concern. I will use linux,ima-kexec-buffer.

Quoted 23 lines
Quoted 17 lines
Quoted 7 lines
Quoted 5 lines · Mark Rutland
Quoted 4 lines

Hi Prakhar,

Quoted 1 line · Prakhar Srivastava

IMA during kexec(kexec file load) verifies the kernel signature and measures

What's IMAIMA is a LSM attempting to detect if files have been accidentally or

maliciously altered, both remotely and locally, it can also be used to appraise a file's measurement against a "good" value stored as an extended attribute, and enforce local file integrity.

IMA also validates and measures the signers of the kernel and initrd during kexec. The measurements are extended to PCR 10(configurable) and the logs stored in memory, however once kexec'd the logs are lost. Kexec is used as secondary boot loader in may use cases and loosing the signer creates a security hole.

Quoted 5 lines

This patch is an implementation to carry over the logs and making it possible to remotely validate the signers of the kernel and initrd. Such a support exits only in powerpc.
This patch makes the carry over of logs architecture independent and puts the complexity in a driver.

Quoted 8 lines

If I'm not mistaken, the code at arch/powerpc/kexec/ima.c isn't actually powerpc-specific. It could be moved to an arch-independent directory and used by any other architecture which supports device trees.

I think that's the simplest way forward. And to be honest I'm still trying to understand why you didn't take that approach. Did you try it and hit some obstacle or noticed a disadvantage for your use case?

The approach i have in this patch set is to provide an abstraction layer that can be called from any architecture. However taking a deeper look only the setup dtb is probably architecture
specific, only because the architecture specific kexec sets up the device tree. I can also move the code up in security/ima. However i do have some concerns with layering. I am hoping you can provide me with some guidance in this aspect, i will send you the patch i am working on to get some early feedback.

Thanks,
Prakhar Srivastava

Quoted 4 lines

--
Thiago Jung Bauermann
IBM Linux Technology Center