[LTP] [PATCH] {delete, finit, init}_module0[1-3]: Handle CONFIG_MODULE_SIG_FORCE

Po-Hsu Lin po-hsu.lin@canonical.com
Mon Dec 23 05:19:21 CET 2024


The patch adds parsing for CONFIG_MODULE_SIG_FORCE kernel config,
which will make tests expect an EKEYREJECTED error like using the
'module.sig_enforce' parameter.

Patch tested on kernel with CONFIG_MODULE_SIG_FORCE=y and it's
working as expected.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 testcases/kernel/syscalls/delete_module/delete_module01.c | 4 +++-
 testcases/kernel/syscalls/delete_module/delete_module03.c | 4 +++-
 testcases/kernel/syscalls/finit_module/finit_module01.c   | 6 ++++--
 testcases/kernel/syscalls/finit_module/finit_module02.c   | 6 ++++--
 testcases/kernel/syscalls/init_module/init_module01.c     | 6 ++++--
 testcases/kernel/syscalls/init_module/init_module02.c     | 6 ++++--
 6 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/syscalls/delete_module/delete_module01.c b/testcases/kernel/syscalls/delete_module/delete_module01.c
index 11c4eae58..5ccbe6fd5 100644
--- a/testcases/kernel/syscalls/delete_module/delete_module01.c
+++ b/testcases/kernel/syscalls/delete_module/delete_module01.c
@@ -28,9 +28,11 @@ static int module_loaded;
 static void do_delete_module(void)
 {
 	struct tst_kcmdline_var params = TST_KCMDLINE_INIT("module.sig_enforce");
+	struct tst_kconfig_var kconfig = TST_KCONFIG_INIT("CONFIG_MODULE_SIG_FORCE");
 
 	tst_kcmdline_parse(&params, 1);
-	if (atoi(params.value) == 1)
+	tst_kconfig_read(&kconfig, 1);
+	if (params.found || kconfig.choice == 'y')
 		tst_brk(TCONF, "module signature is enforced, skip test");
 
 	if (!module_loaded) {
diff --git a/testcases/kernel/syscalls/delete_module/delete_module03.c b/testcases/kernel/syscalls/delete_module/delete_module03.c
index fdf0c293d..76ccfb1e2 100644
--- a/testcases/kernel/syscalls/delete_module/delete_module03.c
+++ b/testcases/kernel/syscalls/delete_module/delete_module03.c
@@ -53,9 +53,11 @@ static void do_delete_module(void)
 static void setup(void)
 {
 	struct tst_kcmdline_var params = TST_KCMDLINE_INIT("module.sig_enforce");
+	struct tst_kconfig_var kconfig = TST_KCONFIG_INIT("CONFIG_MODULE_SIG_FORCE");
 
 	tst_kcmdline_parse(&params, 1);
-	if (atoi(params.value) == 1)
+	tst_kconfig_read(&kconfig, 1);
+	if (params.found || kconfig.choice == 'y')
 		tst_brk(TCONF, "module signature is enforced, skip test");
 
 	/* Load first kernel module */
diff --git a/testcases/kernel/syscalls/finit_module/finit_module01.c b/testcases/kernel/syscalls/finit_module/finit_module01.c
index 1546d4fb7..d75e5e475 100644
--- a/testcases/kernel/syscalls/finit_module/finit_module01.c
+++ b/testcases/kernel/syscalls/finit_module/finit_module01.c
@@ -28,10 +28,12 @@ static char *mod_path;
 static void setup(void)
 {
 	struct tst_kcmdline_var params = TST_KCMDLINE_INIT("module.sig_enforce");
+	struct tst_kconfig_var kconfig = TST_KCONFIG_INIT("CONFIG_MODULE_SIG_FORCE");
 
 	tst_kcmdline_parse(&params, 1);
-	if (params.found)
-		sig_enforce = atoi(params.value);
+	tst_kconfig_read(&kconfig, 1);
+	if (params.found || kconfig.choice == 'y')
+		sig_enforce = 1;
 
 	tst_module_exists(MODULE_NAME, &mod_path);
 
diff --git a/testcases/kernel/syscalls/finit_module/finit_module02.c b/testcases/kernel/syscalls/finit_module/finit_module02.c
index 2fe70af4d..dc81ae727 100644
--- a/testcases/kernel/syscalls/finit_module/finit_module02.c
+++ b/testcases/kernel/syscalls/finit_module/finit_module02.c
@@ -78,10 +78,12 @@ static void setup(void)
 {
 	unsigned long int i;
 	struct tst_kcmdline_var params = TST_KCMDLINE_INIT("module.sig_enforce");
+	struct tst_kconfig_var kconfig = TST_KCONFIG_INIT("CONFIG_MODULE_SIG_FORCE");
 
 	tst_kcmdline_parse(&params, 1);
-	if (params.found)
-		sig_enforce = atoi(params.value);
+	tst_kconfig_read(&kconfig, 1);
+	if (params.found || kconfig.choice == 'y')
+		sig_enforce = 1;
 
 	tst_module_exists(MODULE_NAME, &mod_path);
 
diff --git a/testcases/kernel/syscalls/init_module/init_module01.c b/testcases/kernel/syscalls/init_module/init_module01.c
index 27a1fc627..d7ed08b14 100644
--- a/testcases/kernel/syscalls/init_module/init_module01.c
+++ b/testcases/kernel/syscalls/init_module/init_module01.c
@@ -29,10 +29,12 @@ static void setup(void)
 {
 	int fd;
 	struct tst_kcmdline_var params = TST_KCMDLINE_INIT("module.sig_enforce");
+	struct tst_kconfig_var kconfig = TST_KCONFIG_INIT("CONFIG_MODULE_SIG_FORCE");
 
 	tst_kcmdline_parse(&params, 1);
-	if (params.found)
-		sig_enforce = atoi(params.value);
+	tst_kconfig_read(&kconfig, 1);
+	if (params.found || kconfig.choice == 'y')
+		sig_enforce = 1;
 
 	tst_module_exists(MODULE_NAME, NULL);
 
diff --git a/testcases/kernel/syscalls/init_module/init_module02.c b/testcases/kernel/syscalls/init_module/init_module02.c
index 68d9ff16b..3eb99574d 100644
--- a/testcases/kernel/syscalls/init_module/init_module02.c
+++ b/testcases/kernel/syscalls/init_module/init_module02.c
@@ -54,10 +54,12 @@ static void setup(void)
 	struct stat sb;
 	int fd;
 	struct tst_kcmdline_var params = TST_KCMDLINE_INIT("module.sig_enforce");
+	struct tst_kconfig_var kconfig = TST_KCONFIG_INIT("CONFIG_MODULE_SIG_FORCE");
 
 	tst_kcmdline_parse(&params, 1);
-	if (params.found)
-		sig_enforce = atoi(params.value);
+	tst_kconfig_read(&kconfig, 1);
+	if (params.found || kconfig.choice == 'y')
+		sig_enforce = 1;
 
 	tst_module_exists(MODULE_NAME, NULL);
 
-- 
2.25.1



More information about the ltp mailing list