Skip to contentSkip to conversation

request_key: Add negative tests for request_key

PATCH In review Ma Xinjian via ltp 3 participants 4 messages May 21, 2024 – Sep 17, 2024 Keys/keyrings

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 request_key: Add negative tests for request_key

Add negative tests for request_key(), when errno is EFAULT or EPERM

---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/request_key/.gitignore    |  1 +
 .../syscalls/request_key/request_key06.c      | 52 +++++++++++++++++++
 3 files changed, 54 insertions(+)
 create mode 100644 testcases/kernel/syscalls/request_key/request_key06.c
runtest/syscalls +1 -0
index 3a28123a5..c04359fcd 100644
@@ -1187,6 +1187,7 @@ request_key02 request_key02
 request_key03 request_key03
 request_key04 request_key04
 request_key05 request_key05
+request_key06 request_key06
 
 rmdir01 rmdir01
 rmdir02 rmdir02
testcases/kernel/syscalls/request_key/.gitignore +1 -0
index e8dc1c570..6dcf613c7 100644
@@ -3,3 +3,4 @@
 /request_key03
 /request_key04
 /request_key05
+/request_key06
testcases/kernel/syscalls/request_key/request_key06.c new file +52 -0

52 lines not on this page · raw message

Signature · 5 lines
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw

Hi Ma, Eric, all,

Quoted 1 line

Add negative tests for request_key(), when errno is EFAULT or EPERM

LGTM, thanks!

We also somehow test EACCES (request_key04.c). Looking into man page, there are other interesting errno to test I suppose (EDQUOT, EKEYEXPIRED, EKEYREJECTED, ...)

@Eric, other devs, would you have time to have a quick look on the test?

Kind regards,
Petr

Quoted 87 lines
---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/request_key/.gitignore    |  1 +
 .../syscalls/request_key/request_key06.c      | 52 +++++++++++++++++++
 3 files changed, 54 insertions(+)
 create mode 100644 testcases/kernel/syscalls/request_key/request_key06.c
runtest/syscalls +1 -0
index 3a28123a5..c04359fcd 100644
@@ -1187,6 +1187,7 @@ request_key02 request_key02
 request_key03 request_key03
 request_key04 request_key04
 request_key05 request_key05
+request_key06 request_key06
 
 rmdir01 rmdir01
 rmdir02 rmdir02
testcases/kernel/syscalls/request_key/.gitignore +1 -0
index e8dc1c570..6dcf613c7 100644
@@ -3,3 +3,4 @@
 /request_key03
 /request_key04
 /request_key05
+/request_key06
testcases/kernel/syscalls/request_key/request_key06.c new file +52 -0
new file mode 100644
index 000000000..bd872867b
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
+ * Author: Ma Xinjian <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that request_key(2) fails with
+ *
+ * - EFAULT when type points outside the process's accessible address space
+ * - EFAULT when description points outside the process's accessible address space
+ * - EFAULT when callout_info points outside the process's accessible address space
+ * - EPERM when type argument started with a period '.'
+ */
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+static struct test_case_t {
+	char *type;
+	char *description;
+	char *callout_info;
+	key_serial_t dest_keyring;
+	int expected_errno;
+	char *desc;
+} tcases[] = {
+	{(char *)(-1), "description", NULL, KEY_SPEC_PROCESS_KEYRING, EFAULT,
+		"type points outside the process's accessible address space"},
+	{"type", (char *)(-1), NULL, KEY_SPEC_PROCESS_KEYRING, EFAULT,
+		"description points outside the process's accessible address space"},
+	{"type", "description", (char *)(-1), KEY_SPEC_PROCESS_KEYRING, EFAULT,
+		"callout_info points outside the process's accessible address space"},
+	{".type", "description", NULL, KEY_SPEC_PROCESS_KEYRING, EPERM,
+		"type argument started with a period '.'"},
+};
+
+static void verify_request_key(unsigned int i)
+{
+	struct test_case_t *tc = &tcases[i];
+
+	TST_EXP_FAIL2(request_key(tc->type, tc->description, tc->callout_info,
+		tc->dest_keyring),
+		tc->expected_errno,
+		"%s", tc->desc);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_request_key,
+};
#2 lore raw

Hi!

Quoted 8 lines

LGTM, thanks!

We also somehow test EACCES (request_key04.c). Looking into man page, there are other interesting errno to test I suppose (EDQUOT, EKEYEXPIRED, EKEYREJECTED, ...)

@Eric, other devs, would you have time to have a quick look on the test?

I've pushed the patch, we can add more tests later on.

Signature · 2 lines
Cyril Hrubis
[email protected]