Add tst_kconfig_get() helper function
PATCH v4 1/3 Add tst_kconfig_get() helper function
--- include/tst_kconfig.h | 10 ++++++++++ lib/tst_kconfig.c | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+)
include/tst_kconfig.h +10 -0
@@ -55,4 +55,14 @@ void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len);*/ void tst_kconfig_check (const char *const kconfigs[]); +/** +* Checks kernel config for a single configuration option and returns its +* state if found. The possible return values are the same as for +* tst_kconfig_var.choice, with the same meaning. See tst_kconfig_read() +* description for details. +* +* @param confname The configuration option name to search for. +*/ +char tst_kconfig_get (const char *confname); +#endif /* TST_KCONFIG_H__ */
lib/tst_kconfig.c +21 -0
@@ -511,3 +511,24 @@ void tst_kconfig_check(const char *const kconfigs[])if (abort_test)tst_brk (TCONF ,"Aborting due to unsuitable kernel config, see above!" ); } + +char tst_kconfig_get (const char *confname) +{ +struct tst_kconfig_var var; + + var.id_len =strlen (confname); + +if (var.id_len >=sizeof (var.id)) +tst_brk (TBROK ,"Kconfig var name \"%s\" too long" , confname); + +strcpy (var.id, confname); + var.choice =0 ; + var.val =NULL ; + +tst_kconfig_read (&var,1 ); + +if (var.choice =='v' ) +free (var.val); + +return var.choice; +}
Signature · 1 line
2.29.2
PATCH v4 2/3 Add tst_secureboot_enabled() helper function
Also check for SecureBoot status in tst_lockdown_enabled() if the lockdown sysfile is not available/readable and the kernel is configured to enable lockdown automatically under SecureBoot.
--- include/tst_lockdown.h | 1 + lib/tst_lockdown.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
include/tst_lockdown.h +1 -0
@@ -5,6 +5,7 @@#define PATH_LOCKDOWN "/sys/kernel/security/lockdown" +int tst_secureboot_enabled (void );int tst_lockdown_enabled (void );#endif /* TST_LOCKDOWN_H */
lib/tst_lockdown.c +38 -0
@@ -9,14 +9,52 @@#include "tst_test.h" #include "tst_safe_macros.h" #include "tst_safe_stdio.h" +#include "tst_kconfig.h" #include "tst_lockdown.h" +#define EFIVAR_SECUREBOOT "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c" + +int tst_secureboot_enabled (void ) +{ +int fd; +char data[5 ]; + +if (access (EFIVAR_SECUREBOOT ,F_OK )) { +tst_res (TINFO ,"Efivar FS not available" ); +return -1 ; + } + + fd =open (EFIVAR_SECUREBOOT ,O_RDONLY ); + +if (fd ==-1 ) { +tst_res (TINFO |TERRNO , +"Cannot open SecureBoot Efivar sysfile" ); +return -1 ; + }else if (fd <0 ) { +tst_brk (TBROK |TERRNO ,"Invalid open() return value %d" , fd); +return -1 ; + } + +SAFE_READ (1 , fd, data,5 ); +SAFE_CLOSE (fd); +tst_res (TINFO ,"SecureBoot: %s" , data[4 ] ?"on" :"off" ); +return data[4 ]; +} +int tst_lockdown_enabled (void ) {char line[BUFSIZ ];FILE *file;if (access (PATH_LOCKDOWN ,F_OK ) !=0 ) { +char flag; + + flag =tst_kconfig_get ("CONFIG_EFI_SECURE_BOOT_LOCK_DOWN" ); + +/* SecureBoot enabled could mean integrity lockdown */ +if (flag =='y' &&tst_secureboot_enabled () >0 ) +return 1 ; +tst_res (TINFO ,"Unable to determine system lockdown state" );return 0 ; }
Signature · 1 line
2.29.2
PATCH v4 2/3 Add tst_secureboot_enabled() helper function
Hi!
lib/tst_lockdown.c line 52
Quoted 1 line
lib/tst_lockdown.c +1
-0+ flag =tst_kconfig_get ("CONFIG_EFI_SECURE_BOOT_LOCK_DOWN" );
So this is being used in the test library, I guess that having the config parsed here is inevitable, but still I do not want this function to be exported for testcases.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 3/3 syscalls/iopl02, ioperm02: Skip when kernel is locked down
In reply to Martin DouchaThe iopl() and ioperm() syscalls are blocked when the kernel is locked down. The order of sanity checks is not guaranteed so it's better to skip these tests even if they accidentally work.
--- testcases/kernel/syscalls/ioperm/ioperm02.c | 4 ++++ testcases/kernel/syscalls/iopl/iopl02.c | 5 +++++ 2 files changed, 9 insertions(+)
testcases/kernel/syscalls/ioperm/ioperm02.c +4 -0
@@ -45,6 +45,10 @@ static struct tcase_t {static void setup (void ) { +/* ioperm() is restricted under kernel lockdown. */ +if (tst_lockdown_enabled ()) +tst_brk (TCONF ,"Kernel is locked down, skip this test" ); +/* * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed * from kernel 2.6.8 to permit 16-bits (65536) ioperm
testcases/kernel/syscalls/iopl/iopl02.c +5 -0
@@ -52,6 +52,11 @@ static void verify_iopl(unsigned int i)static void setup (void ) {struct passwd *pw; + +/* iopl() is restricted under kernel lockdown. */ +if (tst_lockdown_enabled ()) +tst_brk (TCONF ,"Kernel is locked down, skip this test" ); + pw =SAFE_GETPWNAM ("nobody" );SAFE_SETEUID (pw->pw_uid); }
Signature · 1 line
2.29.2
PATCH v4 1/3 Add tst_kconfig_get() helper function
In reply to Martin DouchaHi!
include/tst_kconfig.h void tst_kconfig_read(struct tst_kconfig_var vars[], size_t vars_len); · line 66
Quoted 9 lines
include/tst_kconfig.h +9
-0+/** +* Checks kernel config for a single configuration option and returns its +* state if found. The possible return values are the same as for +* tst_kconfig_var.choice, with the same meaning. See tst_kconfig_read() +* description for details. +* +* @param confname The configuration option name to search for. +*/ +char tst_kconfig_get (const char *confname);
I do not like this interface at all since the whole kernel config is parsed every time this function is called and I bet that people would call it five times in a test setup() soon enough.
I guess that if you want easier interface than the tst_kconfig_read() it should be implemented as:
* A function loads config given an array of variable names to store. Either it should return a handle or store the pointer to newly allocated data to a global variable.
* A set of functions that return variable value given variable name
* A function that frees the memory once we are done
Signature · 2 lines
Cyril Hrubis [email protected]