integrity: avoid using __weak functions
Subsystems (9)
PATCH 1/1 integrity: avoid using __weak functions
From: Arnd Bergmann <[email protected]>
The security/integrity/secure_boot.c file containing only a __weak function leads to a build failure with clang:
Cannot find symbol for section 2: .text.security/integrity/secure_boot.o: failed
Moving the function into another file that has at least one non-__weak symbol would solve this, but this is always fragile.
Avoid __weak definitions entirely and instead move the stub helper into an asm-generic header that gets used by default on architectures that do not provide their own version. This is consistent with how a lot of other architecture specific functionality works, and is more reliable.
---
This is a larger change than I had hoped for.
If you prefer a different way to address the build failure, please treat this as a Reported-by when you apply your own fix
--- arch/powerpc/include/asm/secure_boot.h | 6 +++ arch/powerpc/kernel/secure_boot.c | 1 - arch/s390/include/asm/secure_boot.h | 9 +++++ include/asm-generic/Kbuild | 1 + include/asm-generic/secure_boot.h | 37 +++++++++++++++++++ include/linux/secure_boot.h | 8 +--- security/integrity/Makefile | 2 +- .../integrity/platform_certs/load_powerpc.c | 2 +- security/integrity/secure_boot.c | 16 -------- 9 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 arch/s390/include/asm/secure_boot.h create mode 100644 include/asm-generic/secure_boot.h delete mode 100644 security/integrity/secure_boot.c
arch/powerpc/include/asm/secure_boot.h +6 -0
@@ -10,11 +10,17 @@#ifdef CONFIG_PPC_SECURE_BOOT +bool arch_get_secureboot (void );bool is_ppc_secureboot_enabled (void );bool is_ppc_trustedboot_enabled (void );#else +static inline bool arch_get_secureboot (void ) +{ +return false; +} +static inline bool is_ppc_secureboot_enabled (void ) {return false;
arch/powerpc/kernel/secure_boot.c +0 -1
@@ -7,7 +7,6 @@#include <linux/of.h> #include <linux/secure_boot.h> #include <linux/string_choices.h> -#include <asm/secure_boot.h> static struct device_node *get_ppc_fw_sb_node (void ) {
arch/s390/include/asm/secure_boot.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_S390_SECURE_BOOT_H +#define _ASM_S390_SECURE_BOOT_H + +#include <linux/types.h + +bool arch_get_secureboot (void ); + +#endif
include/asm-generic/Kbuild +1 -0
@@ -51,6 +51,7 @@ mandatory-y += rqspinlock.h mandatory-y += runtime-const.h mandatory-y += rwonce.h mandatory-y += sections.h +mandatory-y += secure_boot.h mandatory-y += serial.h mandatory-y += shmparam.h mandatory-y += simd.h
include/asm-generic/secure_boot.h new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2026 Red Hat, Inc. All Rights Reserved. +* +* Author: Coiby Xu <[email protected]> +*/ +#ifndef _ASM_SECURE_BOOT_H +#define _ASM_SECURE_BOOT_H + + +#include <linux/types.h> + +#ifdef CONFIG_EFI + +/* +* Default implementation. +* Architectures that support secure boot must override this. +* +* Returns true if the platform secure boot is enabled. +* Returns false if disabled or not supported. +*/ +bool arch_get_secureboot (void ); + +#else + +/* +* Default implementation. +* Architectures that support secure boot must override this. +*/ +static inline bool arch_get_secureboot (void ) +{ +return false; +} + +#endif + +#endif
include/linux/secure_boot.h +1 -7
@@ -8,12 +8,6 @@#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 ); +#include <asm/secure_boot.h> #endif /* _LINUX_SECURE_BOOT_H */
security/integrity/Makefile +1 -1
@@ -5,7 +5,7 @@ obj-$(CONFIG_INTEGRITY) += integrity.o -integrity-y := iint.o secure_boot.o +integrity-y := iint.o integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o
security/integrity/platform_certs/load_powerpc.c +1 -1
@@ -10,7 +10,7 @@#include <linux/cred.h> #include <linux/err.h> #include <linux/slab.h> -#include <asm/secure_boot.h> +#include <linux/secure_boot.h> #include <asm/secvar.h> #include "keyring_handler.h" #include "../integrity.h"
security/integrity/secure_boot.c deleted +0 -16
@@ -1,16 +0,0 @@ -// 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.39.5
Quoted 23 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
security/integrity/secure_boot.cfile containing only a__weakfunction leads to a build failure with clang:Cannot find symbol for section 2: .text.
security/integrity/secure_boot.o: failedMoving the function into another file that has at least one non-__weak symbol would solve this, but this is always fragile.
Avoid
__weakdefinitions entirely and instead move the stub helper into an asm-generic header that gets used by default on architectures that do not provide their own version. This is consistent with how a lot of other architecture specific functionality works, and is more reliable.Fixes a0f87ede3bf4 ("integrity: Make arch_ima_get_secureboot integrity-wide")Signed-off-by Arnd Bergmann <[email protected]>---
This is a larger change than I had hoped for.If you prefer a different way to address the build failure, please treat this as a Reported-by when you apply your own fix
Quoted 14 lines
--- arch/powerpc/include/asm/secure_boot.h | 6 +++ arch/powerpc/kernel/secure_boot.c | 1 - arch/s390/include/asm/secure_boot.h | 9 +++++ include/asm-generic/Kbuild | 1 + include/asm-generic/secure_boot.h | 37 +++++++++++++++++++ include/linux/secure_boot.h | 8 +--- security/integrity/Makefile | 2 +- .../integrity/platform_certs/load_powerpc.c | 2 +- security/integrity/secure_boot.c | 16 -------- 9 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 arch/s390/include/asm/secure_boot.h create mode 100644 include/asm-generic/secure_boot.h delete mode 100644 security/integrity/secure_boot.c
Thanks, I noticed this as well. The version I came up with and have been locally testing is the following, which is a little bit more compact.
arch/Kconfig | 3 +++ arch/powerpc/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/s390/kernel/ipl.c | 10 +++++----- include/linux/secure_boot.h | 4 ++++ security/integrity/Makefile | 2 +- security/integrity/secure_boot.c | 16 ---------------- 7 files changed, 15 insertions(+), 22 deletions(-)
arch/Kconfig +3 -0
@@ -1841,4 +1841,7 @@ config ARCH_WANTS_PRE_LINK_VMLINUX config ARCH_HAS_CPU_ATTACK_VECTORS bool +config HAVE_ARCH_GET_SECUREBOOT + def_bool EFI + endmenu
arch/powerpc/Kconfig +1 -0
@@ -1062,6 +1062,7 @@ config PPC_SECURE_BOOT depends on IMA_ARCH_POLICY imply IMA_SECURE_AND_OR_TRUSTED_BOOT select PSERIES_PLPKS if PPC_PSERIES + select HAVE_ARCH_GET_SECUREBOOT 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/s390/Kconfig +1 -0
@@ -181,6 +181,7 @@ config S390 select GENERIC_IOREMAP if PCI select HAVE_ALIGNED_STRUCT_PAGE select HAVE_ARCH_AUDITSYSCALL + select HAVE_ARCH_GET_SECUREBOOT select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN
arch/s390/kernel/ipl.c +5 -5
@@ -2388,6 +2388,11 @@ void __no_stack_protector s390_reset_system(void) diag_amode31_ops.diag308_reset (); } +bool arch_get_secureboot (void ) +{ +return ipl_secure_flag; +} +#ifdef CONFIG_KEXEC_FILE int ipl_report_add_component(struct ipl_report *report, struct kexec_buf *kbuf,
@@ -2505,11 +2510,6 @@ 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;
include/linux/secure_boot.h +4 -0
@@ -10,10 +10,14 @@#include <linux/types.h> +#ifdef CONFIG_HAVE_ARCH_GET_SECUREBOOT /* * Returns true if the platform secure boot is enabled. * Returns false if disabled or not supported. */ bool arch_get_secureboot (void ); +#else +static inline bool arch_get_secureboot (void ) {return false; } +#endif #endif /* _LINUX_SECURE_BOOT_H */
security/integrity/Makefile +1 -1
@@ -5,7 +5,7 @@ obj-$(CONFIG_INTEGRITY) += integrity.o -integrity-y := iint.o secure_boot.o +integrity-y := iint.o integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o
security/integrity/secure_boot.c deleted +0 -16
@@ -1,16 +0,0 @@ -// 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; -}
Arnd Bergmann
maintainerQuoted 5 lines · Nathan Chancellor
On Fri, Mar 06, 2026 at 04:03:24PM +0100, Arnd Bergmann wrote:
Thanks, I noticed this as well. The version I came up with and have been locally testing is the following, which is a little bit more compact.
Quoted 9 lines
arch/Kconfig | 3 +++ arch/powerpc/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/s390/kernel/ipl.c | 10 +++++----- include/linux/secure_boot.h | 4 ++++ security/integrity/Makefile | 2 +- security/integrity/secure_boot.c | 16 ---------------- 7 files changed, 15 insertions(+), 22 deletions(-)
Right, your version looks good to me as well.
Arnd
Mimi Zohar
maintainerQuoted 39 lines · Nathan Chancellor
Quoted 23 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The
security/integrity/secure_boot.cfile containing only a__weakfunction leads to a build failure with clang:Cannot find symbol for section 2: .text.
security/integrity/secure_boot.o: failedMoving the function into another file that has at least one non-__weak symbol would solve this, but this is always fragile.
Avoid
__weakdefinitions entirely and instead move the stub helper into an asm-generic header that gets used by default on architectures that do not provide their own version. This is consistent with how a lot of other architecture specific functionality works, and is more reliable.Fixes a0f87ede3bf4 ("integrity: Make arch_ima_get_secureboot integrity-wide")Signed-off-by Arnd Bergmann <[email protected]>---
This is a larger change than I had hoped for.If you prefer a different way to address the build failure, please treat this as a Reported-by when you apply your own fix
Quoted 14 lines
--- arch/powerpc/include/asm/secure_boot.h | 6 +++ arch/powerpc/kernel/secure_boot.c | 1 - arch/s390/include/asm/secure_boot.h | 9 +++++ include/asm-generic/Kbuild | 1 + include/asm-generic/secure_boot.h | 37 +++++++++++++++++++ include/linux/secure_boot.h | 8 +--- security/integrity/Makefile | 2 +- .../integrity/platform_certs/load_powerpc.c | 2 +- security/integrity/secure_boot.c | 16 -------- 9 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 arch/s390/include/asm/secure_boot.h create mode 100644 include/asm-generic/secure_boot.h delete mode 100644 security/integrity/secure_boot.c
Quoted 2 lines
Thanks, I noticed this as well. The version I came up with and have been locally testing is the following, which is a little bit more compact.
Thanks Arnd, Nathan. LGTM. Nathan, could you send a patch with a proper patch description.
Mimi
Quoted 128 lines
arch/Kconfig | 3 +++ arch/powerpc/Kconfig | 1 + arch/s390/Kconfig | 1 + arch/s390/kernel/ipl.c | 10 +++++----- include/linux/secure_boot.h | 4 ++++ security/integrity/Makefile | 2 +- security/integrity/secure_boot.c | 16 ---------------- 7 files changed, 15 insertions(+), 22 deletions(-)arch/Kconfig +3
-0@@ -1841,4 +1841,7 @@ config ARCH_WANTS_PRE_LINK_VMLINUX config ARCH_HAS_CPU_ATTACK_VECTORS bool +config HAVE_ARCH_GET_SECUREBOOT + def_bool EFI + endmenuarch/powerpc/Kconfig +1
-0@@ -1062,6 +1062,7 @@ config PPC_SECURE_BOOT depends on IMA_ARCH_POLICY imply IMA_SECURE_AND_OR_TRUSTED_BOOT select PSERIES_PLPKS if PPC_PSERIES + select HAVE_ARCH_GET_SECUREBOOT help Systems with firmware secure boot enabled need to define security policies to extend secure boot to the OS. This config allows a userarch/s390/Kconfig +1
-0@@ -181,6 +181,7 @@ config S390 select GENERIC_IOREMAP if PCI select HAVE_ALIGNED_STRUCT_PAGE select HAVE_ARCH_AUDITSYSCALL + select HAVE_ARCH_GET_SECUREBOOT select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASANarch/s390/kernel/ipl.c +5
-5@@ -2388,6 +2388,11 @@ void __no_stack_protector s390_reset_system(void) diag_amode31_ops.diag308_reset (); } +bool arch_get_secureboot (void ) +{ +return ipl_secure_flag; +} +#ifdef CONFIG_KEXEC_FILE int ipl_report_add_component(struct ipl_report *report, struct kexec_buf *kbuf,@@ -2505,11 +2510,6 @@ 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;include/linux/secure_boot.h +4
-0@@ -10,10 +10,14 @@#include <linux/types.h> +#ifdef CONFIG_HAVE_ARCH_GET_SECUREBOOT /* * Returns true if the platform secure boot is enabled. * Returns false if disabled or not supported. */ bool arch_get_secureboot (void ); +#else +static inline bool arch_get_secureboot (void ) {return false; } +#endif #endif /* _LINUX_SECURE_BOOT_H */ security/integrity/Makefile +1
-1@@ -5,7 +5,7 @@ obj-$(CONFIG_INTEGRITY) += integrity.o -integrity-y := iint.o secure_boot.o +integrity-y := iint.o integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.osecurity/integrity/secure_boot.c deleted +0
-16@@ -1,16 +0,0 @@ -// 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; -}
Quoted 2 lines · Mimi Zohar
Thanks Arnd, Nathan. LGTM. Nathan, could you send a patch with a proper patch description.
Done, thanks for the input!
Cheers,
Nathan