powerpc: Enabling IMA arch specific secure boot policies
Subsystems (8)
v8 cover powerpc: Enabling IMA arch specific secure boot policies
This patchset extends the previous version[1] by adding support for checking against a blacklist of binary hashes.
The IMA subsystem supports custom, built-in, arch-specific policies to define the files to be measured and appraised. These policies are honored based on priority, where arch-specific policy is the highest and custom is the lowest.
PowerNV system uses a Linux-based bootloader to kexec the OS. The bootloader kernel relies on IMA for signature verification of the OS kernel before doing the kexec. This patchset adds support for powerpc arch-specific IMA policies that are conditionally defined based on a system's secure boot and trusted boot states. The OS secure boot and trusted boot states are determined via device-tree properties.
The verification needs to be performed only for binaries that are not blacklisted. The kernel currently only checks against the blacklist of keys. However, doing so results in blacklisting all the binaries that are signed by the same key. In order to prevent just one particular binary from being loaded, it must be checked against a blacklist of binary hashes. This patchset also adds support to IMA for checking against a hash blacklist for files. signed by appended signature.
[1] http://patchwork.ozlabs.org/cover/1149262/
Changelog:
v8:
* Updates the Patch Description as per Michael's and Mimi's feedback
* Includes feedbacks from Michael for the device tree and policies
* removes the arch-policy hack by defining three arrays.
* fixes related to device-tree calls
* other code specific feedbacks
* Includes feedbacks from Mimi on the blacklist
* generic blacklist function is modified than previous version
* other coding fixes
v7:
* Removes patch related to dt-bindings as per input from Rob Herring.
* fixes Patch 1/8 to use new device-tree updates as per Oliver feedback to device-tree documentation in skiboot mailing list.
(https://lists.ozlabs.org/pipermail/skiboot/2019-September/015329.html)
* Includes feedbacks from Mimi, Thiago
* moves function get_powerpc_fw_sb_node() from Patch 1 to Patch 3
* fixes Patch 2/8 to use CONFIG_MODULE_SIG_FORCE.
* updates Patch description in Patch 5/8
* adds a new patch to add wrapper is_binary_blacklisted()
* removes the patch that deprecated permit_directio
v6:
* includes feedbacks from Michael Ellerman on the patchset v5
* removed email ids from comments
* add the doc for the device-tree
* renames the secboot.c to secure_boot.c and secboot.h to secure_boot.h
* other code specific fixes
* split the patches to differentiate between secureboot and trustedboot state of the system
* adds the patches to support the blacklisting of the binary hash.
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 (8):
powerpc: detect the secure boot mode of the system powerpc/ima: add support to initialize ima policy rules
powerpc: detect the trusted boot state of the system powerpc/ima: add measurement rules to ima arch specific policy
ima: make process_buffer_measurement() generic
certs: add wrapper function to check blacklisted binary hash
ima: check against blacklisted hashes for files with modsig powerpc/ima: update ima arch policy to check for blacklist
Documentation/ABI/testing/ima_policy | 1 + arch/powerpc/Kconfig | 11 ++++ arch/powerpc/include/asm/secure_boot.h | 29 +++++++++++ arch/powerpc/kernel/Makefile | 2 + arch/powerpc/kernel/ima_arch.c | 71 ++++++++++++++++++++++++++ arch/powerpc/kernel/secure_boot.c | 54 ++++++++++++++++++++ certs/blacklist.c | 9 ++++ include/keys/system_keyring.h | 6 +++ include/linux/ima.h | 3 +- security/integrity/ima/ima.h | 11 ++++ security/integrity/ima/ima_appraise.c | 31 +++++++++++ security/integrity/ima/ima_main.c | 63 +++++++++++++++-------- security/integrity/ima/ima_policy.c | 10 +++- security/integrity/integrity.h | 1 + 14 files changed, 277 insertions(+), 25 deletions(-) create mode 100644 arch/powerpc/include/asm/secure_boot.h create mode 100644 arch/powerpc/kernel/ima_arch.c create mode 100644 arch/powerpc/kernel/secure_boot.c
Signature · 1 line
2.20.1
PATCH v8 1/8 powerpc: detect the secure boot mode of the system
This patch defines a function to detect the secure boot state of a PowerNV system.
The PPC_SECURE_BOOT config represents the base enablement of secure boot for powerpc.
--- arch/powerpc/Kconfig | 10 +++++++++ arch/powerpc/include/asm/secure_boot.h | 23 ++++++++++++++++++++ arch/powerpc/kernel/Makefile | 2 ++ arch/powerpc/kernel/secure_boot.c | 30 ++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 arch/powerpc/include/asm/secure_boot.h create mode 100644 arch/powerpc/kernel/secure_boot.c
arch/powerpc/Kconfig +10 -0
@@ -934,6 +934,16 @@ config PPC_MEM_KEYS If unsure, say y. +config PPC_SECURE_BOOT + prompt "Enable secure boot support" + bool + depends on PPC_POWERNV + help + Systems with firmware secure boot enabled need to define security + policies to extend secure boot to the OS. This config allows a user + to enable OS secure boot on systems that have firmware support for + it. If in doubt say N. + endmenu config ISA_DMA_API
arch/powerpc/include/asm/secure_boot.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Secure boot definitions +* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain +*/ +#ifndef _ASM_POWER_SECURE_BOOT_H +#define _ASM_POWER_SECURE_BOOT_H + +#ifdef CONFIG_PPC_SECURE_BOOT + +bool is_ppc_secureboot_enabled (void ); + +#else + +static inline bool is_ppc_secureboot_enabled (void ) +{ +return false; +} + +#endif +#endif
arch/powerpc/kernel/Makefile +2 -0
@@ -161,6 +161,8 @@ ifneq ($(CONFIG_PPC_POWERNV)$(CONFIG_PPC_SVM),) obj-y += ucall.o endif +obj-$(CONFIG_PPC_SECURE_BOOT) += secure_boot.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/secure_boot.c new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain +*/ +#include <linux/types.h> +#include <linux/of.h> +#include <asm/secure_boot.h> + +bool is_ppc_secureboot_enabled (void ) +{ +struct device_node *node; +bool enabled = false; + + node =of_find_compatible_node (NULL ,NULL ,"ibm,secvar-v1" ); +if (!of_device_is_available (node)) { +pr_err ("Cannot find secure variable node in device tree; failing to secure state\n" ); + goto out; + } + +/* +* secureboot is enabled if os-secure-enforcing property exists, +* else disabled. +*/ + enabled =of_property_read_bool (node,"os-secure-enforcing" ); + +out: +pr_info ("Secure boot mode %s\n" , enabled ?"enabled" :"disabled" ); +return enabled; +}
Signature · 1 line
2.20.1
Michael Ellerman
reviewerRe: [PATCH v8 1/8] powerpc: detect the secure boot mode of the system
Quoted 11 lines · Nayna Jain
arch/powerpc/kernel/secure_boot.c new file +5
-0@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain +*/
arch/powerpc/kernel/secure_boot.c line 15
Quoted 10 lines
arch/powerpc/kernel/secure_boot.c new file +10
-0+#include <linux/types.h> +#include <linux/of.h> +#include <asm/secure_boot.h> + +bool is_ppc_secureboot_enabled (void ) +{ +struct device_node *node; +bool enabled = false; + + node =of_find_compatible_node (NULL ,NULL ,"ibm,secvar-v1" );
If this found a node then you have a node with an elevated refcount which you need to drop on the way out.
arch/powerpc/kernel/secure_boot.c line 27
Quoted 12 lines
arch/powerpc/kernel/secure_boot.c new file +12
-0+if (!of_device_is_available (node)) { +pr_err ("Cannot find secure variable node in device tree; failing to secure state\n" ); + goto out; + } + +/* +* secureboot is enabled if os-secure-enforcing property exists, +* else disabled. +*/ + enabled =of_property_read_bool (node,"os-secure-enforcing" ); + +out:
So here you need:
of_node_put(node);
arch/powerpc/kernel/secure_boot.c line 30
Quoted 3 lines
arch/powerpc/kernel/secure_boot.c new file +3
-0+pr_info ("Secure boot mode %s\n" , enabled ?"enabled" :"disabled" ); +return enabled; +}
cheers
PATCH v8 2/8 powerpc/ima: add support to initialize ima policy rules
In reply to Nayna JainPowerNV system use a Linux-based bootloader, which relies on the IMA subsystem to enforce different secure boot modes. Since the verification policy may differ based on the secure boot mode of the system, the policies must be defined at runtime.
This patch implements arch-specific support to define IMA policy rules based on the runtime secure boot mode of the system.
This patch provides arch-specific IMA policies if PPC_SECURE_BOOT config is enabled.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/ima_arch.c | 39 ++++++++++++++++++++++++++++++++++ include/linux/ima.h | 3 ++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/kernel/ima_arch.c
arch/powerpc/Kconfig +1 -0
@@ -938,6 +938,7 @@ config PPC_SECURE_BOOT prompt "Enable secure boot support" bool depends on PPC_POWERNV + depends on IMA_ARCH_POLICY help Systems with firmware secure boot enabled need to define security policies to extend secure boot to the OS. This config allows a user
arch/powerpc/kernel/Makefile +1 -1
@@ -161,7 +161,7 @@ ifneq ($(CONFIG_PPC_POWERNV)$(CONFIG_PPC_SVM),) obj-y += ucall.o endif -obj-$(CONFIG_PPC_SECURE_BOOT) += secure_boot.o +obj-$(CONFIG_PPC_SECURE_BOOT) += secure_boot.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 +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain +*/ + +#include <linux/ima.h> +#include <asm/secure_boot.h> + +bool arch_ima_get_secureboot (void ) +{ +return is_ppc_secureboot_enabled (); +} + +/* +* The "secure_rules" are enabled only on "secureboot" enabled systems. +* These rules verify the file signatures against known good values. +* The "appraise_type=imasig|modsig" option allows the known good signature +* to be stored as an xattr or as an appended signature. +*/ +static const char *const secure_rules[] = { +"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +#ifndef CONFIG_MODULE_SIG_FORCE +"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +#endif +NULL +}; + +/* +* Returns the relevant IMA arch-specific policies based on the system secure +* boot state. +*/ +const char *const *arch_get_ima_policy (void ) +{ +if (is_ppc_secureboot_enabled ()) +return secure_rules; + +return NULL ; +}
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
Mimi Zohar
maintainerRe: [PATCH v8 2/8] powerpc/ima: add support to initialize ima policy rules
Quoted 13 lines · Nayna Jain
index 000000000000..65d82ee74ea4
arch/powerpc/kernel/ima_arch.c new file +9
-0@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 IBM Corporation +* Author: Nayna Jain +*/ + +#include <linux/ima.h> +#include <asm/secure_boot.h> +
arch/powerpc/kernel/ima_arch.c line 19
Quoted 10 lines
arch/powerpc/kernel/ima_arch.c new file +10
-0+bool arch_ima_get_secureboot (void ) +{ +return is_ppc_secureboot_enabled (); +} + +/* +* The "secure_rules" are enabled only on "secureboot" enabled systems. +* These rules verify the file signatures against known good values. +* The "appraise_type=imasig|modsig" option allows the known good signature +* to be stored as an xattr or as an appended signature.
Please add another sentence or two as a separate paragraph with an explanation why the kernel module rule is conditional (eg. Only verify the appended kernel module signatures once.)
arch/powerpc/kernel/ima_arch.c line 28
Quoted 9 lines
arch/powerpc/kernel/ima_arch.c new file +9
-0+*/ +static const char *const secure_rules[] = { +"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +#ifndef CONFIG_MODULE_SIG_FORCE +"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +#endif +NULL +}; +
Mimi
PATCH v8 3/8 powerpc: detect the trusted boot state of the system
In reply to Nayna JainWhile secure boot permits only properly verified signed kernels to be booted, trusted boot takes a measurement of the kernel image prior to boot that can be subsequently compared against good known values via attestation services.
This patch reads the trusted boot state of a PowerNV system. The state is used to conditionally enable additional measurement rules in the IMA arch-specific policies.
--- arch/powerpc/include/asm/secure_boot.h | 6 ++++++ arch/powerpc/kernel/secure_boot.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+)
arch/powerpc/include/asm/secure_boot.h +6 -0
@@ -11,6 +11,7 @@#ifdef CONFIG_PPC_SECURE_BOOT bool is_ppc_secureboot_enabled (void ); +bool is_ppc_trustedboot_enabled (void );#else
@@ -19,5 +20,10 @@ static inline bool is_ppc_secureboot_enabled(void)return false; } +static inline bool is_ppc_trustedboot_enabled (void ) +{ +return false; +} +#endif #endif
arch/powerpc/kernel/secure_boot.c +24 -0
@@ -7,6 +7,17 @@#include <linux/of.h> #include <asm/secure_boot.h> +static struct device_node *get_ppc_fw_sb_node (void ) +{ +static const struct of_device_id ids[] = { + { .compatible ="ibm,secureboot-v1" , }, + { .compatible ="ibm,secureboot-v2" , }, + {}, + }; + +return of_find_matching_node (NULL , ids); +} +bool is_ppc_secureboot_enabled (void ) {struct device_node *node;
@@ -28,3 +39,16 @@ bool is_ppc_secureboot_enabled(void)pr_info ("Secure boot mode %s\n" , enabled ?"enabled" :"disabled" );return enabled; } + +bool is_ppc_trustedboot_enabled (void ) +{ +struct device_node *node; +bool enabled = false; + + node =get_ppc_fw_sb_node (); + enabled =of_property_read_bool (node,"trusted-enabled" ); + +pr_info ("Trusted boot mode %s\n" , enabled ?"enabled" :"disabled" ); + +return enabled; +}
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [PATCH v8 3/8] powerpc: detect the trusted boot state of the system
Quoted 5 lines · Nayna Jain
While secure boot permits only properly verified signed kernels to be booted, trusted boot takes a measurement of the kernel image prior to boot that can be subsequently compared against good known values via attestation services.
Instead of "takes a measurement", either "stores a measurement" or "calculates the file hash of the kernel image and stores the measurement prior to boot, that".
Quoted 21 lines
This patch reads the trusted boot state of a PowerNV system. The state is used to conditionally enable additional measurement rules in the IMA arch-specific policies.
Signed-off-by Nayna Jain <[email protected]>--- arch/powerpc/include/asm/secure_boot.h | 6 ++++++ arch/powerpc/kernel/secure_boot.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+)arch/powerpc/include/asm/secure_boot.h +0
-0arch/powerpc/kernel/secure_boot.c +0
-0@@ -7,6 +7,17 @@#include <linux/of.h>
arch/powerpc/kernel/secure_boot.c line 17
Quoted 10 lines
arch/powerpc/kernel/secure_boot.c +8
-0#include <asm/secure_boot.h> +static struct device_node *get_ppc_fw_sb_node (void ) +{ +static const struct of_device_id ids[] = { + { .compatible ="ibm,secureboot-v1" , }, + { .compatible ="ibm,secureboot-v2" , }, + {}, + }; +
scripts/checkpatch.pl is complaining that secureboot-v1, secureboot-v2 are not documented in the device tree bindings.
Mimi
Michael Ellerman
reviewerRe: [PATCH v8 3/8] powerpc: detect the trusted boot state of the system
In reply to Nayna JainQuoted 6 lines · Nayna Jain
arch/powerpc/kernel/secure_boot.c +0
-0@@ -28,3 +39,16 @@ bool is_ppc_secureboot_enabled(void)pr_info ("Secure boot mode %s\n" , enabled ?"enabled" :"disabled" );
arch/powerpc/kernel/secure_boot.c bool is_ppc_secureboot_enabled(void) · line 49
Quoted 10 lines
arch/powerpc/kernel/secure_boot.c +8
-0return enabled; } + +bool is_ppc_trustedboot_enabled (void ) +{ +struct device_node *node; +bool enabled = false; + + node =get_ppc_fw_sb_node (); + enabled =of_property_read_bool (node,"trusted-enabled" );
Also here you need:
of_node_put(node);
arch/powerpc/kernel/secure_boot.c bool is_ppc_secureboot_enabled(void) · line 54
Quoted 5 lines
arch/powerpc/kernel/secure_boot.c +5
-0+ +pr_info ("Trusted boot mode %s\n" , enabled ?"enabled" :"disabled" ); + +return enabled; +}
cheers
PATCH v8 4/8 powerpc/ima: add measurement rules to ima arch specific policy
In reply to Nayna JainThis patch adds the measurement rules to the arch specific policies on trusted boot enabled systems.
--- arch/powerpc/kernel/ima_arch.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
arch/powerpc/kernel/ima_arch.c +33 -1
@@ -26,6 +26,32 @@ static const char *const secure_rules[] = {NULL }; +/* +* The "measure_rules" are enabled only on "trustedboot" enabled systems. +* These rules add the kexec kernel image and kernel modules file hashes to +* the IMA measurement list. +*/ +static const char *const trusted_rules[] = { +"measure func=KEXEC_KERNEL_CHECK" , +"measure func=MODULE_CHECK" , +NULL +}; + +/* +* The "secure_and_trusted_rules" contains rules for both the secure boot and +* trusted boot. The "template=ima-modsig" option includes the appended +* signature, when available, in the IMA measurement list. +*/ +static const char *const secure_and_trusted_rules[] = { +"measure func=KEXEC_KERNEL_CHECK template=ima-modsig" , +"measure func=MODULE_CHECK template=ima-modsig" , +"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +#ifndef CONFIG_MODULE_SIG_FORCE +"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +#endif +NULL +}; +/* * Returns the relevant IMA arch-specific policies based on the system secure * boot state.
@@ -33,7 +59,13 @@ static const char *const secure_rules[] = {const char *const *arch_get_ima_policy (void ) {if (is_ppc_secureboot_enabled ()) -return secure_rules; +if (is_ppc_trustedboot_enabled ()) +return secure_and_trusted_rules; +else +return secure_rules; +else +if (is_ppc_trustedboot_enabled ()) +return trusted_rules;return NULL ; }
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [PATCH v8 4/8] powerpc/ima: add measurement rules to ima arch specific policy
Quoted 2 lines · Nayna Jain
This patch adds the measurement rules to the arch specific policies on trusted boot enabled systems.
This version does not add rules to the existing arch specific policy, but defines an arch specific trusted boot only policy and a combined secure and trusted boot policy.
Quoted 11 lines
Signed-off-by Nayna Jain <[email protected]>--- arch/powerpc/kernel/ima_arch.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)arch/powerpc/kernel/ima_arch.c +0
-0
arch/powerpc/kernel/ima_arch.c static const char *const secure_rules[] = { · line 30
Quoted 5 lines
arch/powerpc/kernel/ima_arch.c +2
-0@@ -26,6 +26,32 @@ static const char *const secure_rules[] = { NULL }; +/* +* The "measure_rules" are enabled only on "trustedboot" enabled systems.
Please update the policy name to reflect the new "trusted_rules" name.
Quoted 28 lines
arch/powerpc/kernel/ima_arch.c +24
-0+* These rules add the kexec kernel image and kernel modules file hashes to +* the IMA measurement list. +*/ +static const char *const trusted_rules[] = { +"measure func=KEXEC_KERNEL_CHECK" , +"measure func=MODULE_CHECK" , +NULL +}; + +/* +* The "secure_and_trusted_rules" contains rules for both the secure boot and +* trusted boot. The "template=ima-modsig" option includes the appended +* signature, when available, in the IMA measurement list. +*/ +static const char *const secure_and_trusted_rules[] = { +"measure func=KEXEC_KERNEL_CHECK template=ima-modsig" , +"measure func=MODULE_CHECK template=ima-modsig" , +"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +#ifndef CONFIG_MODULE_SIG_FORCE +"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +#endif +NULL +}; +/* * Returns the relevant IMA arch-specific policies based on the system secure * boot state.
arch/powerpc/kernel/ima_arch.c static const char *const secure_rules[] = { · line 67
Quoted 10 lines
arch/powerpc/kernel/ima_arch.c +6
-1@@ -33,7 +59,13 @@ static const char *const secure_rules[] = {const char *const *arch_get_ima_policy (void ) {if (is_ppc_secureboot_enabled ()) -return secure_rules; +if (is_ppc_trustedboot_enabled ()) +return secure_and_trusted_rules; +else +return secure_rules; +else +if (is_ppc_trustedboot_enabled ())
No need for the "if" statement to be on a separate line. Please combine the "else" and "if" statements.
Mimi
Quoted 4 lines
arch/powerpc/kernel/ima_arch.c +1
-0+return trusted_rules;return NULL ; }
PATCH v8 5/8 ima: make process_buffer_measurement() generic
In reply to Nayna Jainprocess_buffer_measurement() is limited to measuring the kexec boot command line. This patch makes process_buffer_measurement() more generic, allowing it to measure other types of buffer data (e.g. blacklisted binary hashes or key hashes).
This patch modifies the function to conditionally retrieve the policy defined pcr and template based on the func.
--- security/integrity/ima/ima.h | 3 ++ security/integrity/ima/ima_main.c | 51 ++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 18 deletions(-)
security/integrity/ima/ima.h +3 -0
@@ -217,6 +217,9 @@ void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file,struct evm_ima_xattr_data *xattr_value, int xattr_len, const struct modsig *modsig, int pcr, struct ima_template_desc *template_desc); +void process_buffer_measurement (const void *buf,int size, +const char *eventname,enum ima_hooks func, +int pcr);void ima_audit_measurement (struct integrity_iint_cache *iint,const unsigned char *filename); int ima_alloc_init_template(struct ima_event_data *event_data,
security/integrity/ima/ima_main.c +33 -18
86 lines not on this page · raw message
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [PATCH v8 5/8] ima: make process_buffer_measurement() generic
Quoted 4 lines · Nayna Jain
process_buffer_measurement()is limited to measuring the kexec boot command line. This patch makesprocess_buffer_measurement()more generic, allowing it to measure other types of buffer data (e.g. blacklisted binary hashes or key hashes).
based on "func".
Quoted 3 lines
This patch modifies the function to conditionally retrieve the policy defined pcr and template based on the func.
This would be done in a subsequent patch, not here.
Quoted 17 lines
security/integrity/ima/ima_main.c +2
-4@@ -642,19 +642,38 @@ static void process_buffer_measurement(const void *buf, int size, .filename = eventname, .buf = buf, .buf_len = size}; -struct ima_template_desc *template_desc =NULL ; +struct ima_template_desc *template =NULL ;struct {struct ima_digest_data hdr;char digest[IMA_MAX_DIGEST_SIZE ]; } hash = {};int violation =0 ; -int pcr =CONFIG_IMA_MEASURE_PCR_IDX ;int action =0 ; +u32 secid; - action =ima_get_action (NULL , cred, secid,0 ,KEXEC_CMDLINE , &pcr, - &template_desc);
security/integrity/ima/ima_main.c static void process_buffer_measurement(const void *buf, int size, · line 661
Quoted 10 lines
security/integrity/ima/ima_main.c +8
-2-if (!(action &IMA_MEASURE )) -return ; +if (func) { +security_task_getsecid (current, &secid); + action =ima_get_action (NULL ,current_cred (), secid,0 , func, + &pcr, &template); +if (!(action &IMA_MEASURE )) +return ; + } +
Initially there is no need to test "func". A specific "func" test would be added as needed.
Mimi
PATCH v8 6/8 certs: add wrapper function to check blacklisted binary hash
In reply to Nayna JainThe -EKEYREJECTED error returned by existing is_hash_blacklisted() is misleading when called for checking against blacklisted hash of a binary.
This patch adds a wrapper function is_binary_blacklisted() to return -EPERM error if binary is blacklisted.
--- certs/blacklist.c | 9 +++++++++ include/keys/system_keyring.h | 6 ++++++ 2 files changed, 15 insertions(+)
certs/blacklist.c +9 -0
@@ -135,6 +135,15 @@ int is_hash_blacklisted(const u8 *hash, size_t hash_len, const char *type) }EXPORT_SYMBOL_GPL (is_hash_blacklisted); +int is_binary_blacklisted (const u8 *hash,size_t hash_len) +{ +if (is_hash_blacklisted (hash, hash_len,"bin" ) == -EKEYREJECTED ) +return -EPERM ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (is_binary_blacklisted); +/* * Initialise the blacklist */
include/keys/system_keyring.h +6 -0
@@ -35,12 +35,18 @@ extern int restrict_link_by_builtin_and_secondary_trusted(extern int mark_hash_blacklisted (const char *hash);extern int is_hash_blacklisted (const u8 *hash,size_t hash_len,const char *type); +extern int is_binary_blacklisted (const u8 *hash,size_t hash_len);#else static inline int is_hash_blacklisted (const u8 *hash,size_t hash_len,const char *type) {return 0 ; } + +static inline int is_binary_blacklisted (const u8 *hash,size_t hash_len) +{ +return 0 ; +}#endif #ifdef CONFIG_IMA_BLACKLIST_KEYRING
Signature · 1 line
2.20.1
PATCH v8 7/8 ima: check against blacklisted hashes for files with modsig
In reply to Nayna JainAsymmetric private keys are used to sign multiple files. The kernel currently support checking against blacklisted keys. However, if the public key is blacklisted, any file signed by the blacklisted key will automatically fail signature verification. We might not want to blacklist all the files signed by a particular key, but just a single file. Blacklisting the public key is not fine enough granularity.
This patch adds support for checking against the blacklisted hash of the file based on the IMA policy. The blacklisted hash is the file hash without the appended signature. Defined is a new policy option "appraise_flag=check_blacklist".
--- Documentation/ABI/testing/ima_policy | 1 + security/integrity/ima/ima.h | 8 +++++++ security/integrity/ima/ima_appraise.c | 31 +++++++++++++++++++++++++++ security/integrity/ima/ima_main.c | 12 +++++++---- security/integrity/ima/ima_policy.c | 10 +++++++-- security/integrity/integrity.h | 1 + 6 files changed, 57 insertions(+), 6 deletions(-)
Documentation/ABI/testing/ima_policy +1 -0
@@ -25,6 +25,7 @@ Description: lsm: [[subj_user=] [subj_role=] [subj_type=] [obj_user=] [obj_role=] [obj_type=]] option: [[appraise_type=]] [template=] [permit_directio] + [appraise_flag=[check_blacklist]] base: func:= [BPRM_CHECK][MMAP_CHECK][CREDS_CHECK][FILE_CHECK][MODULE_CHECK] [FIRMWARE_CHECK] [KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK]
security/integrity/ima/ima.h +8 -0
@@ -256,6 +256,8 @@ int ima_policy_show(struct seq_file *m, void *v);#define IMA_APPRAISE_KEXEC 0x40#ifdef CONFIG_IMA_APPRAISE +int ima_check_blacklist (struct integrity_iint_cache *iint, +const struct modsig *modsig,int pcr); int ima_appraise_measurement(enum ima_hooks func, struct integrity_iint_cache *iint, struct file *file, const unsigned char *filename,
@@ -271,6 +273,12 @@ int ima_read_xattr(struct dentry *dentry, struct evm_ima_xattr_data **xattr_value);#else +static inline int ima_check_blacklist (struct integrity_iint_cache *iint, +const struct modsig *modsig,int pcr) +{ +return 0 ; +} + static inline int ima_appraise_measurement(enum ima_hooks func, struct integrity_iint_cache *iint, struct file *file,
security/integrity/ima/ima_appraise.c +31 -0
@@ -12,6 +12,7 @@#include <linux/magic.h> #include <linux/ima.h> #include <linux/evm.h> +#include <keys/system_keyring.h> #include "ima.h"
@@ -303,6 +304,36 @@ static int modsig_verify(enum ima_hooks func, const struct modsig *modsig,return rc; } +/* +* ima_blacklist_measurement - Checks whether the binary is blacklisted. If +* yes, then adds the hash of the blacklisted binary to the measurement list. +* +* Returns -EPERM if the hash is blacklisted. +*/ +int ima_check_blacklist (struct integrity_iint_cache *iint, +const struct modsig *modsig,int pcr) +{ +enum hash_algo hash_algo; +const u8 *digest =NULL ; +u32 digestsize =0 ; +int rc =0 ; + +if (!(iint->flags &IMA_CHECK_BLACKLIST )) +return 0 ; + +if (iint->flags &IMA_MODSIG_ALLOWED && modsig) { +ima_get_modsig_digest (modsig, &hash_algo, &digest, &digestsize); + + rc =is_binary_blacklisted (digest, digestsize); +if ((rc == -EPERM ) && (iint->flags &IMA_MEASURE )) +process_buffer_measurement (digest, digestsize, +"blacklisted-hash" ,NONE , + pcr); + } + +return rc; +} +/* * ima_appraise_measurement - appraise file measurement *
security/integrity/ima/ima_main.c +8 -4
@@ -335,10 +335,14 @@ static int process_measurement(struct file *file, const struct cred *cred, xattr_value, xattr_len, modsig, pcr, template_desc);if (rc ==0 && (action &IMA_APPRAISE_SUBMASK )) { -inode_lock (inode); - rc =ima_appraise_measurement (func, iint, file, pathname, - xattr_value, xattr_len, modsig); -inode_unlock (inode); + rc =ima_check_blacklist (iint, modsig, pcr); +if (rc != -EPERM ) { +inode_lock (inode); + rc =ima_appraise_measurement (func, iint, file, + pathname, xattr_value, + xattr_len, modsig); +inode_unlock (inode); + }if (!rc) rc =mmap_violation_check (func, file, &pathbuf, &pathname, filename);
security/integrity/ima/ima_policy.c +8 -2
@@ -765,8 +765,8 @@ enum { Opt_fsuuid, Opt_uid_eq, Opt_euid_eq, Opt_fowner_eq, Opt_uid_gt, Opt_euid_gt, Opt_fowner_gt, Opt_uid_lt, Opt_euid_lt, Opt_fowner_lt, - Opt_appraise_type, Opt_permit_directio, - Opt_pcr, Opt_template, Opt_err + Opt_appraise_type, Opt_appraise_flag, + Opt_permit_directio, Opt_pcr, Opt_template, Opt_err }; static const match_table_t policy_tokens = {
@@ -798,6 +798,7 @@ static const match_table_t policy_tokens = { {Opt_euid_lt, "euid<%s"}, {Opt_fowner_lt, "fowner<%s"}, {Opt_appraise_type, "appraise_type=%s"}, + {Opt_appraise_flag, "appraise_flag=%s"}, {Opt_permit_directio, "permit_directio"}, {Opt_pcr, "pcr=%s"}, {Opt_template, "template=%s"},
@@ -1172,6 +1173,11 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)else result = -EINVAL ;break ; +case Opt_appraise_flag: +ima_log_string (ab,"appraise_flag" , args[0 ].from); +if (strstr (args[0 ].from,"blacklist" )) + entry->flags |=IMA_CHECK_BLACKLIST ; +break ;case Opt_permit_directio: entry->flags |=IMA_PERMIT_DIRECTIO ;break ;
security/integrity/integrity.h +1 -0
@@ -32,6 +32,7 @@#define EVM_IMMUTABLE_DIGSIG 0x08000000#define IMA_FAIL_UNVERIFIABLE_SIGS 0x10000000#define IMA_MODSIG_ALLOWED 0x20000000 +#define IMA_CHECK_BLACKLIST 0x40000000#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \ IMA_HASH | IMA_APPRAISE_SUBMASK)
Signature · 1 line
2.20.1
Mimi Zohar
maintainerRe: [PATCH v8 7/8] ima: check against blacklisted hashes for files with modsig
Documentation/ABI/testing/ima_policy Description: · line 28
Quoted 9 lines · Nayna Jain
Documentation/ABI/testing/ima_policy +1
-0@@ -25,6 +25,7 @@ Description: lsm: [[subj_user=] [subj_role=] [subj_type=] [obj_user=] [obj_role=] [obj_type=]] option: [[appraise_type=]] [template=] [permit_directio] + [appraise_flag=[check_blacklist]]
Like the other options, only "[[appraise_flag=]]" should be defined here. The values should be defined in the "option:" section.
Quoted 11 lines
Documentation/ABI/testing/ima_policy +0
-0base: func:= [BPRM_CHECK][MMAP_CHECK][CREDS_CHECK][FILE_CHECK][MODULE_CHECK] [FIRMWARE_CHECK]Documentation/ABI/testing/ima_policy +0
-0[KEXEC_KERNEL_CHECK] [KEXEC_INITRAMFS_CHECK]security/integrity/ima/ima_appraise.c +0
-0
security/integrity/ima/ima_appraise.c static int modsig_verify(enum ima_hooks func, const struct modsig *modsig, · line 308
Quoted 5 lines
security/integrity/ima/ima_appraise.c +2
-0@@ -303,6 +304,36 @@ static int modsig_verify(enum ima_hooks func, const struct modsig *modsig,return rc; } +/* +* ima_blacklist_measurement - Checks whether the binary is blacklisted. If
Please update the function name to reflect the actual function name.
security/integrity/ima/ima_appraise.c static int modsig_verify(enum ima_hooks func, const struct modsig *modsig, · line 309
Quoted 1 line
security/integrity/ima/ima_appraise.c +1
-0+* yes, then adds the hash of the blacklisted binary to the measurement list.
Refer to Documentation/process/coding-style.rst section "8) Commenting" on how to format function comments. Don't start a sentence with "If yes,".
Quoted 14 lines
security/integrity/ima/ima_appraise.c +7
-0+* +* Returns -EPERM if the hash is blacklisted. +*/ +int ima_check_blacklist (struct integrity_iint_cache *iint, +const struct modsig *modsig,int pcr) +{ +enum hash_algo hash_algo;security/integrity/ima/ima_policy.c +0
-0
security/integrity/ima/ima_policy.c static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) · line 1180
Quoted 8 lines
security/integrity/ima/ima_policy.c +5
-0@@ -1172,6 +1173,11 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)else result = -EINVAL ;break ; +case Opt_appraise_flag: +ima_log_string (ab,"appraise_flag" , args[0 ].from); +if (strstr (args[0 ].from,"blacklist" )) + entry->flags |=IMA_CHECK_BLACKLIST ; +break ;
When adding a new policy rule option, ima_policy_show() needs to be updated as well.
Mimi
Quoted 4 lines
security/integrity/ima/ima_policy.c +0
-0case Opt_permit_directio: entry->flags |=IMA_PERMIT_DIRECTIO ;break ;
Mimi Zohar
maintainerRe: [PATCH v8 7/8] ima: check against blacklisted hashes for files with modsig
In reply to Nayna JainQuoted 11 lines · Nayna Jain
Asymmetric private keys are used to sign multiple files. The kernel currently support checking against blacklisted keys. However, if the public key is blacklisted, any file signed by the blacklisted key will automatically fail signature verification. We might not want to blacklist all the files signed by a particular key, but just a single file. Blacklisting the public key is not fine enough granularity.
This patch adds support for checking against the blacklisted hash of the file based on the IMA policy. The blacklisted hash is the file hash without the appended signature. Defined is a new policy option "appraise_flag=check_blacklist".
Please add an example of how to blacklist a file with an appended signature. The simplest example that works on x86 as well as Power would be blacklisting a kernel module. The example should include calculating the kernel module hash without the appended signature, enabling the Kconfig option (CONFIG_SYSTEM_BLACKLIST_HASH_LIST), and the blacklist hash format (eg. "bin:<file hash>").
thanks,
Mimi
Re: [PATCH v8 7/8] ima: check against blacklisted hashes for files with modsig
Quoted 13 lines · Mimi Zohar
Quoted 11 lines · Nayna Jain
Asymmetric private keys are used to sign multiple files. The kernel currently support checking against blacklisted keys. However, if the public key is blacklisted, any file signed by the blacklisted key will automatically fail signature verification. We might not want to blacklist all the files signed by a particular key, but just a single file. Blacklisting the public key is not fine enough granularity.
This patch adds support for checking against the blacklisted hash of the file based on the IMA policy. The blacklisted hash is the file hash without the appended signature. Defined is a new policy option "appraise_flag=check_blacklist".
Quoted 6 lines
Please add an example of how to blacklist a file with an appended signature. The simplest example that works on x86 as well as Power would be blacklisting a kernel module. The example should include calculating the kernel module hash without the appended signature, enabling the
Kconfigoption (CONFIG_SYSTEM_BLACKLIST_HASH_LIST), and the blacklist hash format (eg. "bin:<file hash>").
And of course, the IMA appraise kernel module policy rule containing "appraise_flag=check_blacklist".
thanks,
Mimi
PATCH v8 8/8 powerpc/ima: update ima arch policy to check for blacklist
In reply to Nayna JainThis patch updates the arch-specific policies for PowerNV system to make sure that the binary hash is not blacklisted.
--- arch/powerpc/kernel/ima_arch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/kernel/ima_arch.c +4 -4
@@ -19,9 +19,9 @@ bool arch_ima_get_secureboot(void)* to be stored as an xattr or as an appended signature. */ static const char *const secure_rules[] = { -"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +"appraise func=KEXEC_KERNEL_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig" , #ifndef CONFIG_MODULE_SIG_FORCE -"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +"appraise func=MODULE_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig" , #endifNULL };
@@ -45,9 +45,9 @@ static const char *const trusted_rules[] = {static const char *const secure_and_trusted_rules[] = {"measure func=KEXEC_KERNEL_CHECK template=ima-modsig" ,"measure func=MODULE_CHECK template=ima-modsig" , -"appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig|modsig" , +"appraise func=KEXEC_KERNEL_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig" , #ifndef CONFIG_MODULE_SIG_FORCE -"appraise func=MODULE_CHECK appraise_type=imasig|modsig" , +"appraise func=MODULE_CHECK appraise_flag=check_blacklist appraise_type=imasig|modsig" , #endifNULL };
Signature · 1 line
2.20.1