powerpc: Enabling IMA arch specific secure boot policies
Subsystems (2)
v5 cover powerpc: Enabling IMA arch specific secure boot policies
IMA subsystem supports custom, built-in, arch-specific policies to define the files to be measured and appraised. These policies are honored based on the priority where arch-specific policies is the highest and custom is the lowest.
OpenPOWER systems rely on IMA for signature verification of the kernel. This patchset adds support for powerpc specific arch policies that are defined based on system's OS secureboot state. The OS secureboot state of the system is determined via device-tree entry.
Changelog:
v5:
* secureboot state is now read via device tree entry rather than OPAL secure variables
* ima arch policies are updated to use policy based template for measurement rules
v4:
* Fixed the build issue as reported by Satheesh Rajendran.
v3:
* OPAL APIs in Patch 1 are updated to provide generic interface based on key/keylen. This patchset updates kernel OPAL APIs to be compatible with generic interface.
* Patch 2 is cleaned up to use new OPAL APIs.
* Since OPAL can support different types of backend which can vary in the variable interpretation, the Patch 2 is updated to add a check for the backend version
* OPAL API now expects consumer to first check the supported backend version before calling other secvar OPAL APIs. This check is now added in patch 2.
* IMA policies in Patch 3 is updated to specify appended signature and per policy template.
* The patches now are free of any EFIisms.
v2:
* Removed Patch 1: powerpc/include: Override unneeded early ioremap functions
* Updated Subject line and patch description of the Patch 1 of this series
* Removed dependency of OPAL_SECVAR on EFI, CPU_BIG_ENDIAN and UCS2_STRING
* Changed OPAL APIs from static to non-static. Added opal-secvar.h for the same
* Removed EFI hooks from opal_secvar.c
* Removed opal_secvar_get_next(), opal_secvar_enqueue() and opal_query_variable_info() function
* get_powerpc_sb_mode() in secboot.c now directly calls OPAL Runtime API rather than via EFI hooks.
* Fixed log messages in get_powerpc_sb_mode() function.
* Added dependency for PPC_SECURE_BOOT on configs PPC64 and OPAL_SECVAR
* Replaced obj-$(CONFIG_IMA) with obj-$(CONFIG_PPC_SECURE_BOOT) in arch/powerpc/kernel/Makefile
Nayna Jain (2):
powerpc: detect the secure boot mode of the system
powerpc: Add support to initialize ima policy rules
arch/powerpc/Kconfig | 13 ++++++ arch/powerpc/include/asm/secboot.h | 27 ++++++++++++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/ima_arch.c | 50 +++++++++++++++++++++ arch/powerpc/kernel/secboot.c | 71 ++++++++++++++++++++++++++++++ include/linux/ima.h | 3 +- 6 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/secboot.h create mode 100644 arch/powerpc/kernel/ima_arch.c create mode 100644 arch/powerpc/kernel/secboot.c
Signature · 1 line
2.20.1
PATCH v5 1/2 powerpc: detect the secure boot mode of the system
Secure boot on POWER defines different IMA policies based on the secure boot state of the system.
This patch defines a function to detect the secure boot state of the system.
The PPC_SECURE_BOOT config represents the base enablement of secureboot on POWER.
--- arch/powerpc/Kconfig | 11 +++++ arch/powerpc/include/asm/secboot.h | 27 ++++++++++++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/secboot.c | 71 ++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 arch/powerpc/include/asm/secboot.h create mode 100644 arch/powerpc/kernel/secboot.c
arch/powerpc/Kconfig +11 -0
@@ -912,6 +912,17 @@ config PPC_MEM_KEYS If unsure, say y. +config PPC_SECURE_BOOT + prompt "Enable PowerPC Secure Boot" + bool + default n + depends on PPC64 + help + Linux on POWER with firmware secure boot enabled needs to define + security policies to extend secure boot to the OS.This config + allows user to enable OS Secure Boot on PowerPC systems that + have firmware secure boot support. + endmenu config ISA_DMA_API
arch/powerpc/include/asm/secboot.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* PowerPC secure boot definitions +* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain <[email protected]> +* +*/ +#ifndef POWERPC_SECBOOT_H +#define POWERPC_SECBOOT_H + +#ifdef CONFIG_PPC_SECURE_BOOT +extern struct device_node *is_powerpc_secvar_supported (void ); +extern bool get_powerpc_secureboot (void ); +#else +static inline struct device_node *is_powerpc_secvar_supported (void ) +{ +return NULL ; +} + +static inline bool get_powerpc_secureboot (void ) +{ +return false; +} + +#endif +#endif
arch/powerpc/kernel/Makefile +2 -0
@@ -157,6 +157,8 @@ endif obj-$(CONFIG_EPAPR_PARAVIRT) += epapr_paravirt.o epapr_hcalls.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvm_emul.o +obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o + # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_prom_init.o := n KCOV_INSTRUMENT_prom_init.o := n
arch/powerpc/kernel/secboot.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.20.1
Michael Ellerman
reviewerRe: [PATCH v5 1/2] powerpc: detect the secure boot mode of the system
Hi Nayna,
Sorry I've taken so long to get to this series, there's just too many patches that need reviewing :/
Quoted 2 lines · Nayna Jain
Secure boot on POWER defines different IMA policies based on the secure boot state of the system.
The terminology throughout is a bit vague, we have POWER, PowerPC, Linux on POWER etc.
What this patch is talking about is a particular implemention of secure boot on some OpenPOWER machines running bare metal - am I right?
So saying "Secure boot on POWER defines different IMA policies" is a bit broad I think. Really we've just decided that a way to implement secure boot is to use IMA policies.
Quoted 21 lines
This patch defines a function to detect the secure boot state of the system.
The
PPC_SECURE_BOOTconfig represents the base enablement of secureboot on POWER.Signed-off-by Nayna Jain <[email protected]>--- arch/powerpc/Kconfig | 11 +++++ arch/powerpc/include/asm/secboot.h | 27 ++++++++++++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/secboot.c | 71 ++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 arch/powerpc/include/asm/secboot.h create mode 100644 arch/powerpc/kernel/secboot.carch/powerpc/Kconfig +0
-0
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 916
Quoted 5 lines
arch/powerpc/Kconfig +2
-0@@ -912,6 +912,17 @@ config PPC_MEM_KEYS If unsure, say y. +config PPC_SECURE_BOOT + prompt "Enable PowerPC Secure Boot"
How about "Enable secure boot support"
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 918
Quoted 2 lines
arch/powerpc/Kconfig +2
-0+ bool + default n
The default is 'n', so you don't need that default line.
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 919
Quoted 1 line
arch/powerpc/Kconfig +1
-0+ depends on PPC64
Should it just depend on POWERNV for now? AFAIK there's nothing in here that's necessarily going to be shared with the guest secure boot code is there?
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 924
Quoted 5 lines
arch/powerpc/Kconfig +5
-0+ help + Linux on POWER with firmware secure boot enabled needs to define + security policies to extend secure boot to the OS.This config + allows user to enable OS Secure Boot on PowerPC systems that + have firmware secure boot support.
Again POWER vs PowerPC.
I think something like:
"Enable support for secure boot on some systems that have firmware support for it. If in doubt say N."
arch/powerpc/include/asm/secboot.h
Quoted 1 line
arch/powerpc/include/asm/secboot.h +0
-0
secure_boot.h would be fine.
arch/powerpc/include/asm/secboot.h line 6
Quoted 11 lines
new file mode 100644
index 000000000000..e726261bb00barch/powerpc/include/asm/secboot.h new file +6
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* PowerPC secure boot definitions +* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain <[email protected]>
I prefer to not have email addresses in copyright headers, as they just bit rot. Your email is in the git log.
arch/powerpc/include/asm/secboot.h line 10
Quoted 4 lines
arch/powerpc/include/asm/secboot.h new file +4
-0+* +*/ +#ifndef POWERPC_SECBOOT_H +#define POWERPC_SECBOOT_H
We usually do _ASM_POWERPC_SECBOOT_H (or _ASM_POWERPC_SECURE_BOOT_H).
arch/powerpc/include/asm/secboot.h line 14
Quoted 3 lines
arch/powerpc/include/asm/secboot.h new file +3
-0+#ifdef CONFIG_PPC_SECURE_BOOT +extern struct device_node *is_powerpc_secvar_supported (void ); +extern bool get_powerpc_secureboot (void );
You don't need 'extern' for functions in headers.
Quoted 32 lines
arch/powerpc/include/asm/secboot.h new file +13
-0+#else +static inline struct device_node *is_powerpc_secvar_supported (void ) +{ +return NULL ; +} + +static inline bool get_powerpc_secureboot (void ) +{ +return false; +} + +#endif +#endif arch/powerpc/kernel/Makefile +2
-0@@ -157,6 +157,8 @@ endif obj-$(CONFIG_EPAPR_PARAVIRT) += epapr_paravirt.o epapr_hcalls.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvm_emul.o +obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o + # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_prom_init.o := n KCOV_INSTRUMENT_prom_init.o := narch/powerpc/kernel/secboot.c new file +0
-0
arch/powerpc/kernel/secboot.c line 7
Quoted 7 lines
arch/powerpc/kernel/secboot.c new file +7
-0@@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain <[email protected]> +* +* secboot.c +* - util function to get powerpc secboot state
That's not really necessary.
arch/powerpc/kernel/secboot.c line 13
Quoted 6 lines
arch/powerpc/kernel/secboot.c new file +6
-0+*/ +#include <linux/types.h> +#include <linux/of.h> +#include <asm/secboot.h> + +struct device_node *is_powerpc_secvar_supported (void )
This is a pretty weird signature. The "is_" implies it will return a bool, but then it actually returns a device node *.
arch/powerpc/kernel/secboot.c line 22
Quoted 9 lines
arch/powerpc/kernel/secboot.c new file +9
-0+{ +struct device_node *np; +int status; + + np =of_find_node_by_name (NULL ,"ibm,secureboot" ); +if (!np) { +pr_info ("secureboot node is not found\n" ); +return NULL ; + }
There's no good reason to search by name. You should just search by compatible.
eg. of_find_compatible_node()
Quoted 12 lines
arch/powerpc/kernel/secboot.c new file +12
-0+ status =of_device_is_compatible (np,"ibm,secureboot-v3" ); +if (!status) { +pr_info ("Secure variables are not supported by this firmware\n" ); +return NULL ; + } + +return np; +} + +bool get_powerpc_secureboot (void ) +{ +struct device_node *np;
arch/powerpc/kernel/secboot.c line 45
Quoted 10 lines
arch/powerpc/kernel/secboot.c new file +10
-0+struct device_node *secvar_np; +const u64 *psecboot; +u64 secboot =0 ; + + np =is_powerpc_secvar_supported (); +if (!np) + goto disabled; + +/* Fail-safe for any failure related to secvar */ + secvar_np =of_get_child_by_name (np,"secvar" );
Finding a child by name is not ideal, it encodes the structure of the tree in the API. It's better to just search by compatible.
eg. of_find_compatible_node("ibm,secvar-v1")
You should also define what that means, ie. write a little snippet of doc to define what the expected properties are and their meaning and so on.
arch/powerpc/kernel/secboot.c line 47
Quoted 2 lines
arch/powerpc/kernel/secboot.c new file +2
-0+if (!secvar_np) { +pr_err ("Expected secure variables support, fail-safe\n" );
I'm a bit confused by this. This is the exact opposite of what I understand fail-safe to mean. We shouldn't tell the user the system is securely booted unless we're 100% sure it is. Right?
arch/powerpc/kernel/secboot.c line 54
Quoted 7 lines
arch/powerpc/kernel/secboot.c new file +7
-0+ goto enabled; + } + +if (!of_device_is_available (secvar_np)) { +pr_err ("Secure variables support is in error state, fail-safe\n" ); + goto enabled; + }
It seems a little weird to use the status property to indicate ok/error and then also have a "secure-mode" property. Wouldn't just "secure-mode" be sufficient with several states to represent what we need?
arch/powerpc/kernel/secboot.c line 58
Quoted 3 lines
arch/powerpc/kernel/secboot.c new file +3
-0+ psecboot =of_get_property (secvar_np,"secure-mode" ,NULL ); +if (!psecboot) + goto enabled;
Please use of_read_property_u64() or similar.
arch/powerpc/kernel/secboot.c line 61
Quoted 2 lines
arch/powerpc/kernel/secboot.c new file +2
-0+ secboot =be64_to_cpup ((__be64 *)psecboot); +if (!(secboot & (~0x0 )))
I'm not sure what that's trying to do.
arch/powerpc/kernel/secboot.c line 71
Quoted 11 lines
arch/powerpc/kernel/secboot.c new file +10
-0+ goto disabled; + +enabled: +pr_info ("secureboot mode enabled\n" ); +return true; + +disabled: +pr_info ("secureboot mode disabled\n" ); +return false; +}
cheers
Re: [PATCH v5 1/2] powerpc: detect the secure boot mode of the system
Quoted 1 line · Michael Ellerman
Hi Nayna,
Hi Michael,
Quoted 3 lines
Sorry I've taken so long to get to this series, there's just too many patches that need reviewing :/
No problem. I understand. Thanks for reviewing.
Quoted 7 lines
Quoted 2 lines · Nayna Jain
Secure boot on POWER defines different IMA policies based on the secure boot state of the system.
The terminology throughout is a bit vague, we have POWER, PowerPC, Linux on POWER etc.
Quoted 6 lines
What this patch is talking about is a particular implemention of secure boot on some OpenPOWER machines running bare metal - am I right?
So saying "Secure boot on POWER defines different IMA policies" is a bit broad I think. Really we've just decided that a way to implement secure boot is to use IMA policies.
I think the idea was to convey that the same design can be reused or extended as needed.
But I agree for now it is currently only OpenPOWER machines running on bare metal, I will fix the wordings to use "PowerNV" consistently.
Quoted 23 lines
Quoted 23 lines
This patch defines a function to detect the secure boot state of the system.
The
PPC_SECURE_BOOTconfig represents the base enablement of secureboot on POWER.Signed-off-by Nayna Jain <[email protected]>--- arch/powerpc/Kconfig | 11 +++++ arch/powerpc/include/asm/secboot.h | 27 ++++++++++++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/secboot.c | 71 ++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+)create mode 100644
arch/powerpc/include/asm/secboot.hcreate mode 100644arch/powerpc/kernel/secboot.carch/powerpc/Kconfig +0
-0@@ -912,6 +912,17 @@ config PPC_MEM_KEYS
Quoted 5 lines
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 916
Quoted 4 lines
arch/powerpc/Kconfig +2
-0If unsure, say y. +config PPC_SECURE_BOOT + prompt "Enable PowerPC Secure Boot"How about "Enable secure boot support"
Yes. Sounds better.
Quoted 4 lines
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 918
Quoted 3 lines
arch/powerpc/Kconfig +2
-0+ bool + default nThe default is 'n', so you don't need that default line.
Sure.
Quoted 5 lines
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 919
Quoted 2 lines
arch/powerpc/Kconfig +1
-0+ depends on PPC64Should it just depend on POWERNV for now? AFAIK there's nothing in here that's necessarily going to be shared with the guest secure boot code is there?
Yes. sounds good.
Quoted 8 lines
arch/powerpc/Kconfig config PPC_MEM_KEYS · line 924
Quoted 6 lines
arch/powerpc/Kconfig +5
-0+ help + Linux on POWER with firmware secure boot enabled needs to define + security policies to extend secure boot to the OS.This config + allows user to enable OS Secure Boot on PowerPC systems that + have firmware secure boot support.Again POWER vs PowerPC.
Quoted 4 lines
I think something like:
"Enable support for secure boot on some systems that have firmware support for it. If in doubt say N."
Sure.
Quoted 4 lines
arch/powerpc/include/asm/secboot.h
Quoted 3 lines
arch/powerpc/include/asm/secboot.h +0
-0
secure_boot.hwould be fine.
Sure.
Quoted 14 lines
arch/powerpc/include/asm/secboot.h line 6
Quoted 12 lines
new file mode 100644
index 000000000000..e726261bb00barch/powerpc/include/asm/secboot.h new file +6
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* PowerPC secure boot definitions +* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain <[email protected]> I prefer to not have email addresses in copyright headers, as they just bit rot. Your email is in the git log.
Sure.
Quoted 6 lines
arch/powerpc/include/asm/secboot.h line 10
Quoted 5 lines
arch/powerpc/include/asm/secboot.h new file +4
-0+* +*/ +#ifndef POWERPC_SECBOOT_H +#define POWERPC_SECBOOT_H We usually do
_ASM_POWERPC_SECBOOT_H(or_ASM_POWERPC_SECURE_BOOT_H).
Sure.
Quoted 5 lines
arch/powerpc/include/asm/secboot.h line 14
Quoted 4 lines
arch/powerpc/include/asm/secboot.h new file +3
-0+#ifdef CONFIG_PPC_SECURE_BOOT +extern struct device_node *is_powerpc_secvar_supported (void ); +extern bool get_powerpc_secureboot (void );You don't need 'extern' for functions in headers.
Yes. will fix.
Quoted 33 lines
Quoted 33 lines
arch/powerpc/include/asm/secboot.h new file +13
-0+#else +static inline struct device_node *is_powerpc_secvar_supported (void ) +{ +return NULL ; +} + +static inline bool get_powerpc_secureboot (void ) +{ +return false; +} + +#endif +#endif arch/powerpc/kernel/Makefile +2
-0@@ -157,6 +157,8 @@ endif obj-$(CONFIG_EPAPR_PARAVIRT) += epapr_paravirt.o epapr_hcalls.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvm_emul.o +obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o + # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_prom_init.o := n KCOV_INSTRUMENT_prom_init.o := narch/powerpc/kernel/secboot.c new file +0
-0@@ -0,0 +1,71 @@
Quoted 8 lines
arch/powerpc/kernel/secboot.c line 7
Quoted 7 lines
arch/powerpc/kernel/secboot.c new file +7
-0+// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain <[email protected]> +* +* secboot.c +* - util function to get powerpc secboot state That's not really necessary.
Sure.
Quoted 9 lines
arch/powerpc/kernel/secboot.c line 13
Quoted 7 lines
arch/powerpc/kernel/secboot.c new file +6
-0+*/ +#include <linux/types.h> +#include <linux/of.h> +#include <asm/secboot.h> + +struct device_node *is_powerpc_secvar_supported (void )This is a pretty weird signature. The "
is_" implies it will return a bool, but then it actually returns a device node *.
Yes. Agree. Will fix.
Quoted 12 lines
arch/powerpc/kernel/secboot.c line 22
Quoted 10 lines
arch/powerpc/kernel/secboot.c new file +9
-0+{ +struct device_node *np; +int status; + + np =of_find_node_by_name (NULL ,"ibm,secureboot" ); +if (!np) { +pr_info ("secureboot node is not found\n" ); +return NULL ; + }There's no good reason to search by name. You should just search by compatible.
Quoted 1 line
eg.
of_find_compatible_node()
Sure.
Quoted 26 lines
Quoted 13 lines
arch/powerpc/kernel/secboot.c new file +12
-0+ status =of_device_is_compatible (np,"ibm,secureboot-v3" ); +if (!status) { +pr_info ("Secure variables are not supported by this firmware\n" ); +return NULL ; + } + +return np; +} + +bool get_powerpc_secureboot (void ) +{ +struct device_node *np;arch/powerpc/kernel/secboot.c line 45
Quoted 10 lines
arch/powerpc/kernel/secboot.c new file +10
-0+struct device_node *secvar_np; +const u64 *psecboot; +u64 secboot =0 ; + + np =is_powerpc_secvar_supported (); +if (!np) + goto disabled; + +/* Fail-safe for any failure related to secvar */ + secvar_np =of_get_child_by_name (np,"secvar" );Finding a child by name is not ideal, it encodes the structure of the tree in the API. It's better to just search by compatible.
Quoted 5 lines
eg.
of_find_compatible_node("ibm,secvar-v1")You should also define what that means, ie. write a little snippet of doc to define what the expected properties are and their meaning and so on.
It is part of the skiboot patches (https://patchwork.ozlabs.org/patch/1157346/)
Sure. I will add one in the kernel as well.
Quoted 6 lines
arch/powerpc/kernel/secboot.c line 47
Quoted 3 lines
arch/powerpc/kernel/secboot.c new file +2
-0+if (!secvar_np) { +pr_err ("Expected secure variables support, fail-safe\n" );I'm a bit confused by this. This is the exact opposite of what I understand fail-safe to mean. We shouldn't tell the user the system is securely booted unless we're 100% sure it is. Right?
Yes. Thanks for pointing this out. "Fail secure" is the correct term. This is the situation where secure variables are supported. Any failure reading the secure variables may be an attack, so we fail securely.
Quoted 11 lines
arch/powerpc/kernel/secboot.c line 54
Quoted 8 lines
arch/powerpc/kernel/secboot.c new file +7
-0+ goto enabled; + } + +if (!of_device_is_available (secvar_np)) { +pr_err ("Secure variables support is in error state, fail-safe\n" ); + goto enabled; + }It seems a little weird to use the status property to indicate ok/error and then also have a "secure-mode" property. Wouldn't just "secure-mode" be sufficient with several states to represent what we need?
Before we check in which mode the system booted (e.g. setup, user, etc) using "secure mode" property, the "status" check helps to ensure that the system secure boot initialized correctly. We will look into combining the two variables.
Quoted 5 lines
arch/powerpc/kernel/secboot.c line 58
Quoted 4 lines
arch/powerpc/kernel/secboot.c new file +3
-0+ psecboot =of_get_property (secvar_np,"secure-mode" ,NULL ); +if (!psecboot) + goto enabled;Please use
of_read_property_u64()or similar.
Sure.
Quoted 4 lines
arch/powerpc/kernel/secboot.c line 61
Quoted 3 lines
arch/powerpc/kernel/secboot.c new file +2
-0+ secboot =be64_to_cpup ((__be64 *)psecboot); +if (!(secboot & (~0x0 )))I'm not sure what that's trying to do.
We are exposing secure modes from the skiboot to the kernel via a bitfield, partitioned into generic modes and backend specific modes. I will update this code so that it is clearer.
Thanks & Regards,
- Nayna
PATCH v5 2/2 powerpc: Add support to initialize ima policy rules
In reply to Nayna JainPOWER secure boot relies on the kernel IMA security subsystem to perform the OS kernel image signature verification. Since each secure boot mode has different IMA policy requirements, dynamic definition of the policy rules based on the runtime secure boot mode of the system is required. On systems that support secure boot, but have it disabled, only measurement policy rules of the kernel image and modules are defined.
This patch defines the arch-specific implementation to retrieve the secure boot mode of the system and accordingly configures the IMA policy rules.
This patch provides arch-specific IMA policies if PPC_SECURE_BOOT config is enabled.
--- arch/powerpc/Kconfig | 2 ++ arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/ima_arch.c | 50 ++++++++++++++++++++++++++++++++++ include/linux/ima.h | 3 +- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/kernel/ima_arch.c
arch/powerpc/Kconfig +2 -0
@@ -917,6 +917,8 @@ config PPC_SECURE_BOOT bool default n depends on PPC64 + depends on IMA + depends on IMA_ARCH_POLICY help Linux on POWER with firmware secure boot enabled needs to define security policies to extend secure boot to the OS.This config
arch/powerpc/kernel/Makefile +1 -1
@@ -157,7 +157,7 @@ endif obj-$(CONFIG_EPAPR_PARAVIRT) += epapr_paravirt.o epapr_hcalls.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvm_emul.o -obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o +obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o ima_arch.o # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_prom_init.o := n
arch/powerpc/kernel/ima_arch.c new file +50 -0
50 lines not on this page · raw message
include/linux/ima.h +2 -1
@@ -29,7 +29,8 @@ extern void ima_kexec_cmdline(const void *buf, int size);extern void ima_add_kexec_buffer (struct kimage *image);#endif -#if (defined(CONFIG_X86 ) && defined(CONFIG_EFI )) || defined(CONFIG_S390 ) +#if (defined(CONFIG_X86 ) && defined(CONFIG_EFI )) || defined(CONFIG_S390 ) \ + || defined(CONFIG_PPC_SECURE_BOOT )extern bool arch_ima_get_secureboot (void );extern const char *const *arch_get_ima_policy (void );#else
Signature · 1 line
2.20.1
Michael Ellerman
reviewerRe: [PATCH v5 2/2] powerpc: Add support to initialize ima policy rules
Hi Nayna,
Some more comments below.
Quoted 2 lines · Nayna Jain
POWER secure boot relies on the kernel IMA security subsystem to perform the OS kernel image signature verification.
Again this is just a design choice we've made, it's not specified anywhere or anything like that. And it only applies to bare metal secure boot, at least so far. AIUI.
Quoted 6 lines
Since each secure
boot mode has different IMA policy requirements, dynamic definition of the policy rules based on the runtime secure boot mode of the system is required. On systems that support secure boot, but have it disabled, only measurement policy rules of the kernel image and modules are defined.
It's probably worth mentioning that we intend to use this in our Linux-based boot loader, which uses kexec, and that's one of the reasons why we're particularly interested in defining the rules for kexec?
Quoted 63 lines
This patch defines the arch-specific implementation to retrieve the secure boot mode of the system and accordingly configures the IMA policy rules.
This patch provides arch-specific IMA policies if
PPC_SECURE_BOOTconfig is enabled.Signed-off-by Nayna Jain <[email protected]>--- arch/powerpc/Kconfig | 2 ++ arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/ima_arch.c | 50 ++++++++++++++++++++++++++++++++++ include/linux/ima.h | 3 +- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/kernel/ima_arch.carch/powerpc/Kconfig +2
-0@@ -917,6 +917,8 @@ config PPC_SECURE_BOOT bool default n depends on PPC64 + depends on IMA + depends on IMA_ARCH_POLICY help Linux on POWER with firmware secure boot enabled needs to define security policies to extend secure boot to the OS.This configarch/powerpc/kernel/Makefile +1
-1@@ -157,7 +157,7 @@ endif obj-$(CONFIG_EPAPR_PARAVIRT) += epapr_paravirt.o epapr_hcalls.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvm_emul.o -obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o +obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o ima_arch.o # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_prom_init.o := narch/powerpc/kernel/ima_arch.c new file +15
-0@@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain <[email protected]> +* +* ima_arch.c +* - initialize ima policies for PowerPC Secure Boot +*/ + +#include <linux/ima.h> +#include <asm/secboot.h> + +bool arch_ima_get_secureboot (void ) +{ +return get_powerpc_secureboot ();
arch/powerpc/kernel/ima_arch.c line 25
Quoted 10 lines
arch/powerpc/kernel/ima_arch.c new file +10
-0+} + +/* +* File signature verification is not needed, include only measurements +*/ +static const char *const default_arch_rules[] = { +"measure func=KEXEC_KERNEL_CHECK" , +"measure func=MODULE_CHECK" , +NULL +};
The rules above seem fairly self explanatory.
arch/powerpc/kernel/ima_arch.c line 36
Quoted 11 lines
arch/powerpc/kernel/ima_arch.c new file +11
-0+ +/* Both file signature verification and measurements are needed */ +static const char *const sb_arch_rules[] = { +"measure func=KEXEC_KERNEL_CHECK template=ima-modsig" , +"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +#if IS_ENABLED(CONFIG_MODULE_SIG) +"measure func=MODULE_CHECK" , +#else +"measure func=MODULE_CHECK template=ima-modsig" , +"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +#endif
But these ones are not so obvious, at least to me who knows very little about IMA.
Can you add a one line comment to each of the ones in here saying what it does and why we want it?
arch/powerpc/kernel/ima_arch.c
Quoted 6 lines
arch/powerpc/kernel/ima_arch.c new file +6
-0+ NULL +}; + +/* +* On PowerPC, file measurements are to be added to the IMA measurement list +* irrespective of the secure boot state of the system.
Why? Just because we think it's useful? Would be good to provide some further justification.
* Signature verification
Quoted 13 lines
arch/powerpc/kernel/ima_arch.c new file +8
-0+* is conditionally enabled based on the secure boot state. +*/ +const char *const *arch_get_ima_policy (void ) +{ +if (IS_ENABLED (CONFIG_IMA_ARCH_POLICY ) &&arch_ima_get_secureboot ()) +return sb_arch_rules; +return default_arch_rules; +}include/linux/ima.h +0
-0
include/linux/ima.h extern void ima_kexec_cmdline(const void *buf, int size); · line 36
Quoted 9 lines
include/linux/ima.h +2
-1@@ -29,7 +29,8 @@ extern void ima_kexec_cmdline(const void *buf, int size);extern void ima_add_kexec_buffer (struct kimage *image);#endif -#if (defined(CONFIG_X86 ) && defined(CONFIG_EFI )) || defined(CONFIG_S390 ) +#if (defined(CONFIG_X86 ) && defined(CONFIG_EFI )) || defined(CONFIG_S390 ) \ + || defined(CONFIG_PPC_SECURE_BOOT )extern bool arch_ima_get_secureboot (void );extern const char *const *arch_get_ima_policy (void );#else
cheers
Re: [PATCH v5 2/2] powerpc: Add support to initialize ima policy rules
Quoted 1 line · Michael Ellerman
Hi Nayna,
Hi Michael,
Quoted 9 lines
Some more comments below.
Quoted 2 lines · Nayna Jain
POWER secure boot relies on the kernel IMA security subsystem to perform the OS kernel image signature verification.
Again this is just a design choice we've made, it's not specified anywhere or anything like that. And it only applies to bare metal secure boot, at least so far. AIUI.
Yes. I will make it consistent to use "PowerNV".
Quoted 9 lines
Quoted 6 lines
Since each secure
boot mode has different IMA policy requirements, dynamic definition of the policy rules based on the runtime secure boot mode of the system is required. On systems that support secure boot, but have it disabled, only measurement policy rules of the kernel image and modules are defined.It's probably worth mentioning that we intend to use this in our Linux-based boot loader, which uses kexec, and that's one of the reasons why we're particularly interested in defining the rules for kexec?
Yes. Agreed. I will update patch description to add this.
Quoted 90 lines
Quoted 64 lines
This patch defines the arch-specific implementation to retrieve the secure boot mode of the system and accordingly configures the IMA policy rules.
This patch provides arch-specific IMA policies if
PPC_SECURE_BOOTconfig is enabled.Signed-off-by Nayna Jain <[email protected]>--- arch/powerpc/Kconfig | 2 ++ arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/ima_arch.c | 50 ++++++++++++++++++++++++++++++++++ include/linux/ima.h | 3 +- 4 files changed, 55 insertions(+), 2 deletions(-)create mode 100644
arch/powerpc/kernel/ima_arch.carch/powerpc/Kconfig +2
-0@@ -917,6 +917,8 @@ config PPC_SECURE_BOOT bool default n depends on PPC64 + depends on IMA + depends on IMA_ARCH_POLICY help Linux on POWER with firmware secure boot enabled needs to define security policies to extend secure boot to the OS.This configarch/powerpc/kernel/Makefile +1
-1@@ -157,7 +157,7 @@ endif obj-$(CONFIG_EPAPR_PARAVIRT) += epapr_paravirt.o epapr_hcalls.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvm_emul.o -obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o +obj-$(CONFIG_PPC_SECURE_BOOT) += secboot.o ima_arch.o # Disable GCOV, KCOV & sanitizers in odd or sensitive code GCOV_PROFILE_prom_init.o := narch/powerpc/kernel/ima_arch.c new file +15
-0@@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain <[email protected]> +* +* ima_arch.c +* - initialize ima policies for PowerPC Secure Boot +*/ + +#include <linux/ima.h> +#include <asm/secboot.h> + +bool arch_ima_get_secureboot (void ) +{ +return get_powerpc_secureboot ();arch/powerpc/kernel/ima_arch.c line 25
Quoted 10 lines
arch/powerpc/kernel/ima_arch.c new file +10
-0+} + +/* +* File signature verification is not needed, include only measurements +*/ +static const char *const default_arch_rules[] = { +"measure func=KEXEC_KERNEL_CHECK" , +"measure func=MODULE_CHECK" , +NULL +};The rules above seem fairly self explanatory.
arch/powerpc/kernel/ima_arch.c line 36
Quoted 11 lines
arch/powerpc/kernel/ima_arch.c new file +11
-0+ +/* Both file signature verification and measurements are needed */ +static const char *const sb_arch_rules[] = { +"measure func=KEXEC_KERNEL_CHECK template=ima-modsig" , +"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +#if IS_ENABLED(CONFIG_MODULE_SIG) +"measure func=MODULE_CHECK" , +#else +"measure func=MODULE_CHECK template=ima-modsig" , +"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +#endifBut these ones are not so obvious, at least to me who knows very little about IMA.
Quoted 2 lines
Can you add a one line comment to each of the ones in here saying what it does and why we want it?
Sure.
Quoted 9 lines
arch/powerpc/kernel/ima_arch.c
Quoted 7 lines
arch/powerpc/kernel/ima_arch.c new file +6
-0+ NULL +}; + +/* +* On PowerPC, file measurements are to be added to the IMA measurement list +* irrespective of the secure boot state of the system. Why? Just because we think it's useful? Would be good to provide some further justification.
Sure. I will clarify this in the next version.
Thanks & Regards,
- Nayna