lib/tst_lockdown.c: Add PPC64 architecture support
PATCH 1/1 lib/tst_lockdown.c: Add PPC64 architecture support
Add PPC64 architecture support to the lockdown library.
--- lib/tst_lockdown.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)
lib/tst_lockdown.c +27 -7
@@ -14,33 +14,46 @@#include "tst_lockdown.h" #include "tst_private.h" -#define EFIVAR_SECUREBOOT "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" - +#if defined(__powerpc64__) || defined(__ppc64__) +#define SECUREBOOT_VAR "/proc/device-tree/ibm,secure-boot" +#else +#define SECUREBOOT_VAR "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" +#endif int tst_secureboot_enabled (void ) {int fd;char data[5 ]; -if (access (EFIVAR_SECUREBOOT ,F_OK )) { -tst_res (TINFO ,"Efivar FS not available" ); +if (access (SECUREBOOT_VAR ,F_OK )) { +tst_res (TINFO ,"SecureBoot sysfs file not available" );return -1 ; } - fd =open (EFIVAR_SECUREBOOT ,O_RDONLY ); + fd =open (SECUREBOOT_VAR ,O_RDONLY );if (fd ==-1 ) {tst_res (TINFO |TERRNO , -"Cannot open SecureBoot Efivar sysfile" ); +"Cannot open SecureBoot file" );return -1 ; }else if (fd <0 ) {tst_brk (TBROK |TERRNO ,"Invalid open() return value %d" , fd);return -1 ; } - +#if defined(__powerpc64__) || defined(__ppc64__) +SAFE_READ (1 , fd, data,4 ); +#else SAFE_READ (1 , fd, data,5 ); +#endif +SAFE_CLOSE (fd); + +#if defined(__powerpc64__) || defined(__ppc64__) +tst_res (TINFO ,"SecureBoot: %s" , data[3 ] ?"on" :"off" ); +return data[3 ]; +#else tst_res (TINFO ,"SecureBoot: %s" , data[4 ] ?"on" :"off" );return data[4 ]; +#endif }int tst_lockdown_enabled (void )
@@ -51,9 +64,16 @@ int tst_lockdown_enabled(void)if (access (PATH_LOCKDOWN ,F_OK ) !=0 ) {char flag; +/* SecureBoot enabled could mean integrity lockdown (non-mainline version) */ +#if defined(__powerpc64__) || defined(__ppc64__) + flag =tst_kconfig_get ("CONFIG_SECURITY_LOCKDOWN_LSM" ) =='y' ; + flag |=tst_kconfig_get ("CONFIG_SECURITY_LOCKDOWN_LSM_EARLY" ) =='y' ; +#else flag =tst_kconfig_get ("CONFIG_EFI_SECURE_BOOT_LOCK_DOWN" ) =='y' ; flag |=tst_kconfig_get ("CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT" ) =='y' ; +#endif +if (flag &&tst_secureboot_enabled () >0 )return 1 ;
Signature · 5 lines
2.37.1 (Apple Git-137.1) -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 3 lines · Nageswara R Sastry
Add PPC64 architecture support to the lockdown library.
Signed-off-by Nageswara R Sastry <[email protected]>
Tested with and with out Secure boot enabled on PPC64LE system.
Ran testcases named:finit_module01 finit_module01finit_module02 finit_module02
With secure boot disabled:
...
tst_lockdown.c:90: TINFO: Kernel lockdown: off
tst_lockdown.c:51: TINFO: SecureBoot: off
…
Summary:
passed 10 failed 0 broken 0 skipped 0
warnings 0
With secure boot enabled:
...
tst_lockdown.c:90: TINFO: Kernel lockdown: on
tst_lockdown.c:51: TINFO: SecureBoot: on
…
Summary:
passed 7 failed 0 broken 0 skipped 3
warnings 0
Quoted 79 lines
--- lib/tst_lockdown.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-)lib/tst_lockdown.c +27
-7@@ -14,33 +14,46 @@#include "tst_lockdown.h" #include "tst_private.h" -#define EFIVAR_SECUREBOOT "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" - +#if defined(__powerpc64__) || defined(__ppc64__) +#define SECUREBOOT_VAR "/proc/device-tree/ibm,secure-boot" +#else +#define SECUREBOOT_VAR "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" +#endif int tst_secureboot_enabled (void ) {int fd;char data[5 ]; -if (access (EFIVAR_SECUREBOOT ,F_OK )) { -tst_res (TINFO ,"Efivar FS not available" ); +if (access (SECUREBOOT_VAR ,F_OK )) { +tst_res (TINFO ,"SecureBoot sysfs file not available" );return -1 ; } - fd =open (EFIVAR_SECUREBOOT ,O_RDONLY ); + fd =open (SECUREBOOT_VAR ,O_RDONLY );if (fd ==-1 ) {tst_res (TINFO |TERRNO , -"Cannot open SecureBoot Efivar sysfile" ); +"Cannot open SecureBoot file" );return -1 ; }else if (fd <0 ) {tst_brk (TBROK |TERRNO ,"Invalid open() return value %d" , fd);return -1 ; } - +#if defined(__powerpc64__) || defined(__ppc64__) +SAFE_READ (1 , fd, data,4 ); +#else SAFE_READ (1 , fd, data,5 ); +#endif +SAFE_CLOSE (fd); + +#if defined(__powerpc64__) || defined(__ppc64__) +tst_res (TINFO ,"SecureBoot: %s" , data[3 ] ?"on" :"off" ); +return data[3 ]; +#else tst_res (TINFO ,"SecureBoot: %s" , data[4 ] ?"on" :"off" );return data[4 ]; +#endif }int tst_lockdown_enabled (void )@@ -51,9 +64,16 @@ int tst_lockdown_enabled(void)if (access (PATH_LOCKDOWN ,F_OK ) !=0 ) {char flag; +/* SecureBoot enabled could mean integrity lockdown (non-mainline version) */ +#if defined(__powerpc64__) || defined(__ppc64__) + flag =tst_kconfig_get ("CONFIG_SECURITY_LOCKDOWN_LSM" ) =='y' ; + flag |=tst_kconfig_get ("CONFIG_SECURITY_LOCKDOWN_LSM_EARLY" ) =='y' ; +#else flag =tst_kconfig_get ("CONFIG_EFI_SECURE_BOOT_LOCK_DOWN" ) =='y' ; flag |=tst_kconfig_get ("CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT" ) =='y' ; +#endif +if (flag &&tst_secureboot_enabled () >0 )return 1 ;
Signature · 5 lines
Thanks and Regards R.Nageswara Sastry -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
lib/tst_lockdown.c line 21
Quoted 5 lines
lib/tst_lockdown.c +5
-0+#if defined(__powerpc64__) || defined(__ppc64__) +#define SECUREBOOT_VAR "/proc/device-tree/ibm,secure-boot" +#else +#define SECUREBOOT_VAR "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" +#endif
This is not properly indented, for preprocessor directives the # has to always be first character in the line, then inner blocks are indented by spaces between # and the rest such as:
#if foo
# if bar # define BAZ # endif #endif
Quoted 20 lines
int
tst_secureboot_enabled(void)
{lib/tst_lockdown.c +4
-4int fd;char data[5 ]; -if (access (EFIVAR_SECUREBOOT ,F_OK )) { -tst_res (TINFO ,"Efivar FS not available" ); +if (access (SECUREBOOT_VAR ,F_OK )) { +tst_res (TINFO ,"SecureBoot sysfs file not available" );return -1 ; } - fd =open (EFIVAR_SECUREBOOT ,O_RDONLY ); + fd =open (SECUREBOOT_VAR ,O_RDONLY );if (fd ==-1 ) {tst_res (TINFO |TERRNO , -"Cannot open SecureBoot Efivar sysfile" ); +"Cannot open SecureBoot file" );return -1 ;
lib/tst_lockdown.c line 46
Quoted 10 lines
lib/tst_lockdown.c +4
-1}else if (fd <0 ) {tst_brk (TBROK |TERRNO ,"Invalid open() return value %d" , fd);return -1 ; } - +#if defined(__powerpc64__) || defined(__ppc64__) +SAFE_READ (1 , fd, data,4 ); +#else SAFE_READ (1 , fd, data,5 ); +#endif
Here as well, the ifdefs has to start at first character in the line:
#if ... SAFE_READ(...); #else SAFE_READ(...);
#endif
Quoted 16 lines
lib/tst_lockdown.c +6
-0SAFE_CLOSE (fd); + +#if defined(__powerpc64__) || defined(__ppc64__) +tst_res (TINFO ,"SecureBoot: %s" , data[3 ] ?"on" :"off" ); +return data[3 ]; +#else tst_res (TINFO ,"SecureBoot: %s" , data[4 ] ?"on" :"off" );return data[4 ]; +#endif }int tst_lockdown_enabled (void )@@ -51,9 +64,16 @@ int tst_lockdown_enabled(void)if (access (PATH_LOCKDOWN ,F_OK ) !=0 ) {
lib/tst_lockdown.c int tst_lockdown_enabled(void) · line 75
Quoted 10 lines
lib/tst_lockdown.c +6
-0char flag; +/* SecureBoot enabled could mean integrity lockdown (non-mainline version) */ +#if defined(__powerpc64__) || defined(__ppc64__) + flag =tst_kconfig_get ("CONFIG_SECURITY_LOCKDOWN_LSM" ) =='y' ; + flag |=tst_kconfig_get ("CONFIG_SECURITY_LOCKDOWN_LSM_EARLY" ) =='y' ; +#else flag =tst_kconfig_get ("CONFIG_EFI_SECURE_BOOT_LOCK_DOWN" ) =='y' ; flag |=tst_kconfig_get ("CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT" ) =='y' ; +#endif
However all of these cases we can just define a few constants instead of cluttering the code with ifdefs.
#ifdef ppc
# define VAR_DATA_SIZE 5 # define VAR_DATA_OFF 4 # define KERNEL_KCONFIG1 "CONFIG_SECURITY_LOCKDOWN_LSM" # define KERNEL_KCONFIG2 "CONFIG_SECURITY_LOCKDOWN_LSM_EARLY" ... #else # define VAR_DATA_SIZE 4 # define VAR_DATA_OFF 3 ... #endif
Quoted 9 lines
lib/tst_lockdown.c +0
-0if (flag &&tst_secureboot_enabled () >0 )return 1 ;Signature · 5 lines
2.37.1 (Apple Git-137.1) -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 28 lines · Cyril Hrubis
lib/tst_lockdown.c line 46
Quoted 5 lines
lib/tst_lockdown.c +4
-0+#if defined(__powerpc64__) || defined(__ppc64__) +SAFE_READ (1 , fd, data,4 ); +#else SAFE_READ (1 , fd, data,5 ); +#endif Here as well, the ifdefs has to start at first character in the line:
#if ... SAFE_READ(...); #else SAFE_READ(...);#endif
lib/tst_lockdown.c line 56
Quoted 9 lines
SAFE_CLOSE(fd);lib/tst_lockdown.c +6
-0+ +#if defined(__powerpc64__) || defined(__ppc64__) +tst_res (TINFO ,"SecureBoot: %s" , data[3 ] ?"on" :"off" ); +return data[3 ]; +#else tst_res (TINFO ,"SecureBoot: %s" , data[4 ] ?"on" :"off" );return data[4 ]; +#endif However all of these cases we can just define a few constants instead of cluttering the code with ifdefs.
#ifdef ppc
Quoted 8 lines
# define VAR_DATA_SIZE 5 # define VAR_DATA_OFF 4 # define KERNEL_KCONFIG1 "CONFIG_SECURITY_LOCKDOWN_LSM" # define KERNEL_KCONFIG2 "CONFIG_SECURITY_LOCKDOWN_LSM_EARLY" ... #else # define VAR_DATA_SIZE 4 # define VAR_DATA_OFF 3
I'd also recommend using named constant for read size and offset. But we only need one constant. The read size will always be VAR_DATA_OFF+1. We don't care whether there's any additional data after the the byte we want to check.
Signature · 11 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp