mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
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. Reported-and-suggested-by: Mimi Zohar <zohar@linux.ibm.com> Suggested-by: Roberto Sassu <roberto.sassu@huawei.com> Signed-off-by: Coiby Xu <coxu@redhat.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
@@ -12668,6 +12668,7 @@ R: Eric Snowberg <eric.snowberg@oracle.com>
|
||||
L: linux-integrity@vger.kernel.org
|
||||
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/
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 @@ out:
|
||||
return enabled;
|
||||
}
|
||||
|
||||
bool arch_get_secureboot(void)
|
||||
{
|
||||
return is_ppc_secureboot_enabled();
|
||||
}
|
||||
|
||||
bool is_ppc_trustedboot_enabled(void)
|
||||
{
|
||||
struct device_node *node;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -2504,6 +2504,11 @@ out:
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -920,7 +920,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -73,14 +74,8 @@ int ima_validate_range(phys_addr_t phys, 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;
|
||||
|
||||
19
include/linux/secure_boot.h
Normal file
19
include/linux/secure_boot.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
|
||||
*
|
||||
* Author: Coiby Xu <coxu@redhat.com>
|
||||
*/
|
||||
|
||||
#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 */
|
||||
@@ -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/
|
||||
|
||||
56
security/integrity/efi_secureboot.c
Normal file
56
security/integrity/efi_secureboot.c
Normal file
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: GPL-1.0+
|
||||
/*
|
||||
* Copyright (C) 2018 IBM Corporation
|
||||
*/
|
||||
#include <linux/efi.h>
|
||||
#include <linux/secure_boot.h>
|
||||
#include <asm/efi.h>
|
||||
|
||||
#ifndef arch_efi_boot_mode
|
||||
#define arch_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("integrity: 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("integrity: secureboot mode disabled\n");
|
||||
else if (mode == efi_secureboot_mode_unknown)
|
||||
pr_info("integrity: secureboot mode unknown\n");
|
||||
else
|
||||
pr_info("integrity: secureboot mode enabled\n");
|
||||
return mode;
|
||||
}
|
||||
|
||||
/*
|
||||
* Query secure boot status
|
||||
*
|
||||
* Note don't call this function too early e.g. in __setup hook otherwise the
|
||||
* kernel may hang when calling efi_get_secureboot_mode.
|
||||
*
|
||||
*/
|
||||
bool arch_get_secureboot(void)
|
||||
{
|
||||
static enum efi_secureboot_mode sb_mode;
|
||||
static bool initialized;
|
||||
|
||||
if (!initialized && efi_enabled(EFI_BOOT)) {
|
||||
sb_mode = arch_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;
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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[] = {
|
||||
@@ -67,7 +24,7 @@ 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()) {
|
||||
if (IS_ENABLED(CONFIG_MODULE_SIG))
|
||||
set_module_sig_enforced();
|
||||
if (IS_ENABLED(CONFIG_KEXEC_SIG))
|
||||
|
||||
@@ -953,8 +953,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
16
security/integrity/secure_boot.c
Normal file
16
security/integrity/secure_boot.c
Normal file
@@ -0,0 +1,16 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Copyright (C) 2026 Red Hat, Inc. All Rights Reserved.
|
||||
*
|
||||
* Author: Coiby Xu <coxu@redhat.com>
|
||||
*/
|
||||
#include <linux/secure_boot.h>
|
||||
|
||||
/*
|
||||
* Default weak implementation.
|
||||
* Architectures that support secure boot must override this.
|
||||
*/
|
||||
__weak bool arch_get_secureboot(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user