[LTP] [PATCH 2/3] request_key03: Split test into 3 testcases
Martin Doucha
mdoucha@suse.cz
Fri Sep 16 18:07:25 CEST 2022
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
.../syscalls/request_key/request_key03.c | 70 ++++++++++---------
1 file changed, 37 insertions(+), 33 deletions(-)
diff --git a/testcases/kernel/syscalls/request_key/request_key03.c b/testcases/kernel/syscalls/request_key/request_key03.c
index 2780532f3..cb256f41e 100644
--- a/testcases/kernel/syscalls/request_key/request_key03.c
+++ b/testcases/kernel/syscalls/request_key/request_key03.c
@@ -37,6 +37,30 @@
#include "tst_test.h"
#include "lapi/keyctl.h"
+static struct test_case {
+ const char *type;
+ const char *payload;
+ int effort;
+} testcase_list[] = {
+ /*
+ * Briefly test the "encrypted" and/or "trusted" key types when
+ * availaible, mainly to reproduce CVE-2017-15299.
+ */
+ {"encrypted", "update user:foo 32", 2},
+ {"trusted", "update", 2},
+
+ /*
+ * Test the "user" key type for longer, mainly in order to reproduce
+ * CVE-2017-15951. However, without the fix for CVE-2017-15299 as well,
+ * WARNs may show up in the kernel log.
+ *
+ * Note: the precise iteration count is arbitrary; it's just intended to
+ * be enough to give a decent chance of reproducing the bug, without
+ * wasting too much time.
+ */
+ {"user", "payload", 20},
+};
+
static char *opt_bug;
static void run_child_add(const char *type, const char *payload, int effort)
@@ -95,29 +119,29 @@ static void run_child_request(const char *type, int effort)
}
}
-static void test_with_key_type(const char *type, const char *payload,
- int effort)
+static void do_test(unsigned int n)
{
int status;
pid_t add_key_pid;
pid_t request_key_pid;
bool info_only;
+ struct test_case *tc = testcase_list + n;
TEST(keyctl(KEYCTL_JOIN_SESSION_KEYRING, NULL));
if (TST_RET < 0)
tst_brk(TBROK | TTERRNO, "failed to join new session keyring");
- TEST(add_key(type, "desc", payload, strlen(payload),
+ TEST(add_key(tc->type, "desc", tc->payload, strlen(tc->payload),
KEY_SPEC_SESSION_KEYRING));
if (TST_RET < 0 && TST_ERR != EINVAL) {
if (TST_ERR == ENODEV) {
tst_res(TCONF, "kernel doesn't support key type '%s'",
- type);
+ tc->type);
return;
}
tst_brk(TBROK | TTERRNO,
"unexpected error checking whether key type '%s' is supported",
- type);
+ tc->type);
}
/*
@@ -126,13 +150,13 @@ static void test_with_key_type(const char *type, const char *payload,
*/
add_key_pid = SAFE_FORK();
if (add_key_pid == 0) {
- run_child_add(type, payload, effort);
+ run_child_add(tc->type, tc->payload, tc->effort);
exit(0);
}
request_key_pid = SAFE_FORK();
if (request_key_pid == 0) {
- run_child_request(type, effort);
+ run_child_request(tc->type, tc->effort);
exit(0);
}
@@ -149,11 +173,11 @@ static void test_with_key_type(const char *type, const char *payload,
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
tst_res(info_only ? TINFO : TPASS,
"didn't crash while updating key of type '%s'",
- type);
+ tc->type);
} else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
tst_res(info_only ? TINFO : TFAIL,
"kernel oops while updating key of type '%s'",
- type);
+ tc->type);
} else {
tst_brk(TBROK, "add_key child %s", tst_strstatus(status));
}
@@ -163,39 +187,19 @@ static void test_with_key_type(const char *type, const char *payload,
if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
tst_res(info_only ? TINFO : TPASS,
"didn't crash while requesting key of type '%s'",
- type);
+ tc->type);
} else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
tst_res(info_only ? TINFO : TFAIL,
"kernel oops while requesting key of type '%s'",
- type);
+ tc->type);
} else {
tst_brk(TBROK, "request_key child %s", tst_strstatus(status));
}
}
-static void do_test(void)
-{
- /*
- * Briefly test the "encrypted" and/or "trusted" key types when
- * availaible, mainly to reproduce CVE-2017-15299.
- */
- test_with_key_type("encrypted", "update user:foo 32", 2);
- test_with_key_type("trusted", "update", 2);
-
- /*
- * Test the "user" key type for longer, mainly in order to reproduce
- * CVE-2017-15951. However, without the fix for CVE-2017-15299 as well,
- * WARNs may show up in the kernel log.
- *
- * Note: the precise iteration count is arbitrary; it's just intended to
- * be enough to give a decent chance of reproducing the bug, without
- * wasting too much time.
- */
- test_with_key_type("user", "payload", 20);
-}
-
static struct tst_test test = {
- .test_all = do_test,
+ .test = do_test,
+ .tcnt = ARRAY_SIZE(testcase_list),
.forks_child = 1,
.options = (struct tst_option[]) {
{"b:", &opt_bug, "Bug to test for (cve-2017-15299 or cve-2017-15951; default is both)"},
--
2.37.3
More information about the ltp
mailing list