powerpc: Enabling IMA arch specific secure boot policies
Subsystems (3)
v4 cover powerpc: Enabling IMA arch specific secure boot policies
This patch set, previously named "powerpc: Enabling secure boot on powernv systems - Part 1", is part of a series that implements secure boot on PowerNV systems.
In order to verify the OS kernel on PowerNV, secure boot requires X.509 certificates trusted by the platform, the secure boot modes, and several other pieces of information. These are stored in secure variables controlled by OPAL, also known as OPAL secure variables.
The IMA architecture specific policy support on POWER is dependent on OPAL runtime services to access secure variables. OPAL APIs in skiboot are modified to define generic interface compatible to any backend. This patchset is consequently updated to be compatible with new OPAL API interface. This has cleaned up any EFIsms in the arch specific code. Further, the ima arch specific policies are updated to be able to support appended signatures. They also now use per policy template.
Exposing the OPAL secure variables to userspace will be posted as a separate patch set, allowing the IMA architecture specific policy on POWER to be upstreamed independently.
This patch set adds the following features:
1. Add support for OPAL Runtime API to access secure variables controlled by OPAL.
2. Define IMA arch-specific policies based on the secure boot state and mode of the system. On secure boot enabled PowerNV systems, the OS kernel signature will be verified by IMA appraisal.
Pre-requisites for this patchset are:
1. OPAL APIs in Skiboot[1]
2. Appended signature support in IMA [2]
3. Per policy template support in IMA [3]
[1] https://patchwork.ozlabs.org/project/skiboot/list/?series=112868
[2] https://patchwork.ozlabs.org/cover/1087361/. Updated version will be posted soon
[3] Repo: https://kernel.googlesource.com/pub/scm/linux/kernel/git/zohar/linux-integrity
Branch: next-queued-testing. Commit: f241bb1f42aa95
----------------------------------------------------------------------------------
Original Cover Letter:
This patch set is part of a series that implements secure boot on PowerNV systems.
In order to verify the OS kernel on PowerNV, secure boot requires X.509 certificates trusted by the platform, the secure boot modes, and several other pieces of information. These are stored in secure variables controlled by OPAL, also known as OPAL secure variables.
The IMA architecture specific policy support on Power is dependent on OPAL runtime services to access secure variables. Instead of directly accessing the OPAL runtime services, version 3 of this patch set relied upon the EFI hooks. This version drops that dependency and calls the OPAL runtime services directly. Skiboot OPAL APIs are due to be posted soon.
Exposing the OPAL secure variables to userspace will be posted as a separate patch set, allowing the IMA architecture specific policy on Power to be upstreamed independently.
This patch set adds the following features:
1. Add support for OPAL Runtime API to access secure variables controlled by OPAL.
2. Define IMA arch-specific policies based on the secure boot state and mode of the system. On secure boot enabled powernv systems, the OS kernel signature will be verified by IMA appraisal.
[1] https://patchwork.kernel.org/cover/10882149/
Changelog:
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
Claudio Carvalho (1):
powerpc/powernv: Add OPAL API interface to get secureboot state
Nayna Jain (2):
powerpc/powernv: detect the secure boot mode of the system
powerpc: Add support to initialize ima policy rules
arch/powerpc/Kconfig | 14 ++++ arch/powerpc/include/asm/opal-api.h | 4 +- arch/powerpc/include/asm/opal-secvar.h | 23 ++++++ arch/powerpc/include/asm/opal.h | 6 ++ arch/powerpc/include/asm/secboot.h | 21 +++++ arch/powerpc/kernel/Makefile | 1 + arch/powerpc/kernel/ima_arch.c | 54 +++++++++++++ arch/powerpc/platforms/powernv/Kconfig | 6 ++ arch/powerpc/platforms/powernv/Makefile | 1 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/opal-secvar.c | 85 ++++++++++++++++++++ arch/powerpc/platforms/powernv/secboot.c | 61 ++++++++++++++ include/linux/ima.h | 3 +- 13 files changed, 279 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/include/asm/opal-secvar.h create mode 100644 arch/powerpc/include/asm/secboot.h create mode 100644 arch/powerpc/kernel/ima_arch.c create mode 100644 arch/powerpc/platforms/powernv/opal-secvar.c create mode 100644 arch/powerpc/platforms/powernv/secboot.c
Signature · 1 line
2.20.1
PATCH v4 1/3 powerpc/powernv: Add OPAL API interface to get secureboot state
From: Claudio Carvalho <[email protected]>
The X.509 certificates trusted by the platform and other information required to secure boot the OS kernel are wrapped in secure variables, which are controlled by OPAL.
This patch adds support to read OPAL secure variables through OPAL_SECVAR_GET call. It returns the metadata and data for a given secure variable based on the unique key.
Since OPAL can support different types of backend which can vary in the variable interpretation, a new OPAL API call named OPAL_SECVAR_BACKEND, is added to retrieve the supported backend version. This helps the consumer to know how to interpret the variable.
This support can be enabled using CONFIG_OPAL_SECVAR
---
This patch depends on a new OPAL call that is being added to skiboot. The patch set that implements the new call has been posted to
https://patchwork.ozlabs.org/project/skiboot/list/?series=112868
arch/powerpc/include/asm/opal-api.h | 4 +- arch/powerpc/include/asm/opal-secvar.h | 23 ++++++ arch/powerpc/include/asm/opal.h | 6 ++ arch/powerpc/platforms/powernv/Kconfig | 6 ++ arch/powerpc/platforms/powernv/Makefile | 1 + arch/powerpc/platforms/powernv/opal-call.c | 2 + arch/powerpc/platforms/powernv/opal-secvar.c | 85 ++++++++++++++++++++ 7 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/opal-secvar.h create mode 100644 arch/powerpc/platforms/powernv/opal-secvar.c
arch/powerpc/include/asm/opal-api.h +3 -1
@@ -212,7 +212,9 @@#define OPAL_HANDLE_HMI2 166#define OPAL_NX_COPROC_INIT 167#define OPAL_XIVE_GET_VP_STATE 170 -#define OPAL_LAST 170 +#define OPAL_SECVAR_GET 173 +#define OPAL_SECVAR_BACKEND 177 +#define OPAL_LAST 177#define QUIESCE_HOLD 1/* Spin all calls at entry */ #define QUIESCE_REJECT 2/* Fail all calls with OPAL_BUSY */
arch/powerpc/include/asm/opal-secvar.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* PowerNV definitions for secure variables OPAL API. +* +* Copyright (C) 2019 IBM Corporation +* Author: Claudio Carvalho <[email protected]> +* +*/ +#ifndef OPAL_SECVAR_H +#define OPAL_SECVAR_H + +enum { +BACKEND_NONE =0 , +BACKEND_TC_COMPAT_V1 , +}; + +extern int opal_get_variable (u8 *key,unsigned long ksize, +u8 *metadata,unsigned long *mdsize, +u8 *data,unsigned long *dsize); + +extern int opal_variable_version (unsigned long *backend); + +#endif
arch/powerpc/include/asm/opal.h +6 -0
@@ -394,6 +394,12 @@ void opal_powercap_init(void);void opal_psr_init (void );void opal_sensor_groups_init (void ); +extern int opal_secvar_get (uint64_t k_key,uint64_t k_key_len, +uint64_t k_metadata,uint64_t k_metadata_size, +uint64_t k_data,uint64_t k_data_size); + +extern int opal_secvar_backend (uint64_t k_backend); +#endif /* __ASSEMBLY__ */ #endif /* _ASM_POWERPC_OPAL_H */
arch/powerpc/platforms/powernv/Kconfig +6 -0
@@ -47,3 +47,9 @@ config PPC_VAS VAS adapters are found in POWER9 based systems. If unsure, say N. + +config OPAL_SECVAR + bool "OPAL Secure Variables" + depends on PPC_POWERNV + help + This enables the kernel to access OPAL secure variables.
arch/powerpc/platforms/powernv/Makefile +1 -0
@@ -16,3 +16,4 @@ obj-$(CONFIG_PERF_EVENTS) += opal-imc.o obj-$(CONFIG_PPC_MEMTRACE) += memtrace.o obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o obj-$(CONFIG_OCXL_BASE) += ocxl.o +obj-$(CONFIG_OPAL_SECVAR) += opal-secvar.o
arch/powerpc/platforms/powernv/opal-call.c +2 -0
@@ -288,3 +288,5 @@ OPAL_CALL(opal_pci_set_pbcq_tunnel_bar, OPAL_PCI_SET_PBCQ_TUNNEL_BAR);OPAL_CALL (opal_sensor_read_u64,OPAL_SENSOR_READ_U64 );OPAL_CALL (opal_sensor_group_enable,OPAL_SENSOR_GROUP_ENABLE );OPAL_CALL (opal_nx_coproc_init,OPAL_NX_COPROC_INIT ); +OPAL_CALL (opal_secvar_get,OPAL_SECVAR_GET ); +OPAL_CALL (opal_secvar_backend,OPAL_SECVAR_BACKEND );
arch/powerpc/platforms/powernv/opal-secvar.c new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 2/3 powerpc/powernv: detect the secure boot mode of the system
In reply to Nayna JainPowerNV secure boot 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.
--- arch/powerpc/include/asm/secboot.h | 21 ++++++++ arch/powerpc/platforms/powernv/Makefile | 2 +- arch/powerpc/platforms/powernv/secboot.c | 61 ++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/include/asm/secboot.h create mode 100644 arch/powerpc/platforms/powernv/secboot.c
arch/powerpc/include/asm/secboot.h new file +21 -0
@@ -0,0 +1,21 @@ +/* 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 + +#if defined(CONFIG_OPAL_SECVAR ) +extern bool get_powerpc_sb_mode (void ); +#else +static inline bool get_powerpc_sb_mode (void ) +{ +return false; +} +#endif + +#endif
arch/powerpc/platforms/powernv/Makefile +1 -1
@@ -16,4 +16,4 @@ obj-$(CONFIG_PERF_EVENTS) += opal-imc.o obj-$(CONFIG_PPC_MEMTRACE) += memtrace.o obj-$(CONFIG_PPC_VAS) += vas.o vas-window.o vas-debug.o obj-$(CONFIG_OCXL_BASE) += ocxl.o -obj-$(CONFIG_OPAL_SECVAR) += opal-secvar.o +obj-$(CONFIG_OPAL_SECVAR) += opal-secvar.o secboot.o
arch/powerpc/platforms/powernv/secboot.c new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 3/3 powerpc: Add support to initialize ima policy rules
In reply to Nayna JainPowerNV 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 | 14 +++++++++ arch/powerpc/kernel/Makefile | 1 + arch/powerpc/kernel/ima_arch.c | 54 ++++++++++++++++++++++++++++++++++ include/linux/ima.h | 3 +- 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/kernel/ima_arch.c
arch/powerpc/Kconfig +14 -0
@@ -902,6 +902,20 @@ config PPC_MEM_KEYS If unsure, say y. +config PPC_SECURE_BOOT + prompt "Enable PowerPC Secure Boot" + bool + default n + depends on PPC64 + depends on OPAL_SECVAR + 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 + allows user to enable OS Secure Boot on PowerPC systems that + have firmware secure boot support. + endmenu config ISA_DMA_API
arch/powerpc/kernel/Makefile +1 -0
@@ -131,6 +131,7 @@ ifdef CONFIG_IMA obj-y += ima_kexec.o endif endif +obj-$(CONFIG_PPC_SECURE_BOOT) += ima_arch.o obj-$(CONFIG_AUDIT) += audit.o obj64-$(CONFIG_AUDIT) += compat_audit.o
arch/powerpc/kernel/ima_arch.c new file +54 -0
54 lines not on this page · raw message
include/linux/ima.h +2 -1
@@ -31,7 +31,8 @@ extern void ima_post_path_mknod(struct dentry *dentry);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