add ima_arch support for ARM64
Subsystems (4)
v2 cover add ima_arch support for ARM64
Add IMA arch dependent support for ARM64. Some IMA functions can check arch-specific status before running. For example, the ima_load_data function or the boot param "ima_appraise=" should not be executed when UEFI secure boot is enabled. We want to fill the gap in order to complete the IMA support on ARM64.
Changes in v2:
- Separate get_sb_mode() from x86 so all EFI-based architectures can reuse the same function.
- Refactor arch/arm64/kernel/ima_arch.c based on Ard's patch[1].
Test platforms:
- QEMU [aarch64-virt] + EDK2/OVMF
- NXP LX2160A-RDB + EDK2
[1] https://www.spinics.net/lists/linux-efi/msg20645.html
Chester Lin (2):
efi: add secure boot get helper
arm64/ima: add ima_arch support
arch/arm64/Kconfig | 1 + arch/arm64/kernel/Makefile | 2 ++ arch/arm64/kernel/ima_arch.c | 46 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/ima_arch.c | 47 ++---------------------------------- drivers/firmware/efi/efi.c | 43 +++++++++++++++++++++++++++++++++ include/linux/efi.h | 5 ++++ 6 files changed, 99 insertions(+), 45 deletions(-) create mode 100644 arch/arm64/kernel/ima_arch.c
Signature · 1 line
2.26.1
PATCH v2 1/2 efi: add secure boot get helper
Separate the get_sb_mode() from arch/x86 and treat it as a common function [rename to efi_get_secureboot_mode] so all EFI-based architectures can reuse the same logic.
--- arch/x86/kernel/ima_arch.c | 47 ++------------------------------------ drivers/firmware/efi/efi.c | 43 ++++++++++++++++++++++++++++++++++ include/linux/efi.h | 5 ++++ 3 files changed, 50 insertions(+), 45 deletions(-)
arch/x86/kernel/ima_arch.c +2 -45
@@ -8,49 +8,6 @@extern struct boot_params boot_params; -static enum efi_secureboot_mode get_sb_mode (void ) -{ -efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; -efi_status_t status; -unsigned long size; -u8 secboot, setupmode; - - size =sizeof (secboot); - -if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { -pr_info ("ima: secureboot mode unknown, no efi\n" ); -return efi_secureboot_mode_unknown; - } - -/* Get variable contents into buffer */ - status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, -NULL , &size, &secboot); -if (status ==EFI_NOT_FOUND ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -if (status !=EFI_SUCCESS ) { -pr_info ("ima: secureboot mode unknown\n" ); -return efi_secureboot_mode_unknown; - } - - size =sizeof (setupmode); - status = efi.get_variable (L"SetupMode" , &efi_variable_guid, -NULL , &size, &setupmode); - -if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ - setupmode =0 ; - -if (secboot ==0 || setupmode ==1 ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -pr_info ("ima: secureboot mode enabled\n" ); -return efi_secureboot_mode_enabled; -} -bool arch_ima_get_secureboot (void ) {static enum efi_secureboot_mode sb_mode;
@@ -60,7 +17,7 @@ bool arch_ima_get_secureboot(void) sb_mode = boot_params.secure_boot;if (sb_mode == efi_secureboot_mode_unset) - sb_mode =get_sb_mode (); + sb_mode =efi_get_secureboot_mode (); initialized = true; }
@@ -70,7 +27,7 @@ bool arch_ima_get_secureboot(void)return false; } -/* secureboot arch rules */ +/* secure and trusted boot arch rules */ static const char *const sb_arch_rules[] = { #if !IS_ENABLED(CONFIG_KEXEC_SIG) "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",
drivers/firmware/efi/efi.c +43 -0
46 lines not on this page · raw message
include/linux/efi.h +5 -0
@@ -1076,8 +1076,13 @@ static inline int efi_runtime_map_copy(void *buf, size_t bufsz)#ifdef CONFIG_EFI extern bool efi_runtime_disabled (void ); +extern enum efi_secureboot_mode efi_get_secureboot_mode (void );#else static inline bool efi_runtime_disabled (void ) {return true; } +static inline enum efi_secureboot_mode efi_get_secureboot_mode (void ) +{ +return efi_secureboot_mode_disabled; +}#endif extern void efi_call_virt_check_flags (unsigned long flags,const char *call);
Signature · 1 line
2.26.1
PATCH v2 2/2 arm64/ima: add ima_arch support
In reply to Chester LinAdd arm64 IMA arch support. The code and arch policy is mainly inherited from x86.
--- arch/arm64/Kconfig | 1 + arch/arm64/kernel/Makefile | 2 ++ arch/arm64/kernel/ima_arch.c | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 arch/arm64/kernel/ima_arch.c
arch/arm64/Kconfig +1 -0
@@ -199,6 +199,7 @@ config ARM64 select SWIOTLB select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK + imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI help ARM 64-bit (AArch64) Linux support.
arch/arm64/kernel/Makefile +2 -0
@@ -69,3 +69,5 @@ extra-y += $(head-y) vmlinux.lds ifeq ($(CONFIG_DEBUG_EFI),y) AFLAGS_head.o += -DVMLINUX_PATH="\"$(realpath $(objtree)/vmlinux)\"" endif + +obj-$(CONFIG_IMA_SECURE_AND_OR_TRUSTED_BOOT) += ima_arch.o
arch/arm64/kernel/ima_arch.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.26.1
Re: [PATCH v2 1/2] efi: add secure boot get helper
In reply to Chester LinHi Ard and Mimi,
drivers/firmware/efi/efi.c
Quoted 87 lines · Chester Lin
Separate the
get_sb_mode()fromarch/x86and treat it as a common function [rename toefi_get_secureboot_mode] so all EFI-based architectures can reuse the same logic.Signed-off-by Chester Lin <[email protected]>--- arch/x86/kernel/ima_arch.c | 47 ++------------------------------------ drivers/firmware/efi/efi.c | 43 ++++++++++++++++++++++++++++++++++ include/linux/efi.h | 5 ++++ 3 files changed, 50 insertions(+), 45 deletions(-)arch/x86/kernel/ima_arch.c +2
-45@@ -8,49 +8,6 @@extern struct boot_params boot_params; -static enum efi_secureboot_mode get_sb_mode (void ) -{ -efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; -efi_status_t status; -unsigned long size; -u8 secboot, setupmode; - - size =sizeof (secboot); - -if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { -pr_info ("ima: secureboot mode unknown, no efi\n" ); -return efi_secureboot_mode_unknown; - } - -/* Get variable contents into buffer */ - status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, -NULL , &size, &secboot); -if (status ==EFI_NOT_FOUND ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -if (status !=EFI_SUCCESS ) { -pr_info ("ima: secureboot mode unknown\n" ); -return efi_secureboot_mode_unknown; - } - - size =sizeof (setupmode); - status = efi.get_variable (L"SetupMode" , &efi_variable_guid, -NULL , &size, &setupmode); - -if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ - setupmode =0 ; - -if (secboot ==0 || setupmode ==1 ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -pr_info ("ima: secureboot mode enabled\n" ); -return efi_secureboot_mode_enabled; -} -bool arch_ima_get_secureboot (void ) {static enum efi_secureboot_mode sb_mode;@@ -60,7 +17,7 @@ bool arch_ima_get_secureboot(void) sb_mode = boot_params.secure_boot;if (sb_mode == efi_secureboot_mode_unset) - sb_mode =get_sb_mode (); + sb_mode =efi_get_secureboot_mode (); initialized = true; }@@ -70,7 +27,7 @@ bool arch_ima_get_secureboot(void)return false; } -/* secureboot arch rules */ +/* secure and trusted boot arch rules */ static const char *const sb_arch_rules[] = { #if !IS_ENABLED(CONFIG_KEXEC_SIG) "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",drivers/firmware/efi/efi.c +0
-0
I hope you don't mind that I temporarily move the get_sb_mode() to efi since I'm not sure which place is better. Please let me know if any suggestions.
Thanks,
Chester
Quoted 68 lines
drivers/firmware/efi/efi.c +43
-0@@ -1022,3 +1022,46 @@ static int __init register_update_efi_random_seed(void) }late_initcall (register_update_efi_random_seed);#endif + +enum efi_secureboot_mode efi_get_secureboot_mode (void ) +{ +efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size; +u8 secboot, setupmode; + + size =sizeof (secboot); + +if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { +pr_info ("ima: secureboot mode unknown, no efi\n" ); +return efi_secureboot_mode_unknown; + } + +/* Get variable contents into buffer */ + status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, +NULL , &size, &secboot); +if (status ==EFI_NOT_FOUND ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +if (status !=EFI_SUCCESS ) { +pr_info ("ima: secureboot mode unknown\n" ); +return efi_secureboot_mode_unknown; + } + + size =sizeof (setupmode); + status = efi.get_variable (L"SetupMode" , &efi_variable_guid, +NULL , &size, &setupmode); + +if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ + setupmode =0 ; + +if (secboot ==0 || setupmode ==1 ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +pr_info ("ima: secureboot mode enabled\n" ); +return efi_secureboot_mode_enabled; +}include/linux/efi.h +5
-0@@ -1076,8 +1076,13 @@ static inline int efi_runtime_map_copy(void *buf, size_t bufsz)#ifdef CONFIG_EFI extern bool efi_runtime_disabled (void ); +extern enum efi_secureboot_mode efi_get_secureboot_mode (void );#else static inline bool efi_runtime_disabled (void ) {return true; } +static inline enum efi_secureboot_mode efi_get_secureboot_mode (void ) +{ +return efi_secureboot_mode_disabled; +}#endif extern void efi_call_virt_check_flags (unsigned long flags,const char *call);Signature · 1 line
2.26.1
Ard Biesheuvel
maintainerRe: [PATCH v2 1/2] efi: add secure boot get helper
In reply to Chester LinHello Chester,
Thanks for looking into this.
Some comments below.
Quoted 94 lines · Chester Lin
Separate the
get_sb_mode()fromarch/x86and treat it as a common function [rename toefi_get_secureboot_mode] so all EFI-based architectures can reuse the same logic.Signed-off-by Chester Lin <[email protected]>--- arch/x86/kernel/ima_arch.c | 47 ++------------------------------------ drivers/firmware/efi/efi.c | 43 ++++++++++++++++++++++++++++++++++ include/linux/efi.h | 5 ++++ 3 files changed, 50 insertions(+), 45 deletions(-)arch/x86/kernel/ima_arch.c +2
-45@@ -8,49 +8,6 @@extern struct boot_params boot_params; -static enum efi_secureboot_mode get_sb_mode (void ) -{ -efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; -efi_status_t status; -unsigned long size; -u8 secboot, setupmode; - - size =sizeof (secboot); - -if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { -pr_info ("ima: secureboot mode unknown, no efi\n" ); -return efi_secureboot_mode_unknown; - } - -/* Get variable contents into buffer */ - status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, -NULL , &size, &secboot); -if (status ==EFI_NOT_FOUND ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -if (status !=EFI_SUCCESS ) { -pr_info ("ima: secureboot mode unknown\n" ); -return efi_secureboot_mode_unknown; - } - - size =sizeof (setupmode); - status = efi.get_variable (L"SetupMode" , &efi_variable_guid, -NULL , &size, &setupmode); - -if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ - setupmode =0 ; - -if (secboot ==0 || setupmode ==1 ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -pr_info ("ima: secureboot mode enabled\n" ); -return efi_secureboot_mode_enabled; -} -bool arch_ima_get_secureboot (void ) {static enum efi_secureboot_mode sb_mode;@@ -60,7 +17,7 @@ bool arch_ima_get_secureboot(void) sb_mode = boot_params.secure_boot;if (sb_mode == efi_secureboot_mode_unset) - sb_mode =get_sb_mode (); + sb_mode =efi_get_secureboot_mode (); initialized = true; }@@ -70,7 +27,7 @@ bool arch_ima_get_secureboot(void)return false; } -/* secureboot arch rules */ +/* secure and trusted boot arch rules */ static const char *const sb_arch_rules[] = { #if !IS_ENABLED(CONFIG_KEXEC_SIG) "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",drivers/firmware/efi/efi.c +2
-0@@ -1022,3 +1022,46 @@ static int __init register_update_efi_random_seed(void) }late_initcall (register_update_efi_random_seed);#endif + +enum efi_secureboot_mode efi_get_secureboot_mode (void )
drivers/firmware/efi/efi.c static int __init register_update_efi_random_seed(void) · line 1036
Quoted 10 lines
drivers/firmware/efi/efi.c +10
-0+{ +efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size; +u8 secboot, setupmode; + + size =sizeof (secboot); + +if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { +pr_info ("ima: secureboot mode unknown, no efi\n" );
These prints don't belong here anymore.
Also, it would be useful if we could reuse this logic in the EFI stub as well, which is built as a separate executable, and does not provide efi.get_variable().
So, you could you please break this up into
static inline
enum efi_secureboot_mode efi_get_secureboot_mode(efi_get_variable_t *get_var) {
}
placed into include/linux/efi.h, which encapsulates the core logic, but using get_var(), and without the prints.
Then, we could put something like
bool efi_ima_get_secureboot(void)
{
}
in drivers/firmware/efi/efi.c (guarded by #ifdef CONFIG_IMA_xxx), which performs the efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) check, calls efi_get_secureboot_mode(efi.get_variable), and implements the logic.
And actually, if the logic is identical between x86 and arm64, I wonder if it wouldn't be better to put the whole thing into
drivers/firmware/efi/efi-ima.c
or
security/integrity/ima/ima-efi.c
with the only difference being the boot_params->secure_boot access for x86, which we can factor out to a static inline helper.
Mimi, any thoughts here?
Quoted 52 lines
drivers/firmware/efi/efi.c +31
-0+return efi_secureboot_mode_unknown; + } + +/* Get variable contents into buffer */ + status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, +NULL , &size, &secboot); +if (status ==EFI_NOT_FOUND ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +if (status !=EFI_SUCCESS ) { +pr_info ("ima: secureboot mode unknown\n" ); +return efi_secureboot_mode_unknown; + } + + size =sizeof (setupmode); + status = efi.get_variable (L"SetupMode" , &efi_variable_guid, +NULL , &size, &setupmode); + +if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ + setupmode =0 ; + +if (secboot ==0 || setupmode ==1 ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +pr_info ("ima: secureboot mode enabled\n" ); +return efi_secureboot_mode_enabled; +}include/linux/efi.h +5
-1@@ -1076,8 +1076,13 @@ static inline int efi_runtime_map_copy(void *buf, size_t bufsz)#ifdef CONFIG_EFI extern bool efi_runtime_disabled (void ); +extern enum efi_secureboot_mode efi_get_secureboot_mode (void );#else static inline bool efi_runtime_disabled (void ) {return true; } +static inline enum efi_secureboot_mode efi_get_secureboot_mode (void ) +{ +return efi_secureboot_mode_disabled; +}#endif extern void efi_call_virt_check_flags (unsigned long flags,const char *call); --2.26.1
Mimi Zohar
maintainerRe: [PATCH v2 1/2] efi: add secure boot get helper
Quoted 144 lines · Ard Biesheuvel
Hello Chester,
Thanks for looking into this.
Some comments below.
Quoted 94 lines · Chester Lin
Separate the
get_sb_mode()fromarch/x86and treat it as a common function [rename toefi_get_secureboot_mode] so all EFI-based architectures can reuse the same logic.Signed-off-by Chester Lin <[email protected]>--- arch/x86/kernel/ima_arch.c | 47 ++------------------------------------ drivers/firmware/efi/efi.c | 43 ++++++++++++++++++++++++++++++++++ include/linux/efi.h | 5 ++++ 3 files changed, 50 insertions(+), 45 deletions(-)arch/x86/kernel/ima_arch.c +2
-45@@ -8,49 +8,6 @@extern struct boot_params boot_params; -static enum efi_secureboot_mode get_sb_mode (void ) -{ -efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; -efi_status_t status; -unsigned long size; -u8 secboot, setupmode; - - size =sizeof (secboot); - -if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { -pr_info ("ima: secureboot mode unknown, no efi\n" ); -return efi_secureboot_mode_unknown; - } - -/* Get variable contents into buffer */ - status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, -NULL , &size, &secboot); -if (status ==EFI_NOT_FOUND ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -if (status !=EFI_SUCCESS ) { -pr_info ("ima: secureboot mode unknown\n" ); -return efi_secureboot_mode_unknown; - } - - size =sizeof (setupmode); - status = efi.get_variable (L"SetupMode" , &efi_variable_guid, -NULL , &size, &setupmode); - -if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ - setupmode =0 ; - -if (secboot ==0 || setupmode ==1 ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -pr_info ("ima: secureboot mode enabled\n" ); -return efi_secureboot_mode_enabled; -} -bool arch_ima_get_secureboot (void ) {static enum efi_secureboot_mode sb_mode;@@ -60,7 +17,7 @@ bool arch_ima_get_secureboot(void) sb_mode = boot_params.secure_boot;if (sb_mode == efi_secureboot_mode_unset) - sb_mode =get_sb_mode (); + sb_mode =efi_get_secureboot_mode (); initialized = true; }@@ -70,7 +27,7 @@ bool arch_ima_get_secureboot(void)return false; } -/* secureboot arch rules */ +/* secure and trusted boot arch rules */ static const char *const sb_arch_rules[] = { #if !IS_ENABLED(CONFIG_KEXEC_SIG) "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",drivers/firmware/efi/efi.c +2
-0@@ -1022,3 +1022,46 @@ static int __init register_update_efi_random_seed(void) }late_initcall (register_update_efi_random_seed);#endif + +enum efi_secureboot_mode efi_get_secureboot_mode (void )drivers/firmware/efi/efi.c static int __init register_update_efi_random_seed(void) · line 1036
Quoted 10 lines
drivers/firmware/efi/efi.c +10
-0+{ +efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size; +u8 secboot, setupmode; + + size =sizeof (secboot); + +if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { +pr_info ("ima: secureboot mode unknown, no efi\n" );These prints don't belong here anymore.
Also, it would be useful if we could reuse this logic in the EFI stub as well, which is built as a separate executable, and does not provide
efi.get_variable().So, you could you please break this up into
static inline
enumefi_secureboot_modeefi_get_secureboot_mode(efi_get_variable_t *get_var){
}placed into
include/linux/efi.h, which encapsulates the core logic, but usingget_var(), and without the prints.Then, we could put something like
bool
efi_ima_get_secureboot(void)
{
}in
drivers/firmware/efi/efi.c(guarded by #ifdefCONFIG_IMA_xxx), which performs theefi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) check, callsefi_get_secureboot_mode(efi.get_variable), and implements the logic.And actually, if the logic is identical between x86 and arm64, I wonder if it wouldn't be better to put the whole thing into
drivers/firmware/efi/efi-ima.c
Quoted 8 lines
or
security/integrity/ima/ima-efi.cwith the only difference being the
boot_params->secure_bootaccess for x86, which we can factor out to a static inline helper.Mimi, any thoughts here?
Sounds good. Keeping as much IMA code in the IMA directory makes
sense. The IMA Makefile would then include ima-efi.c based on an EFIKconfig option.
thanks,
Mimi
Quoted 55 lines
Quoted 55 lines
drivers/firmware/efi/efi.c +31
-0+return efi_secureboot_mode_unknown; + } + +/* Get variable contents into buffer */ + status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, +NULL , &size, &secboot); +if (status ==EFI_NOT_FOUND ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +if (status !=EFI_SUCCESS ) { +pr_info ("ima: secureboot mode unknown\n" ); +return efi_secureboot_mode_unknown; + } + + size =sizeof (setupmode); + status = efi.get_variable (L"SetupMode" , &efi_variable_guid, +NULL , &size, &setupmode); + +if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ + setupmode =0 ; + +if (secboot ==0 || setupmode ==1 ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +pr_info ("ima: secureboot mode enabled\n" ); +return efi_secureboot_mode_enabled; +}include/linux/efi.h +5
-1@@ -1076,8 +1076,13 @@ static inline int efi_runtime_map_copy(void *buf, size_t bufsz)#ifdef CONFIG_EFI extern bool efi_runtime_disabled (void ); +extern enum efi_secureboot_mode efi_get_secureboot_mode (void );#else static inline bool efi_runtime_disabled (void ) {return true; } +static inline enum efi_secureboot_mode efi_get_secureboot_mode (void ) +{ +return efi_secureboot_mode_disabled; +}#endif extern void efi_call_virt_check_flags (unsigned long flags,const char *call); --2.26.1
kernel test robot
build botRe: [PATCH v2 1/2] efi: add secure boot get helper
In reply to Chester LinThank you for the patch! Yet something to improve:
Hi Chester,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on efi/next tip/x86/core v5.9 next-20201013] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Chester-Lin/add-ima_arch-support-for-ARM64/20201014-184221 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: i386-randconfig-a005-20201014 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/d88d2474c8dbc487055a897d379568b92bb3666e git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Chester-Lin/add-ima_arch-support-for-ARM64/20201014-184221 git checkout d88d2474c8dbc487055a897d379568b92bb3666e # save the attached .config to linux build tree make W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from arch/x86/kernel/asm-offsets_32.c:6,
from arch/x86/kernel/asm-offsets.c:27:
>> include/linux/efi.h:1090:40: error: return type is an incomplete type
1090 | static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/efi.h: In function 'efi_get_secureboot_mode':
>> include/linux/efi.h:1092:9: error: 'efi_secureboot_mode_disabled' undeclared (first use in this function); did you mean 'efi_secureboot_mode'?
1092 | return efi_secureboot_mode_disabled;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| efi_secureboot_mode include/linux/efi.h:1092:9: note: each undeclared identifier is reported only once for each function it appears in include/linux/efi.h:1092:9: warning: 'return' with a value, in function returning void [-Wreturn-type] include/linux/efi.h:1090:40: note: declared here
1090 | static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
| ^~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:117: arch/x86/kernel/asm-offsets.s] Error 1
make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1202: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:185: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +1090 include/linux/efi.h
1084
1085 #ifdef CONFIG_EFI
1086 extern bool efi_runtime_disabled(void);
1087 extern enum efi_secureboot_mode efi_get_secureboot_mode(void);
1088 #else
1089 static inline bool efi_runtime_disabled(void) { return true; }
> 1090 static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
1091 {
> 1092 return efi_secureboot_mode_disabled; 1093 }
1094 #endif
1095
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v2 1/2] efi: add secure boot get helper
In reply to Chester LinThank you for the patch! Yet something to improve:
Hi Chester,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on efi/next tip/x86/core v5.9 next-20201013] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Chester-Lin/add-ima_arch-support-for-ARM64/20201014-184221 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: x86_64-randconfig-r003-20201014 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project e7fe3c6dfede8d5781bd000741c3dea7088307a4)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/d88d2474c8dbc487055a897d379568b92bb3666e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Chester-Lin/add-ima_arch-support-for-ARM64/20201014-184221 git checkout d88d2474c8dbc487055a897d379568b92bb3666e
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from arch/x86/mm/fault.c:19:
>> include/linux/efi.h:1090:40: error: incomplete result type 'enum efi_secureboot_mode' in function definition
static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
^
include/linux/efi.h:1090:20: note: forward declaration of 'enum efi_secureboot_mode'
static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
^
>> include/linux/efi.h:1092:9: error: use of undeclared identifier 'efi_secureboot_mode_disabled'
return efi_secureboot_mode_disabled;
^
2 errors generated.
--
In file included from arch/x86/mm/ioremap.c:18:
>> include/linux/efi.h:1090:40: error: incomplete result type 'enum efi_secureboot_mode' in function definition
static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
^
include/linux/efi.h:1090:20: note: forward declaration of 'enum efi_secureboot_mode'
static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
^
>> include/linux/efi.h:1092:9: error: use of undeclared identifier 'efi_secureboot_mode_disabled'
return efi_secureboot_mode_disabled;
^
arch/x86/mm/ioremap.c:737:17: warning: no previous prototype for function 'early_memremap_pgprot_adjust' [-Wmissing-prototypes]
pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
^ arch/x86/mm/ioremap.c:737:1: note: declare 'static' if the function is not intended to be used outside of this translation unit pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
^
static
1 warning and 2 errors generated.
vim +1090 include/linux/efi.h
1084
1085 #ifdef CONFIG_EFI
1086 extern bool efi_runtime_disabled(void);
1087 extern enum efi_secureboot_mode efi_get_secureboot_mode(void);
1088 #else
1089 static inline bool efi_runtime_disabled(void) { return true; }
> 1090 static inline enum efi_secureboot_mode efi_get_secureboot_mode(void)
1091 {
> 1092 return efi_secureboot_mode_disabled; 1093 }
1094 #endif
1095
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v2 1/2] efi: add secure boot get helper
In reply to Mimi ZoharHi Ard and Mimi,
Quoted 154 lines · Mimi Zohar
Quoted 144 lines · Ard Biesheuvel
Hello Chester,
Thanks for looking into this.
Some comments below.
Quoted 94 lines · Chester Lin
Separate the
get_sb_mode()fromarch/x86and treat it as a common function [rename toefi_get_secureboot_mode] so all EFI-based architectures can reuse the same logic.Signed-off-by Chester Lin <[email protected]>--- arch/x86/kernel/ima_arch.c | 47 ++------------------------------------ drivers/firmware/efi/efi.c | 43 ++++++++++++++++++++++++++++++++++ include/linux/efi.h | 5 ++++ 3 files changed, 50 insertions(+), 45 deletions(-)arch/x86/kernel/ima_arch.c +2
-45@@ -8,49 +8,6 @@extern struct boot_params boot_params; -static enum efi_secureboot_mode get_sb_mode (void ) -{ -efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; -efi_status_t status; -unsigned long size; -u8 secboot, setupmode; - - size =sizeof (secboot); - -if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { -pr_info ("ima: secureboot mode unknown, no efi\n" ); -return efi_secureboot_mode_unknown; - } - -/* Get variable contents into buffer */ - status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, -NULL , &size, &secboot); -if (status ==EFI_NOT_FOUND ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -if (status !=EFI_SUCCESS ) { -pr_info ("ima: secureboot mode unknown\n" ); -return efi_secureboot_mode_unknown; - } - - size =sizeof (setupmode); - status = efi.get_variable (L"SetupMode" , &efi_variable_guid, -NULL , &size, &setupmode); - -if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ - setupmode =0 ; - -if (secboot ==0 || setupmode ==1 ) { -pr_info ("ima: secureboot mode disabled\n" ); -return efi_secureboot_mode_disabled; - } - -pr_info ("ima: secureboot mode enabled\n" ); -return efi_secureboot_mode_enabled; -} -bool arch_ima_get_secureboot (void ) {static enum efi_secureboot_mode sb_mode;@@ -60,7 +17,7 @@ bool arch_ima_get_secureboot(void) sb_mode = boot_params.secure_boot;if (sb_mode == efi_secureboot_mode_unset) - sb_mode =get_sb_mode (); + sb_mode =efi_get_secureboot_mode (); initialized = true; }@@ -70,7 +27,7 @@ bool arch_ima_get_secureboot(void)return false; } -/* secureboot arch rules */ +/* secure and trusted boot arch rules */ static const char *const sb_arch_rules[] = { #if !IS_ENABLED(CONFIG_KEXEC_SIG) "appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig",drivers/firmware/efi/efi.c +2
-0@@ -1022,3 +1022,46 @@ static int __init register_update_efi_random_seed(void) }late_initcall (register_update_efi_random_seed);#endif + +enum efi_secureboot_mode efi_get_secureboot_mode (void )drivers/firmware/efi/efi.c static int __init register_update_efi_random_seed(void) · line 1036
Quoted 10 lines
drivers/firmware/efi/efi.c +10
-0+{ +efi_guid_t efi_variable_guid =EFI_GLOBAL_VARIABLE_GUID ; +efi_status_t status; +unsigned long size; +u8 secboot, setupmode; + + size =sizeof (secboot); + +if (!efi_rt_services_supported (EFI_RT_SUPPORTED_GET_VARIABLE )) { +pr_info ("ima: secureboot mode unknown, no efi\n" );These prints don't belong here anymore.
Also, it would be useful if we could reuse this logic in the EFI stub as well, which is built as a separate executable, and does not provide
efi.get_variable().So, you could you please break this up into
static inline
enumefi_secureboot_modeefi_get_secureboot_mode(efi_get_variable_t *get_var){
}placed into
include/linux/efi.h, which encapsulates the core logic, but usingget_var(), and without the prints.Then, we could put something like
bool
efi_ima_get_secureboot(void)
{
}in
drivers/firmware/efi/efi.c(guarded by #ifdefCONFIG_IMA_xxx), which performs theefi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) check, callsefi_get_secureboot_mode(efi.get_variable), and implements the logic.And actually, if the logic is identical between x86 and arm64, I wonder if it wouldn't be better to put the whole thing into
drivers/firmware/efi/efi-ima.cQuoted 8 lines
or
security/integrity/ima/ima-efi.cwith the only difference being the
boot_params->secure_bootaccess for x86, which we can factor out to a static inline helper.Mimi, any thoughts here?
Quoted 7 lines
Sounds good. Keeping as much IMA code in the IMA directory makes
sense. The IMAMakefilewould then includeima-efi.cbased on an EFIKconfigoption.thanks,
Mimi
Thanks for your suggestions. I will include them in v3.
Regards,
Chester
Quoted 57 lines
Quoted 55 lines
Quoted 55 lines
drivers/firmware/efi/efi.c +31
-0+return efi_secureboot_mode_unknown; + } + +/* Get variable contents into buffer */ + status = efi.get_variable (L"SecureBoot" , &efi_variable_guid, +NULL , &size, &secboot); +if (status ==EFI_NOT_FOUND ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +if (status !=EFI_SUCCESS ) { +pr_info ("ima: secureboot mode unknown\n" ); +return efi_secureboot_mode_unknown; + } + + size =sizeof (setupmode); + status = efi.get_variable (L"SetupMode" , &efi_variable_guid, +NULL , &size, &setupmode); + +if (status !=EFI_SUCCESS )/* ignore unknown SetupMode */ + setupmode =0 ; + +if (secboot ==0 || setupmode ==1 ) { +pr_info ("ima: secureboot mode disabled\n" ); +return efi_secureboot_mode_disabled; + } + +pr_info ("ima: secureboot mode enabled\n" ); +return efi_secureboot_mode_enabled; +}include/linux/efi.h +5
-1@@ -1076,8 +1076,13 @@ static inline int efi_runtime_map_copy(void *buf, size_t bufsz)#ifdef CONFIG_EFI extern bool efi_runtime_disabled (void ); +extern enum efi_secureboot_mode efi_get_secureboot_mode (void );#else static inline bool efi_runtime_disabled (void ) {return true; } +static inline enum efi_secureboot_mode efi_get_secureboot_mode (void ) +{ +return efi_secureboot_mode_disabled; +}#endif extern void efi_call_virt_check_flags (unsigned long flags,const char *call); --2.26.1