2018-10-09 23:00:33 +05:30
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright ( C ) 2018 IBM Corporation
*/
# include <linux/efi.h>
2019-04-03 22:12:17 -04:00
# include <linux/module.h>
2018-10-09 23:00:33 +05:30
# include <linux/ima.h>
2020-10-30 14:08:39 +08:00
# include <asm/efi.h>
2018-10-09 23:00:33 +05:30
2020-10-30 14:08:39 +08:00
# ifndef arch_ima_efi_boot_mode
# define arch_ima_efi_boot_mode efi_secureboot_mode_unset
# endif
2018-10-09 23:00:33 +05:30
2018-11-18 04:08:12 -05:00
static enum efi_secureboot_mode get_sb_mode ( void )
{
2020-10-30 14:08:39 +08:00
enum efi_secureboot_mode mode ;
2018-11-18 04:08:12 -05:00
2020-01-23 13:09:35 +01:00
if ( ! efi_rt_services_supported ( EFI_RT_SUPPORTED_GET_VARIABLE ) ) {
2019-04-23 17:48:07 -05:00
pr_info ( " ima: secureboot mode unknown, no efi \n " ) ;
return efi_secureboot_mode_unknown ;
}
2020-10-30 14:08:39 +08:00
mode = efi_get_secureboot_mode ( efi . get_variable ) ;
if ( mode = = efi_secureboot_mode_disabled )
2018-11-18 04:08:12 -05:00
pr_info ( " ima: secureboot mode disabled \n " ) ;
2020-10-30 14:08:39 +08:00
else if ( mode = = efi_secureboot_mode_unknown )
2018-11-18 04:08:12 -05:00
pr_info ( " ima: secureboot mode unknown \n " ) ;
2020-10-30 14:08:39 +08:00
else
pr_info ( " ima: secureboot mode enabled \n " ) ;
return mode ;
2018-11-18 04:08:12 -05:00
}
2018-10-09 23:00:33 +05:30
bool arch_ima_get_secureboot ( void )
{
2018-11-18 04:08:12 -05:00
static enum efi_secureboot_mode sb_mode ;
static bool initialized ;
if ( ! initialized & & efi_enabled ( EFI_BOOT ) ) {
2020-10-30 14:08:39 +08:00
sb_mode = arch_ima_efi_boot_mode ;
2018-11-18 04:08:12 -05:00
if ( sb_mode = = efi_secureboot_mode_unset )
sb_mode = get_sb_mode ( ) ;
initialized = true ;
}
if ( sb_mode = = efi_secureboot_mode_enabled )
2018-10-09 23:00:33 +05:30
return true ;
else
return false ;
}
2018-10-09 23:00:37 +05:30
/* secureboot arch rules */
static const char * const sb_arch_rules [ ] = {
2019-08-19 17:17:44 -07:00
# if !IS_ENABLED(CONFIG_KEXEC_SIG)
2018-10-09 23:00:37 +05:30
" appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig " ,
2019-08-19 17:17:44 -07:00
# endif /* CONFIG_KEXEC_SIG */
2018-10-09 23:00:37 +05:30
" measure func=KEXEC_KERNEL_CHECK " ,
2019-01-27 19:03:45 -05:00
# if !IS_ENABLED(CONFIG_MODULE_SIG)
" appraise func=MODULE_CHECK appraise_type=imasig " ,
2023-07-26 10:08:05 +08:00
# endif
# if IS_ENABLED(CONFIG_INTEGRITY_MACHINE_KEYRING) && IS_ENABLED(CONFIG_IMA_KEYRINGS_PERMIT_SIGNED_BY_BUILTIN_OR_SECONDARY)
" appraise func=POLICY_CHECK appraise_type=imasig " ,
2019-01-27 19:03:45 -05:00
# endif
" measure func=MODULE_CHECK " ,
2018-10-09 23:00:37 +05:30
NULL
} ;
const char * const * arch_get_ima_policy ( void )
{
2019-01-27 19:03:45 -05:00
if ( IS_ENABLED ( CONFIG_IMA_ARCH_POLICY ) & & arch_ima_get_secureboot ( ) ) {
if ( IS_ENABLED ( CONFIG_MODULE_SIG ) )
set_module_sig_enforced ( ) ;
2022-07-13 15:21:11 +08:00
if ( IS_ENABLED ( CONFIG_KEXEC_SIG ) )
set_kexec_sig_enforced ( ) ;
2018-10-09 23:00:37 +05:30
return sb_arch_rules ;
2019-01-27 19:03:45 -05:00
}
2018-10-09 23:00:37 +05:30
return NULL ;
}