Make detecting the secure boot status integrity-wide
Subsystems (10)
v2 cover Make detecting the secure boot status integrity-wide
EVM and other LSMs need the ability to query the secure boot status of the system, without directly calling the IMA arch_ima_get_secureboot function. Make arch_ima_get_secureboot integrity-wide.
v2:
- drop CONFIG_INTEGRITY_SECURE_BOOT Kconfig option since it "imply INTEGRITY_SECURE_BOOT" is anti-pattern as pointed out by Ard Biesheuvel
Coiby Xu (3):
integrity: Make arch_ima_get_secureboot integrity-wide
evm: Don't enable fix mode when secure boot is enabled
s390: Drop unnecessary CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
MAINTAINERS | 1 + arch/powerpc/kernel/ima_arch.c | 5 -- arch/powerpc/kernel/secure_boot.c | 6 ++ arch/s390/Kconfig | 1 - arch/s390/kernel/Makefile | 1 - arch/s390/kernel/ima_arch.c | 14 ----- arch/s390/kernel/ipl.c | 5 ++ arch/x86/include/asm/efi.h | 4 +- arch/x86/platform/efi/efi.c | 2 +- include/linux/ima.h | 7 +-- include/linux/secure_boot.h | 19 +++++++ security/integrity/Makefile | 3 +- security/integrity/efi_secureboot.c | 56 +++++++++++++++++++ security/integrity/evm/evm_main.c | 24 +++++--- security/integrity/ima/ima_appraise.c | 2 +- security/integrity/ima/ima_efi.c | 48 +--------------- security/integrity/ima/ima_main.c | 4 +- security/integrity/integrity.h | 1 + security/integrity/platform_certs/load_uefi.c | 2 +- security/integrity/secure_boot.c | 16 ++++++ 20 files changed, 134 insertions(+), 87 deletions(-) delete mode 100644 arch/s390/kernel/ima_arch.c create mode 100644 include/linux/secure_boot.h create mode 100644 security/integrity/efi_secureboot.c create mode 100644 security/integrity/secure_boot.c
base-commit: 8dfce8991b95d8625d0a1d2896e42f93b9d7f68d
Signature · 1 line
2.52.0
PATCH v2 1/3 integrity: Make arch_ima_get_secureboot integrity-wide
EVM and other LSMs need the ability to query the secure boot status of the system, without directly calling the IMA arch_ima_get_secureboot function. Refactor the secure boot status check into a general function named arch_get_secureboot.
--- MAINTAINERS | 1 + arch/powerpc/kernel/ima_arch.c | 5 -- arch/powerpc/kernel/secure_boot.c | 6 ++ arch/s390/kernel/ima_arch.c | 6 -- arch/s390/kernel/ipl.c | 5 ++ arch/x86/include/asm/efi.h | 4 +- arch/x86/platform/efi/efi.c | 2 +- include/linux/ima.h | 7 +-- include/linux/secure_boot.h | 19 +++++++ security/integrity/Makefile | 3 +- security/integrity/efi_secureboot.c | 56 +++++++++++++++++++ security/integrity/ima/ima_appraise.c | 2 +- security/integrity/ima/ima_efi.c | 48 +--------------- security/integrity/ima/ima_main.c | 4 +- security/integrity/integrity.h | 1 + security/integrity/platform_certs/load_uefi.c | 2 +- security/integrity/secure_boot.c | 16 ++++++ 17 files changed, 117 insertions(+), 70 deletions(-) create mode 100644 include/linux/secure_boot.h create mode 100644 security/integrity/efi_secureboot.c create mode 100644 security/integrity/secure_boot.c
MAINTAINERS +1 -0
@@ -12519,6 +12519,7 @@ R: Eric Snowberg <[email protected]> L: [email protected] S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git +F: include/linux/secure_boot.h F: security/integrity/ F: security/integrity/ima/
arch/powerpc/kernel/ima_arch.c +0 -5
@@ -7,11 +7,6 @@#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.
arch/powerpc/kernel/secure_boot.c +6 -0
@@ -5,6 +5,7 @@*/ #include <linux/types.h> #include <linux/of.h> +#include <linux/secure_boot.h> #include <linux/string_choices.h> #include <asm/secure_boot.h>
@@ -44,6 +45,11 @@ bool is_ppc_secureboot_enabled(void)return enabled; } +bool arch_get_secureboot (void ) +{ +return is_ppc_secureboot_enabled (); +} +bool is_ppc_trustedboot_enabled (void ) {struct device_node *node;
arch/s390/kernel/ima_arch.c +0 -6
@@ -1,12 +1,6 @@// SPDX-License-Identifier: GPL-2.0 #include <linux/ima.h> -#include <asm/boot_data.h> - -bool arch_ima_get_secureboot (void ) -{ -return ipl_secure_flag; -}const char *const *arch_get_ima_policy (void ) {
arch/s390/kernel/ipl.c +5 -0
@@ -2504,6 +2504,11 @@ void *ipl_report_finish(struct ipl_report *report)return buf; } +bool arch_get_secureboot (void ) +{ +return ipl_secure_flag; +} +int ipl_report_free (struct ipl_report *report) {struct ipl_report_component *comp, *ncomp;
arch/x86/include/asm/efi.h +2 -2
@@ -401,9 +401,9 @@ extern int __init efi_memmap_split_count(efi_memory_desc_t *md,extern void __init efi_memmap_insert (struct efi_memory_map *old_memmap,void *buf,struct efi_mem_range *mem); -extern enum efi_secureboot_mode __x86_ima_efi_boot_mode (void ); +enum efi_secureboot_mode __x86_efi_boot_mode (void ); -#define arch_ima_efi_boot_mode __x86_ima_efi_boot_mode() +#define arch_efi_boot_mode __x86_efi_boot_mode()#ifdef CONFIG_EFI_RUNTIME_MAP int efi_get_runtime_map_size (void );
arch/x86/platform/efi/efi.c +1 -1
@@ -921,7 +921,7 @@ umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n)return attr->mode; } -enum efi_secureboot_mode __x86_ima_efi_boot_mode (void ) +enum efi_secureboot_mode __x86_efi_boot_mode (void ) {return boot_params.secure_boot; }
include/linux/ima.h +1 -6
@@ -11,6 +11,7 @@#include <linux/fs.h> #include <linux/security.h> #include <linux/kexec.h> +#include <linux/secure_boot.h> #include <crypto/hash_info.h> struct linux_binprm ;
@@ -72,14 +73,8 @@ int __init ima_get_kexec_buffer(void **addr, size_t *size);#endif #ifdef CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT -extern bool arch_ima_get_secureboot (void );extern const char *const *arch_get_ima_policy (void );#else -static inline bool arch_ima_get_secureboot (void ) -{ -return false; -} -static inline const char *const *arch_get_ima_policy (void ) {return NULL ;
include/linux/secure_boot.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2026 Red Hat, Inc. All Rights Reserved. +* +* Author: Coiby Xu <[email protected]> +*/ + +#ifndef _LINUX_SECURE_BOOT_H +#define _LINUX_SECURE_BOOT_H + +#include <linux/types.h> + +/* +* Returns true if the platform secure boot is enabled. +* Returns false if disabled or not supported. +*/ +bool arch_get_secureboot (void ); + +#endif /* _LINUX_SECURE_BOOT_H */
security/integrity/Makefile +2 -1
@@ -5,7 +5,7 @@ obj-$(CONFIG_INTEGRITY) += integrity.o -integrity-y := iint.o +integrity-y := iint.o secure_boot.o integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o
@@ -18,6 +18,7 @@ integrity-$(CONFIG_LOAD_IPL_KEYS) += platform_certs/load_ipl_s390.o integrity-$(CONFIG_LOAD_PPC_KEYS) += platform_certs/efi_parser.o \ platform_certs/load_powerpc.o \ platform_certs/keyring_handler.o +integrity-$(CONFIG_EFI) += efi_secureboot.o # The relative order of the 'ima' and 'evm' LSMs depends on the order below. obj-$(CONFIG_IMA) += ima/ obj-$(CONFIG_EVM) += evm/
security/integrity/efi_secureboot.c new file +56 -0
56 lines not on this page · raw message
security/integrity/ima/ima_appraise.c +1 -1
@@ -27,7 +27,7 @@ core_param(ima_appraise, ima_appraise_cmdline_default, charp, 0);void __init ima_appraise_parse_cmdline (void ) {const char *str = ima_appraise_cmdline_default; -bool sb_state =arch_ima_get_secureboot (); +bool sb_state =arch_get_secureboot ();int appraisal_state = ima_appraise;if (!str)
security/integrity/ima/ima_efi.c +3 -45
62 lines not on this page · raw message
security/integrity/ima/ima_main.c +2 -2
@@ -949,8 +949,8 @@ static int ima_load_data(enum kernel_load_data_id id, bool contents)switch (id) {case LOADING_KEXEC_IMAGE : -if (IS_ENABLED (CONFIG_KEXEC_SIG ) - &&arch_ima_get_secureboot ()) { +if (IS_ENABLED (CONFIG_KEXEC_SIG ) && +arch_get_secureboot ()) {pr_err ("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n" );return -EACCES ; }
security/integrity/integrity.h +1 -0
@@ -14,6 +14,7 @@#include <linux/types.h> #include <linux/integrity.h> +#include <linux/secure_boot.h> #include <crypto/sha1.h> #include <crypto/hash.h> #include <linux/key.h>
security/integrity/platform_certs/load_uefi.c +1 -1
@@ -212,7 +212,7 @@ static int __init load_uefi_certs(void) }/* the MOK/MOKx can not be trusted when secure boot is disabled */ -if (!arch_ima_get_secureboot ()) +if (!arch_get_secureboot ())return 0 ; mokx =get_cert_list (L"MokListXRT" , &mok_var, &mokxsize, &status);
security/integrity/secure_boot.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2026 Red Hat, Inc. All Rights Reserved. +* +* Author: Coiby Xu <[email protected]> +*/ +#include <linux/secure_boot.h> + +/* +* Default weak implementation. +* Architectures that support secure boot must override this. +*/ +__weak bool arch_get_secureboot (void ) +{ +return false; +}
Signature · 1 line
2.52.0
Mimi Zohar
maintainerRe: [PATCH v2 1/3] integrity: Make arch_ima_get_secureboot integrity-wide
Quoted 8 lines · Coiby Xu
EVM and other LSMs need the ability to query the secure boot status of the system, without directly calling the IMA
arch_ima_get_securebootfunction. Refactor the secure boot status check into a general function namedarch_get_secureboot.Reported-and-suggested-by Mimi Zohar <[email protected]>Suggested-by Roberto Sassu <[email protected]>Signed-off-by Coiby Xu <[email protected]>
Thanks, Coiby. Other than unnecessarily splitting a line, the patch set looks good. As soon as the open window closes, I'll queue these patches for linux- next.
Quoted 59 lines
security/integrity/ima/ima_efi.c +1
-44@@ -2,52 +2,9 @@/* * Copyright (C) 2018 IBM Corporation */ -#include <linux/efi.h> #include <linux/module.h> #include <linux/ima.h> -#include <asm/efi.h> - -#ifndef arch_ima_efi_boot_mode -#define arch_ima_efi_boot_mode efi_secureboot_mode_unset -#endif - -static enum efi_secureboot_mode get_sb_mode (void ) -{ -enum efi_secureboot_mode mode; - -if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { -pr_info ("ima: secureboot mode unknown, no efi\n" ); -return efi_secureboot_mode_unknown; - } - - mode =efi_get_secureboot_mode (efi.get_variable); -if (mode == efi_secureboot_mode_disabled) -pr_info ("ima: secureboot mode disabled\n" ); -else if (mode == efi_secureboot_mode_unknown) -pr_info ("ima: secureboot mode unknown\n" ); -else -pr_info ("ima: secureboot mode enabled\n" ); -return mode; -} - -bool arch_ima_get_secureboot (void ) -{ -static enum efi_secureboot_mode sb_mode; -static bool initialized; - -if (!initialized &&efi_enabled (EFI_BOOT )) { - sb_mode = arch_ima_efi_boot_mode; - -if (sb_mode == efi_secureboot_mode_unset) - sb_mode =get_sb_mode (); - initialized = true; - } - -if (sb_mode == efi_secureboot_mode_enabled) -return true; -else -return false; -} +#include <linux/secure_boot.h> /* secureboot arch rules */ static const char *const sb_arch_rules[] = {
security/integrity/ima/ima_efi.c static const char * const sb_arch_rules[] = { · line 28
Quoted 6 lines
security/integrity/ima/ima_efi.c +2
-1@@ -67,7 +24,8 @@ static const char * const sb_arch_rules[] = {const char *const *arch_get_ima_policy (void ) { -if (IS_ENABLED (CONFIG_IMA_ARCH_POLICY ) &&arch_ima_get_secureboot ()) { +if (IS_ENABLED (CONFIG_IMA_ARCH_POLICY ) && +arch_get_secureboot ()) {
No need to split the line here or below.
Quoted 8 lines
security/integrity/ima/ima_efi.c +0
-0if (IS_ENABLED (CONFIG_MODULE_SIG ))set_module_sig_enforced ();if (IS_ENABLED (CONFIG_KEXEC_SIG ))security/integrity/ima/ima_main.c +0
-0
security/integrity/ima/ima_main.c static int ima_load_data(enum kernel_load_data_id id, bool contents) · line 953
Quoted 7 lines
security/integrity/ima/ima_main.c +2
-2@@ -949,8 +949,8 @@ static int ima_load_data(enum kernel_load_data_id id, bool contents)switch (id) {case LOADING_KEXEC_IMAGE : -if (IS_ENABLED (CONFIG_KEXEC_SIG ) - &&arch_ima_get_secureboot ()) { +if (IS_ENABLED (CONFIG_KEXEC_SIG ) && +arch_get_secureboot ()) {
===>
Mimi
Quoted 3 lines
security/integrity/ima/ima_main.c +0
-0pr_err ("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n" );return -EACCES ; }
Re: [PATCH v2 1/3] integrity: Make arch_ima_get_secureboot integrity-wide
Quoted 6 lines · Mimi Zohar
Quoted 5 lines · Coiby Xu
EVM and other LSMs need the ability to query the secure boot status of the system, without directly calling the IMA
arch_ima_get_securebootfunction. Refactor the secure boot status check into a general function namedarch_get_secureboot.
Quoted 7 lines
Quoted 3 lines
Reported-and-suggested-by Mimi Zohar <[email protected]>Suggested-by Roberto Sassu <[email protected]>Signed-off-by Coiby Xu <[email protected]>Thanks, Coiby. Other than unnecessarily splitting a line, the patch set looks good. As soon as the open window closes, I'll queue these patches for linux- next.
Hi Mimi, thanks for reviewing the patch set! Would you like me to send a new version with the line splitting issue fixed?
Quoted 5 lines
Quoted 5 lines
security/integrity/ima/ima_efi.c +0
-0
[...]
Quoted 32 lines
security/integrity/ima/ima_efi.c static const char * const sb_arch_rules[] = { · line 28
Quoted 4 lines
{
security/integrity/ima/ima_efi.c +2
-1-if (IS_ENABLED (CONFIG_IMA_ARCH_POLICY ) &&arch_ima_get_secureboot ()) { +if (IS_ENABLED (CONFIG_IMA_ARCH_POLICY ) && +arch_get_secureboot ()) {No need to split the line here or below.
Quoted 8 lines
security/integrity/ima/ima_efi.c +0
-0if (IS_ENABLED (CONFIG_MODULE_SIG ))set_module_sig_enforced ();if (IS_ENABLED (CONFIG_KEXEC_SIG ))security/integrity/ima/ima_main.c +0
-0security/integrity/ima/ima_main.c static int ima_load_data(enum kernel_load_data_id id, bool contents) · line 953
Quoted 7 lines
security/integrity/ima/ima_main.c +2
-2@@ -949,8 +949,8 @@ static int ima_load_data(enum kernel_load_data_id id, bool contents)switch (id) {case LOADING_KEXEC_IMAGE : -if (IS_ENABLED (CONFIG_KEXEC_SIG ) - &&arch_ima_get_secureboot ()) { +if (IS_ENABLED (CONFIG_KEXEC_SIG ) && +arch_get_secureboot ()) {===>
Mimi
Quoted 3 lines
security/integrity/ima/ima_main.c +0
-0pr_err ("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n" );return -EACCES ; }
Signature · 2 lines
Best regards, Coiby
Mimi Zohar
maintainerRe: [PATCH v2 1/3] integrity: Make arch_ima_get_secureboot integrity-wide
Quoted 11 lines · Coiby Xu
Quoted 10 lines · Mimi Zohar
Quoted 8 lines · Coiby Xu
EVM and other LSMs need the ability to query the secure boot status of the system, without directly calling the IMA
arch_ima_get_securebootfunction. Refactor the secure boot status check into a general function namedarch_get_secureboot.Reported-and-suggested-by Mimi Zohar <[email protected]>Suggested-by Roberto Sassu <[email protected]>Signed-off-by Coiby Xu <[email protected]>
Quoted 6 lines
Quoted 3 lines
Thanks, Coiby. Other than unnecessarily splitting a line, the patch set looks good. As soon as the open window closes, I'll queue these patches for linux- next.
Hi Mimi, thanks for reviewing the patch set! Would you like me to send a new version with the line splitting issue fixed?
Yes, thanks.
Mimi
Quoted 39 lines
Quoted 6 lines
Quoted 6 lines
security/integrity/ima/ima_efi.c +0
-0[...]
Quoted 32 lines
security/integrity/ima/ima_efi.c static const char * const sb_arch_rules[] = { · line 28
Quoted 4 lines
{
security/integrity/ima/ima_efi.c +2
-1-if (IS_ENABLED (CONFIG_IMA_ARCH_POLICY ) &&arch_ima_get_secureboot ()) { +if (IS_ENABLED (CONFIG_IMA_ARCH_POLICY ) && +arch_get_secureboot ()) {No need to split the line here or below.
Quoted 8 lines
security/integrity/ima/ima_efi.c +0
-0if (IS_ENABLED (CONFIG_MODULE_SIG ))set_module_sig_enforced ();if (IS_ENABLED (CONFIG_KEXEC_SIG ))security/integrity/ima/ima_main.c +0
-0security/integrity/ima/ima_main.c static int ima_load_data(enum kernel_load_data_id id, bool contents) · line 953
Quoted 7 lines
security/integrity/ima/ima_main.c +2
-2@@ -949,8 +949,8 @@ static int ima_load_data(enum kernel_load_data_id id, bool contents)switch (id) {case LOADING_KEXEC_IMAGE : -if (IS_ENABLED (CONFIG_KEXEC_SIG ) - &&arch_ima_get_secureboot ()) { +if (IS_ENABLED (CONFIG_KEXEC_SIG ) && +arch_get_secureboot ()) {===>
Mimi
Quoted 3 lines
security/integrity/ima/ima_main.c +0
-0pr_err ("impossible to appraise a kernel image without a file descriptor; try using kexec_file_load syscall.\n" );return -EACCES ; }
PATCH v2 2/3 evm: Don't enable fix mode when secure boot is enabled
In reply to Coiby XuSimilar to IMA fix mode, forbid EVM fix mode when secure boot is enabled.
--- security/integrity/evm/evm_main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
security/integrity/evm/evm_main.c +17 -7
@@ -72,17 +72,25 @@ static struct xattr_list evm_config_default_xattrnames[] = {LIST_HEAD (evm_config_xattrnames); +static char *evm_cmdline__initdata ; +core_param (evm, evm_cmdline, charp,0 ); +static int evm_fixmode__ro_after_init ; -static int __init evm_set_fixmode (char *str) +static void __init evm_set_fixmode (void ) { -if (strncmp (str,"fix" ,3 ) ==0 ) - evm_fixmode =1 ; -else -pr_err ("invalid \"%s\" mode" , str); +if (!evm_cmdline) +return ; -return 1 ; +if (strncmp (evm_cmdline,"fix" ,3 ) ==0 ) { +if (arch_get_secureboot ()) { +pr_info ("Secure boot enabled: ignoring evm=fix" ); +return ; + } + evm_fixmode =1 ; + }else { +pr_err ("invalid \"%s\" mode" , evm_cmdline); + } } -__setup ("evm=" , evm_set_fixmode);static void __init evm_init_config (void ) {
@@ -1119,6 +1127,8 @@ static int __init init_evm(void)evm_init_config (); +evm_set_fixmode (); + error =integrity_init_keyring (INTEGRITY_KEYRING_EVM );if (error) goto error;
Signature · 1 line
2.52.0
PATCH v2 3/3 s390: Drop unnecessary CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT
In reply to Coiby XuCommit b5ca117365d9 ("ima: prevent kexec_load syscall based on runtime secureboot flag") and commit 268a78404973 ("s390/kexec_file: Disable kexec_load when IPLed secure") disabled the kexec_load syscall based on the secureboot mode. Commit 9e2b4be377f0 ("ima: add a new CONFIG for loading arch-specific policies") needed to detect the secure boot mode, not to load an IMA architecture specific policy. Since there is the new CONFIG_INTEGRITY_SECURE_BOOT, drop CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT for s390.
--- arch/s390/Kconfig | 1 - arch/s390/kernel/Makefile | 1 - arch/s390/kernel/ima_arch.c | 8 -------- 3 files changed, 10 deletions(-) delete mode 100644 arch/s390/kernel/ima_arch.c
arch/s390/Kconfig +0 -1
@@ -77,7 +77,6 @@ config S390 # # Note: keep this list sorted alphabetically # - imply IMA_SECURE_AND_OR_TRUSTED_BOOT select ALTERNATE_USER_ADDRESS_SPACE select ARCH_32BIT_USTAT_F_TINODE select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE
arch/s390/kernel/Makefile +0 -1
@@ -71,7 +71,6 @@ obj-$(CONFIG_STACKPROTECTOR) += stackprotector.o obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o kexec_image.o obj-$(CONFIG_KEXEC_FILE) += kexec_elf.o obj-$(CONFIG_CERT_STORE) += cert_store.o -obj-$(CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT) += ima_arch.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o obj-$(CONFIG_PERF_EVENTS) += perf_cpum_cf.o perf_cpum_sf.o
arch/s390/kernel/ima_arch.c deleted +0 -8
@@ -1,8 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include <linux/ima.h> - -const char *const *arch_get_ima_policy (void ) -{ -return NULL ; -}
Signature · 1 line
2.52.0