[LTP] [PATCH] syscalls/finit_module02: Rewrite lockdown skips
Martin Doucha
mdoucha@suse.cz
Tue Sep 21 12:30:50 CEST 2021
Different kernels may return different module signature validation errors
for null-param and invalid-param test cases. Skip both test cases when
the kernel is in lockdown.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
.../syscalls/finit_module/finit_module02.c | 44 +++++++++----------
1 file changed, 20 insertions(+), 24 deletions(-)
diff --git a/testcases/kernel/syscalls/finit_module/finit_module02.c b/testcases/kernel/syscalls/finit_module/finit_module02.c
index 503c8e994..0d2bf917e 100644
--- a/testcases/kernel/syscalls/finit_module/finit_module02.c
+++ b/testcases/kernel/syscalls/finit_module/finit_module02.c
@@ -38,6 +38,7 @@ struct tcase {
int flags;
int cap;
int exp_errno;
+ int skip_in_lockdown;
void (*fix_errno)(struct tcase *tc);
};
@@ -65,24 +66,21 @@ static void dir_setup(struct tcase *tc)
tc->exp_errno = EINVAL;
}
-static void lockdown_setup(struct tcase *tc)
-{
- if (kernel_lockdown)
- tc->exp_errno = EPERM;
-}
-
static struct tcase tcases[] = {
- {"invalid-fd", &fd_invalid, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, bad_fd_setup},
- {"zero-fd", &fd_zero, "", O_RDONLY | O_CLOEXEC, 0, 0, EINVAL, NULL},
- {"null-param", &fd, NULL, O_RDONLY | O_CLOEXEC, 0, 0, EFAULT,
- lockdown_setup},
+ {"invalid-fd", &fd_invalid, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, 0,
+ bad_fd_setup},
+ {"zero-fd", &fd_zero, "", O_RDONLY | O_CLOEXEC, 0, 0, EINVAL, 0, NULL},
+ {"null-param", &fd, NULL, O_RDONLY | O_CLOEXEC, 0, 0, EFAULT, 1, NULL},
{"invalid-param", &fd, "status=invalid", O_RDONLY | O_CLOEXEC, 0, 0,
- EINVAL, lockdown_setup},
- {"invalid-flags", &fd, "", O_RDONLY | O_CLOEXEC, -1, 0, EINVAL, NULL},
- {"no-perm", &fd, "", O_RDONLY | O_CLOEXEC, 0, 1, EPERM, NULL},
- {"module-exists", &fd, "", O_RDONLY | O_CLOEXEC, 0, 0, EEXIST, NULL},
- {"file-not-readable", &fd, "", O_WRONLY | O_CLOEXEC, 0, 0, 0, wo_file_setup},
- {"directory", &fd_dir, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, dir_setup},
+ EINVAL, 1, NULL},
+ {"invalid-flags", &fd, "", O_RDONLY | O_CLOEXEC, -1, 0, EINVAL, 0,
+ NULL},
+ {"no-perm", &fd, "", O_RDONLY | O_CLOEXEC, 0, 1, EPERM, 0, NULL},
+ {"module-exists", &fd, "", O_RDONLY | O_CLOEXEC, 0, 0, EEXIST, 1,
+ NULL},
+ {"file-not-readable", &fd, "", O_WRONLY | O_CLOEXEC, 0, 0, 0, 0,
+ wo_file_setup},
+ {"directory", &fd_dir, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, 0, dir_setup},
};
static void setup(void)
@@ -112,21 +110,19 @@ static void run(unsigned int n)
{
struct tcase *tc = &tcases[n];
+ if (tc->skip_in_lockdown && kernel_lockdown) {
+ tst_res(TCONF, "Kernel is locked down, skipping %s", tc->name);
+ return;
+ }
+
fd = SAFE_OPEN(mod_path, tc->open_flags);
if (tc->cap)
tst_cap_action(&cap_drop);
/* Insert module twice */
- if (tc->exp_errno == EEXIST) {
- if (kernel_lockdown) {
- tst_res(TCONF, "Kernel is locked down, skipping %s",
- tc->name);
- return;
- }
-
+ if (tc->exp_errno == EEXIST)
tst_module_load(MODULE_NAME, NULL);
- }
TST_EXP_FAIL(finit_module(*tc->fd, tc->param, tc->flags), tc->exp_errno,
"TestName: %s", tc->name);
--
2.33.0
More information about the ltp
mailing list