Skip to contentSkip to conversation

Improve coverage for keyctl() syscall

PATCH In review Andrea Cervesato 4 participants 65 messages Sep 4 – Sep 16 Library code

lore
Share & tools
lore
#0 lore raw

v2 cover Improve coverage for keyctl() syscall

Improve the keyctl() syscall coverage by adding more tests for the following features, which are not currently tested in LTP:

- KEYCTL_DESCRIBE
- KEYCTL_GET_SECURITY
- KEYCTL_MOVE
- KEYCTL_RESTRICT_KEYRING
- KEYCTL_DH_COMPUTE
- KEYCTL_PKEY_*
- KEYCTL_CAPABILITIES
- KEYCTL_WATCH_KEY

The testing suite has been assisted by GLM 5.3 for coverage analysis and Gemini Flash 3.7 for the tests skeleton.

Validation: https://openqa.opensuse.org/tests/6199954#

---
Changes in v2:
- fix build
- Link to v1: https://lore.kernel.org/[email protected]

To: Linux Test Project <[email protected]>

---
Andrea Cervesato (33):
lapi/keyctl.h: Add fallback definitions for extended ops
keyctl10: Test KEYCTL_DESCRIBE format parsing
keyctl11: Test KEYCTL_DESCRIBE with exact buffer size
keyctl12: Test KEYCTL_DESCRIBE with too small buffer
keyctl13: Test KEYCTL_DESCRIBE size query
keyctl14: Negative tests for KEYCTL_DESCRIBE
keyctl15: Test KEYCTL_GET_SECURITY label retrieval
keyctl16: Test KEYCTL_GET_SECURITY truncated copy
keyctl17: Negative tests for KEYCTL_GET_SECURITY
keyctl18: Test basic KEYCTL_MOVE
keyctl19: Test KEYCTL_MOVE with same source and destination
keyctl20: Test KEYCTL_MOVE displacement
keyctl21: Negative and boundary tests for KEYCTL_MOVE
keyctl22: Test KEYCTL_RESTRICT_KEYRING reject-all
keyctl23: Test KEYCTL_RESTRICT_KEYRING builtin_trusted
keyctl24: Negative tests for KEYCTL_RESTRICT_KEYRING
keyctl25: Test KEYCTL_DH_COMPUTE shared secret computation
keyctl26: Test KEYCTL_DH_COMPUTE size query
keyctl27: Test KEYCTL_DH_COMPUTE KDF key derivation
keyctl28: Negative and boundary tests for KEYCTL_DH_COMPUTE lapi/keyctl.h: Add fallback definitions for public key ops
keyctl29: Test KEYCTL_PKEY_QUERY on public key
keyctl30: Test KEYCTL_PKEY_QUERY on private key
keyctl31: Test KEYCTL_PKEY_ENCRYPT and KEYCTL_PKEY_DECRYPT
keyctl32: Test KEYCTL_PKEY_SIGN and VERIFY
keyctl33: Negative tests for KEYCTL_PKEY_* lapi/keyctl.h: Add capability fallback defines
keyctl34: Test KEYCTL_CAPABILITIES flag retrieval
keyctl35: Test KEYCTL_CAPABILITIES size query
keyctl36: Test KEYCTL_CAPABILITIES buffer sizing
keyctl37: Negative tests for KEYCTL_CAPABILITIES
keyctl38: Test KEYCTL_WATCH_KEY add and remove
keyctl39: Negative tests for KEYCTL_WATCH_KEY

 include/lapi/keyctl.h                              | 141 +++++++++++-
 m4/ltp-keyutils.m4                                 |  13 ++
 runtest/syscalls                                   |  30 +++
 testcases/kernel/syscalls/keyctl/.gitignore        |  30 +++
 testcases/kernel/syscalls/keyctl/keyctl10.c        |  99 +++++++++
 testcases/kernel/syscalls/keyctl/keyctl11.c        |  62 ++++++
 testcases/kernel/syscalls/keyctl/keyctl12.c        |  62 ++++++
 testcases/kernel/syscalls/keyctl/keyctl13.c        |  46 ++++
 testcases/kernel/syscalls/keyctl/keyctl14.c        |  54 +++++
 testcases/kernel/syscalls/keyctl/keyctl15.c        |  66 ++++++
 testcases/kernel/syscalls/keyctl/keyctl16.c        |  74 ++++++
 testcases/kernel/syscalls/keyctl/keyctl17.c        |  55 +++++
 testcases/kernel/syscalls/keyctl/keyctl18.c        |  60 +++++
 testcases/kernel/syscalls/keyctl/keyctl19.c        |  43 ++++
 testcases/kernel/syscalls/keyctl/keyctl20.c        |  62 ++++++
 testcases/kernel/syscalls/keyctl/keyctl21.c        | 111 +++++++++
 testcases/kernel/syscalls/keyctl/keyctl22.c        |  54 +++++
 testcases/kernel/syscalls/keyctl/keyctl23.c        | 142 ++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl24.c        | 173 +++++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl25.c        |  66 ++++++
 testcases/kernel/syscalls/keyctl/keyctl26.c        |  53 +++++
 testcases/kernel/syscalls/keyctl/keyctl27.c        |  78 +++++++
 testcases/kernel/syscalls/keyctl/keyctl28.c        | 140 ++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl29.c        |  90 ++++++++
 testcases/kernel/syscalls/keyctl/keyctl30.c        |  86 +++++++
 testcases/kernel/syscalls/keyctl/keyctl31.c        | 110 +++++++++
 testcases/kernel/syscalls/keyctl/keyctl32.c        | 121 ++++++++++
 testcases/kernel/syscalls/keyctl/keyctl33.c        | 247 +++++++++++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl34.c        |  62 ++++++
 testcases/kernel/syscalls/keyctl/keyctl35.c        |  49 ++++
 testcases/kernel/syscalls/keyctl/keyctl36.c        |  88 ++++++++
 testcases/kernel/syscalls/keyctl/keyctl37.c        |  63 ++++++
 testcases/kernel/syscalls/keyctl/keyctl38.c        |  91 ++++++++
 testcases/kernel/syscalls/keyctl/keyctl39.c        | 149 +++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl_common.h   |  73 ++++++
 testcases/kernel/syscalls/keyctl/keyctl_dh_data.h  |  79 +++++++
 .../kernel/syscalls/keyctl/keyctl_pkey_data.h      | 152 +++++++++++++
 37 files changed, 3173 insertions(+), 1 deletion(-)

---
base-commit: 043bdc49af410f55ece6f61abcdaba7d9580f86a
change-id: 20260831-keyctl_coverage-345a4c4d7992

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


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

PATCH v2 1/33 lapi/keyctl.h: Add fallback definitions for extended ops

From: Andrea Cervesato <[email protected]>

Add fallback definitions for KEYCTL_LINK, KEYCTL_RESTRICT_KEYRING, KEYCTL_MOVE, and KEYCTL_MOVE_EXCL, as well as fallback definitions for struct keyctl_dh_params and struct keyctl_kdf_params when built without keyutils.h or linux/keyctl.h.

---
 include/lapi/keyctl.h | 36 +++++++++++++++++++++++++++++++++++-
 m4/ltp-keyutils.m4    | 13 +++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
include/lapi/keyctl.h +35 -1
index 83fa09303..1c6627f55 100644
@@ -8,6 +8,8 @@
 
 #include "config.h"
 
+#include <stdint.h>
+
 #if defined(HAVE_KEYUTILS_H) && defined(HAVE_LIBKEYUTILS)
 # include <keyutils.h>
 #else
@@ -16,7 +18,6 @@
 # endif /* HAVE_LINUX_KEYCTL_H */
 
 # include <stdarg.h>
-# include <stdint.h>
 # include "lapi/syscalls.h"
 typedef int32_t key_serial_t;
 
@@ -60,6 +61,23 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {
 
 #endif /* defined(HAVE_KEYUTILS_H) && defined(HAVE_LIBKEYUTILS) */
 
+#ifndef HAVE_STRUCT_KEYCTL_DH_PARAMS
+struct keyctl_dh_params {
+	int32_t priv;
+	int32_t prime;
+	int32_t base;
+};
+#endif
+
+#ifndef HAVE_STRUCT_KEYCTL_KDF_PARAMS
+struct keyctl_kdf_params {
+	char *hashname;
+	char *otherinfo;
+	uint32_t otherinfolen;
+	uint32_t __spare[8];
+};
+#endif
+
 /* special process keyring shortcut IDs */
 #ifndef KEY_SPEC_THREAD_KEYRING
 # define KEY_SPEC_THREAD_KEYRING -1
@@ -124,6 +142,10 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {
 # define KEYCTL_CLEAR 7
 #endif
 
+#ifndef KEYCTL_LINK
+# define KEYCTL_LINK 8
+#endif
+
 #ifndef KEYCTL_UNLINK
 # define KEYCTL_UNLINK 9
 #endif
@@ -168,6 +190,18 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {
 # define KEYCTL_WATCH_KEY 32
 #endif
 
+#ifndef KEYCTL_RESTRICT_KEYRING
+# define KEYCTL_RESTRICT_KEYRING 29
+#endif
+
+#ifndef KEYCTL_MOVE
+# define KEYCTL_MOVE 30
+#endif
+
+#ifndef KEYCTL_MOVE_EXCL
+# define KEYCTL_MOVE_EXCL 0x00000001 /* do not displace from the to-keyring */
+#endif
+
 /* key permissions */
 #ifndef KEY_POS_VIEW
 # define KEY_POS_VIEW    0x01000000
m4/ltp-keyutils.m4 +13 -0
index 451c549f3..82303bef7 100644
@@ -7,4 +7,17 @@ AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT], [
 	AC_CHECK_LIB([keyutils], [add_key],
 	[AC_DEFINE(HAVE_LIBKEYUTILS, 1, [Define to 1 if you have libkeyutils installed.])
 	      AC_SUBST(KEYUTILS_LIBS, "-lkeyutils")])
+
+	LTP_KEYCTL_HEADERS=""
+
+	if test "x$ac_cv_header_keyutils_h" = "xyes" && \
+	   test "x$ac_cv_lib_keyutils_add_key" = "xyes"; then
+		LTP_KEYCTL_HEADERS="#include <keyutils.h>"
+	elif test "x$ac_cv_header_linux_keyctl_h" = "xyes"; then
+		LTP_KEYCTL_HEADERS="#include <linux/keyctl.h>"
+	fi
+
+	AC_CHECK_TYPES([struct keyctl_dh_params, struct keyctl_kdf_params,
+			struct keyctl_pkey_query, struct keyctl_pkey_params],,,
+			[$LTP_KEYCTL_HEADERS])
 ])
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] lapi/keyctl.h: Add fallback definitions for extended ops

Hi Andrea,

Quoted 1 line · Andrea Cervesato

lapi/keyctl.h: Add fallback definitions for extended ops

--- [PATCH 15/33] ---

Review

Quoted 4 lines
(quoted diff) +4 -0
+	/* Probe if asymmetric key type is supported */
+	TEST(keyctl(KEYCTL_RESTRICT_KEYRING, ring_builtin,
+		    (unsigned long)"asymmetric", (unsigned long)"bogus", 0));
+	asym_supported = (TST_RET != -1 || TST_ERR != ENODEV);

KEYCTL_RESTRICT_KEYRING returns ENOKEY, not ENODEV, when the asymmetric key type is absent: keyring_restrict() propagates the raw -ENOKEY from key_type_lookup(), unlike add_key() which remaps it to ENODEV. On a kernel without CONFIG_ASYMMETRIC_KEY_TYPE this probe therefore sets asym_supported to true, so run() proceeds and the builtin_trusted restriction returns ENOKEY, which is not handled as TCONF and reports TFAIL. Use asym_supported = !(TST_RET == -1 && TST_ERR == ENOKEY);

--- [PATCH 16/33] ---

Review

Quoted 3 lines
(quoted diff) +3 -0
+	TEST(keyctl(KEYCTL_RESTRICT_KEYRING, probe_ring,
+		    (unsigned long)"asymmetric", (unsigned long)"bogus", 0));
+	asym_supported = (TST_RET != -1 || TST_ERR != ENODEV);

Same probe defect: the absent-type errno is ENOKEY, not ENODEV, so asym_supported is true without CONFIG_ASYMMETRIC_KEY_TYPE and the needs_asym tcases are not skipped as intended. Use asym_supported = !(TST_RET == -1 && TST_ERR == ENOKEY);

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v2 01/33] lapi/keyctl.h: Add fallback definitions for extended ops

In reply to Andrea Cervesato

Hi!

Quoted 10 lines
m4/ltp-keyutils.m4 +4 -0
@@ -7,4 +7,17 @@ AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT], [
 	AC_CHECK_LIB([keyutils], [add_key],
 	[AC_DEFINE(HAVE_LIBKEYUTILS, 1, [Define to 1 if you have libkeyutils installed.])
 	      AC_SUBST(KEYUTILS_LIBS, "-lkeyutils")])
+
+	LTP_KEYCTL_HEADERS=""
+
+	if test "x$ac_cv_header_keyutils_h" = "xyes" && \

m4/ltp-keyutils.m4 AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT], [ · line 23

Quoted 10 lines
m4/ltp-keyutils.m4 +9 -0
+	   test "x$ac_cv_lib_keyutils_add_key" = "xyes"; then
+		LTP_KEYCTL_HEADERS="#include <keyutils.h>"
+	elif test "x$ac_cv_header_linux_keyctl_h" = "xyes"; then
+		LTP_KEYCTL_HEADERS="#include <linux/keyctl.h>"
+	fi
+
+	AC_CHECK_TYPES([struct keyctl_dh_params, struct keyctl_kdf_params,
+			struct keyctl_pkey_query, struct keyctl_pkey_params],,,
+			[$LTP_KEYCTL_HEADERS])
 ])

Maybe we can simplify this to just linux/keyctl.h. The linux uapi header has been quite stable for nearly a decade.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH v2 01/33] lapi/keyctl.h: Add fallback definitions for extended ops

Quoted 16 lines

Hi!

Quoted 15 lines
m4/ltp-keyutils.m4 +9 -0
@@ -7,4 +7,17 @@ AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT], [
 	AC_CHECK_LIB([keyutils], [add_key],
 	[AC_DEFINE(HAVE_LIBKEYUTILS, 1, [Define to 1 if you have libkeyutils installed.])
 	      AC_SUBST(KEYUTILS_LIBS, "-lkeyutils")])
+
+	LTP_KEYCTL_HEADERS=""
+
+	if test "x$ac_cv_header_keyutils_h" = "xyes" && \
+	   test "x$ac_cv_lib_keyutils_add_key" = "xyes"; then
+		LTP_KEYCTL_HEADERS="#include <keyutils.h>"
+	elif test "x$ac_cv_header_linux_keyctl_h" = "xyes"; then
+		LTP_KEYCTL_HEADERS="#include <linux/keyctl.h>"
+	fi
Quoted 8 lines

m4/ltp-keyutils.m4 AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT], [ · line 23

Quoted 5 lines
m4/ltp-keyutils.m4 +4 -0
+
+	AC_CHECK_TYPES([struct keyctl_dh_params, struct keyctl_kdf_params,
+			struct keyctl_pkey_query, struct keyctl_pkey_params],,,
+			[$LTP_KEYCTL_HEADERS])
 ])

Maybe we can simplify this to just linux/keyctl.h. The linux uapi header has been quite stable for nearly a decade.

I was going to write the same. I checked that:

struct keyctl_dh_params was added in ddbb411487243 => v4.7-rc1.
struct keyctl_kdf_params was added in f1c316a3ab9d2 => v4.12-rc1
struct keyctl_pkey_query and keyctl_pkey_params were added in 00d60fd3b9321 => v4.20-rc1

And please move it to configure.ac.
(Ideally we would slowly simplify and move all m4/ltp-*.m4 to configure.ac.)

Anyway, very nice patchset, thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH v2 2/33 keyctl10: Test KEYCTL_DESCRIBE format parsing

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test the format parsing of KEYCTL_DESCRIBE: verify that describing a valid key returns a string formatted as "type;uid;gid;perm;description" and that all five fields match the key's attributes.

Also add keyctl_common.h helper header for shared test definitions.

---
 runtest/syscalls                                 |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore      |  1 +
 testcases/kernel/syscalls/keyctl/keyctl10.c      | 99 ++++++++++++++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl_common.h | 53 +++++++++++++
 4 files changed, 154 insertions(+)
runtest/syscalls +1 -0
index 737c63e31..bf4c0d46e 100644
@@ -727,6 +727,7 @@ keyctl06 keyctl06
 keyctl07 keyctl07
 keyctl08 keyctl08
 keyctl09 keyctl09
+keyctl10 keyctl10
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index f9948c176..08b2d101d 100644
@@ -7,3 +7,4 @@
 /keyctl07
 /keyctl08
 /keyctl09
+/keyctl10
testcases/kernel/syscalls/keyctl/keyctl10.c new file +99 -0

99 lines not on this page · raw message

testcases/kernel/syscalls/keyctl/keyctl_common.h new file +53 -0

53 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v2 02/33] keyctl10: Test KEYCTL_DESCRIBE format parsing

Hi!

Quoted 40 lines
testcases/kernel/syscalls/keyctl/keyctl_common.h new file +34 -0
new file mode 100644
index 000000000..c7290cc6e
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <[email protected]>
+ */
+
+#ifndef KEYCTL_COMMON_H__
+#define KEYCTL_COMMON_H__
+
+#include <stdint.h>
+#include <string.h>
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+#define KEY_PERM_ALL		(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL)
+#define KEY_PERM_SET		(KEY_POS_ALL | KEY_USR_ALL)
+
+#define KEY_VIEW_BITS		(KEY_POS_VIEW | KEY_USR_VIEW | KEY_GRP_VIEW | KEY_OTH_VIEW)
+#define KEY_PERM_NO_VIEW	(KEY_PERM_ALL & ~KEY_VIEW_BITS)
+
+#define KEY_WRITE_BITS		(KEY_POS_WRITE | KEY_USR_WRITE | KEY_GRP_WRITE | KEY_OTH_WRITE)
+#define KEY_PERM_NO_WRITE	(KEY_PERM_ALL & ~KEY_WRITE_BITS)
+
+#define KEY_SETATTR_BITS	(KEY_POS_SETATTR | KEY_USR_SETATTR | KEY_GRP_SETATTR | KEY_OTH_SETATTR)
+#define KEY_PERM_NO_SETATTR	(KEY_PERM_ALL & ~KEY_SETATTR_BITS)
+
+static inline key_serial_t new_ring(const char *desc)
+{
+	TEST(add_key("keyring", desc, NULL, 0, KEY_SPEC_PROCESS_KEYRING));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "failed to create keyring '%s'", desc);
+
+	return TST_RET;
+}

testcases/kernel/syscalls/keyctl/keyctl_common.h line 44

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl_common.h new file +10 -0
+
+static inline key_serial_t new_user_key(const char *desc, const void *payload,
+					size_t plen, key_serial_t ring)
+{
+	TEST(add_key("user", desc, payload, plen, ring));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "failed to add user key '%s'", desc);
+
+	return TST_RET;
+}

These looks like we are working around the need to add SAFE_ADD_KEY().

Even if we are going to keep them in keyctl_common.h I would stick to the SAFE_FOO() pattern, adding safe_add_key() first and building macros on the top of it. I.e.:

SAFE_NEW_RING(const char *desc) \
	safe_add_key(__FILE__, __LINE__, "keyring", desc, NULL, 0, KEY_SPEC_PROCESS_KEYRING)

testcases/kernel/syscalls/keyctl/keyctl_common.h line 51

Quoted 6 lines
testcases/kernel/syscalls/keyctl/keyctl_common.h new file +6 -0
+static inline key_serial_t search_ring(key_serial_t ring, const char *type,
+				       const char *desc)
+{
+	return keyctl(KEYCTL_SEARCH, ring, (unsigned long)type,
+		      (unsigned long)desc, 0);
+}

I'm not that sure this indirection is adding much value.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v2 3/33 keyctl11: Test KEYCTL_DESCRIBE with exact buffer size

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_DESCRIBE when called with a buffer sized exactly to the full description length: verify the string is copied completely including the terminating NUL byte.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl11.c | 62 +++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
runtest/syscalls +1 -0
index bf4c0d46e..7c9042471 100644
@@ -728,6 +728,7 @@ keyctl07 keyctl07
 keyctl08 keyctl08
 keyctl09 keyctl09
 keyctl10 keyctl10
+keyctl11 keyctl11
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 08b2d101d..4974fe48d 100644
@@ -8,3 +8,4 @@
 /keyctl08
 /keyctl09
 /keyctl10
+/keyctl11
testcases/kernel/syscalls/keyctl/keyctl11.c new file +62 -0

62 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH v2 03/33] keyctl11: Test KEYCTL_DESCRIBE with exact buffer size

Hi!

Quoted 19 lines
testcases/kernel/syscalls/keyctl/keyctl11.c new file +19 -0
+#include "keyctl_common.h"
+
+static key_serial_t key;
+static long desc_len;
+static char *buf;
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	key = new_user_key("k", "payload", 7, KEY_SPEC_PROCESS_KEYRING);
+	SAFE_KEYCTL(KEYCTL_SETPERM, key, KEY_PERM_SET, 0, 0);
+
+	TEST(keyctl(KEYCTL_DESCRIBE, key, (unsigned long)NULL, 0, 0));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "KEYCTL_DESCRIBE failed");
+
+	desc_len = TST_RET;
+	buf = SAFE_MALLOC(desc_len);

testcases/kernel/syscalls/keyctl/keyctl11.c line 43

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl11.c new file +10 -0
+}
+
+static void cleanup(void)
+{
+	free(buf);
+}
+
+static void run(void)
+{
+	memset(buf, 0, desc_len);

If we are trying to check that the string was copied including the terminating byte we should memset the buffer to 0xff, right?

testcases/kernel/syscalls/keyctl/keyctl11.c line 56

Quoted 13 lines
testcases/kernel/syscalls/keyctl/keyctl11.c new file +13 -0
+	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_DESCRIBE, key, (unsigned long)buf,
+				    desc_len, 0), desc_len);
+	if (!TST_PASS)
+		return;
+
+	if (buf[desc_len - 1] != '\0') {
+		tst_res(TFAIL, "description is not NUL terminated");
+		return;
+	}
+
+	tst_res(TPASS, "full description including NUL fits exact %ld byte buffer",
+		desc_len);
+}

Also this is quite similar to the previous test, maybe it would make sense to put this check in the previous test instead.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

PATCH v2 4/33 keyctl12: Test KEYCTL_DESCRIBE with too small buffer

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_DESCRIBE when called with a buffer smaller than the full description length: verify the buffer is left untouched and the return value still reports the full length.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl12.c | 62 +++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
runtest/syscalls +1 -0
index 7c9042471..d8e846e65 100644
@@ -729,6 +729,7 @@ keyctl08 keyctl08
 keyctl09 keyctl09
 keyctl10 keyctl10
 keyctl11 keyctl11
+keyctl12 keyctl12
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 4974fe48d..9ce6e2250 100644
@@ -9,3 +9,4 @@
 /keyctl09
 /keyctl10
 /keyctl11
+/keyctl12
testcases/kernel/syscalls/keyctl/keyctl12.c new file +62 -0

62 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v2 04/33] keyctl12: Test KEYCTL_DESCRIBE with too small buffer

Hi!

Quoted 8 lines
testcases/kernel/syscalls/keyctl/keyctl12.c new file +8 -0
+static void run(void)
+{
+	size_t i;
+
+	memset(buf, 0xAA, sizeof(buf));
+	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_DESCRIBE, key, (unsigned long)buf,
+				    desc_len - 1, 0), desc_len);
+	if (!TST_PASS)

testcases/kernel/syscalls/keyctl/keyctl12.c line 54

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl12.c new file +10 -0
+		return;
+
+	for (i = 0; i < sizeof(buf); i++) {
+		if (buf[i] != (char)0xAA) {
+			tst_res(TFAIL,
+				"too small buffer was written to at offset %zu",
+				i);
+			return;
+		}
+	}

It may make sense to loop this with:

	for (buf_len = 0; buf_len < desc_len; buf_len++) {
		...
	}

It should be fast and would increase the coverage..

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

Re: [LTP] [PATCH v2 04/33] keyctl12: Test KEYCTL_DESCRIBE with too small buffer

Quoted 22 lines

Hi!

Quoted 8 lines
testcases/kernel/syscalls/keyctl/keyctl12.c new file +8 -0
+static void run(void)
+{
+	size_t i;
+
+	memset(buf, 0xAA, sizeof(buf));
+	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_DESCRIBE, key, (unsigned long)buf,
+				    desc_len - 1, 0), desc_len);
+	if (!TST_PASS)

testcases/kernel/syscalls/keyctl/keyctl12.c line 54

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl12.c new file +10 -0
+		return;
+
+	for (i = 0; i < sizeof(buf); i++) {
+		if (buf[i] != (char)0xAA) {
+			tst_res(TFAIL,
+				"too small buffer was written to at offset %zu",
+				i);
+			return;
+		}
+	}

It may make sense to loop this with:

Quoted 5 lines
	for (buf_len = 0; buf_len < desc_len; buf_len++) {
		...
	}

It should be fast and would increase the coverage..

I suppose you want to check the actual key description in case it's longer than buffer size.

desc_len is 12, sizeof(buf) is 64 therefore it's safe but I'll change it in v3 so that it works in case of a longer key in the future.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

Re: [LTP] [PATCH v2 04/33] keyctl12: Test KEYCTL_DESCRIBE with too small buffer

Quoted 26 lines
Quoted 25 lines

Hi!

Quoted 8 lines
testcases/kernel/syscalls/keyctl/keyctl12.c new file +8 -0
+static void run(void)
+{
+	size_t i;
+
+	memset(buf, 0xAA, sizeof(buf));
+	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_DESCRIBE, key, (unsigned long)buf,
+				    desc_len - 1, 0), desc_len);
+	if (!TST_PASS)

testcases/kernel/syscalls/keyctl/keyctl12.c line 54

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl12.c new file +10 -0
+		return;
+
+	for (i = 0; i < sizeof(buf); i++) {
+		if (buf[i] != (char)0xAA) {
+			tst_res(TFAIL,
+				"too small buffer was written to at offset %zu",
+				i);
+			return;
+		}
+	}

It may make sense to loop this with:

	for (buf_len = 0; buf_len < desc_len; buf_len++) {
		...
	}
Quoted 7 lines
Quoted 1 line

It should be fast and would increase the coverage..

I suppose you want to check the actual key description in case it's longer than buffer size.

desc_len is 12, sizeof(buf) is 64 therefore it's safe but I'll change it in v3 so that it works in case of a longer key in the future.

Well, I thought I'd use

for (i = 0; i < desc_len; i++) {

but that could be problematic if desc_len (keyctl() return value) is higher sizeof(buf). Maybe I did not get what you meant.

Kind regards,
Petr

Quoted 2 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v2 5/33 keyctl13: Test KEYCTL_DESCRIBE size query

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_DESCRIBE when called with a NULL buffer and buflen 0:
verify the call succeeds and returns the full description length without writing to userspace memory.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl13.c | 46 +++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
runtest/syscalls +1 -0
index d8e846e65..25367084d 100644
@@ -730,6 +730,7 @@ keyctl09 keyctl09
 keyctl10 keyctl10
 keyctl11 keyctl11
 keyctl12 keyctl12
+keyctl13 keyctl13
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 9ce6e2250..d4ce61a6e 100644
@@ -10,3 +10,4 @@
 /keyctl10
 /keyctl11
 /keyctl12
+/keyctl13
testcases/kernel/syscalls/keyctl/keyctl13.c new file +46 -0

46 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH v2 6/33 keyctl14: Negative tests for KEYCTL_DESCRIBE

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test error conditions of KEYCTL_DESCRIBE using a parameterized tcase table: verify ENOKEY on a bogus key id and EACCES when View permission is missing.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl14.c | 54 +++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)
runtest/syscalls +1 -0
index 25367084d..160d2f798 100644
@@ -731,6 +731,7 @@ keyctl10 keyctl10
 keyctl11 keyctl11
 keyctl12 keyctl12
 keyctl13 keyctl13
+keyctl14 keyctl14
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index d4ce61a6e..8120454d8 100644
@@ -11,3 +11,4 @@
 /keyctl11
 /keyctl12
 /keyctl13
+/keyctl14
testcases/kernel/syscalls/keyctl/keyctl14.c new file +54 -0

54 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#16 lore raw

PATCH v2 7/33 keyctl15: Test KEYCTL_GET_SECURITY label retrieval

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_GET_SECURITY label retrieval: verify reading the security label of a valid key into a large buffer returns a positive length and an empty string when no LSM label is set.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl15.c | 66 +++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+)
runtest/syscalls +1 -0
index 160d2f798..da901baae 100644
@@ -732,6 +732,7 @@ keyctl11 keyctl11
 keyctl12 keyctl12
 keyctl13 keyctl13
 keyctl14 keyctl14
+keyctl15 keyctl15
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 8120454d8..852fee4ea 100644
@@ -12,3 +12,4 @@
 /keyctl12
 /keyctl13
 /keyctl14
+/keyctl15
testcases/kernel/syscalls/keyctl/keyctl15.c new file +66 -0

66 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw

Re: [LTP] [PATCH v2 07/33] keyctl15: Test KEYCTL_GET_SECURITY label retrieval

Hi!

Quoted 40 lines
testcases/kernel/syscalls/keyctl/keyctl15.c new file +34 -0
new file mode 100644
index 000000000..c281e9c69
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * Test ``KEYCTL_GET_SECURITY`` label retrieval of :manpage:`keyctl(2)`.
+ *
+ * ``KEYCTL_GET_SECURITY`` reads the LSM security label of a key.
+ * When no label is set (no LSM enabled or the LSM does not label keys)
+ * the operation returns 1 and an empty string.
+ *
+ * [Algorithm]
+ *
+ * - read the label of a valid key into a large buffer, verify the return
+ *   value is at least 1 and an empty string is returned when no label is set
+ */
+
+#include "keyctl_common.h"
+
+#define KEY_DESC	"ltpkeyctl15"
+#define PAYLOAD		"payload"
+#define BUF_SIZE	128
+
+static key_serial_t key;
+static char buf[BUF_SIZE];
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	key = new_user_key(KEY_DESC, PAYLOAD, sizeof(PAYLOAD),
+			   KEY_SPEC_PROCESS_KEYRING);
+	SAFE_KEYCTL(KEYCTL_SETPERM, key, KEY_PERM_SET, 0, 0);

testcases/kernel/syscalls/keyctl/keyctl15.c line 44

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl15.c new file +10 -0
+}
+
+static void run(void)
+{
+	memset(buf, 0, sizeof(buf));
+
+	TEST(keyctl(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "KEYCTL_GET_SECURITY failed");
+

TST_EXP_POSITIVE()?

testcases/kernel/syscalls/keyctl/keyctl15.c line 58

Quoted 13 lines
testcases/kernel/syscalls/keyctl/keyctl15.c new file +13 -0
+	if (TST_RET < 1) {
+		tst_res(TFAIL, "returned %ld, expected at least 1", TST_RET);
+		return;
+	}
+	if (TST_RET == 1) {
+		if (buf[0] != '\0') {
+			tst_res(TFAIL, "empty label is not NUL terminated");
+			return;
+		}
+
+		tst_res(TPASS, "no label set, empty string returned");
+		return;
+	}

Is the string supposed to be null terminated? Shouldn't we just check that the is null at the end regardless the length (we fail the test if < 1 either way)?

Quoted 14 lines
testcases/kernel/syscalls/keyctl/keyctl15.c new file +7 -0
+	tst_res(TPASS, "security label returned, full length %ld", TST_RET);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+};
Signature · 6 lines
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#18 lore raw

Re: [LTP] [PATCH v2 07/33] keyctl15: Test KEYCTL_GET_SECURITY label retrieval

...

Quoted 9 lines

testcases/kernel/syscalls/keyctl/keyctl15.c line 44

Quoted 8 lines
testcases/kernel/syscalls/keyctl/keyctl15.c new file +8 -0
+static void run(void)
+{
+	memset(buf, 0, sizeof(buf));
+
+	TEST(keyctl(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "KEYCTL_GET_SECURITY failed");
+

TST_EXP_POSITIVE()?

Well, it would not help much because Andrea wanted to use tst_brk(). I've been thinking for a while to add TST_EXP_*_BRK() variants.

Therefore it would need to check the result anyway:

TST_EXP_POSITIVE(keyctl(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0)); if (TST_PASS)

	tst_brk(TBROK | TTERRNO, "KEYCTL_GET_SECURITY failed");

(And I ignore that we don't have TST_EXP_POSITIVE_SILENT() and probably we don't want to call TST_EXP_POSITIVE_() to make it quiet on TPASS).

Kind regards,
Petr

Quoted 9 lines
Quoted 9 lines
testcases/kernel/syscalls/keyctl/keyctl15.c new file +9 -0
+	if (TST_RET < 1) {
+		tst_res(TFAIL, "returned %ld, expected at least 1", TST_RET);
+		return;
+	}
+	if (TST_RET == 1) {
+		if (buf[0] != '\0') {
+			tst_res(TFAIL, "empty label is not NUL terminated");
+			return;
+		}
Quoted 8 lines

testcases/kernel/syscalls/keyctl/keyctl15.c line 58

Quoted 4 lines
testcases/kernel/syscalls/keyctl/keyctl15.c new file +4 -0
+
+		tst_res(TPASS, "no label set, empty string returned");
+		return;
+	}

Is the string supposed to be null terminated? Shouldn't we just check that the is null at the end regardless the length (we fail the test if < 1 either way)?

+1

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#19 lore raw

Re: [LTP] [PATCH v2 07/33] keyctl15: Test KEYCTL_GET_SECURITY label retrieval

Hi!

Quoted 5 lines
Quoted 1 line

TST_EXP_POSITIVE()?

Well, it would not help much because Andrea wanted to use tst_brk(). I've been thinking for a while to add TST_EXP_*_BRK() variants.

Quoted 8 lines

Therefore it would need to check the result anyway:

TST_EXP_POSITIVE(keyctl(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0)); if (TST_PASS)

	tst_brk(TBROK | TTERRNO, "KEYCTL_GET_SECURITY failed");

(And I ignore that we don't have TST_EXP_POSITIVE_SILENT() and probably we don't want to call TST_EXP_POSITIVE_() to make it quiet on TPASS).

Why can't we just do:

	TST_EXP_POSITIVE(keyctl(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0));
	if (!TST_PASS)
		return;
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#20 lore raw

Re: [LTP] [PATCH v2 07/33] keyctl15: Test KEYCTL_GET_SECURITY label retrieval

Quoted 13 lines

Hi!

Quoted 10 lines
Quoted 1 line

TST_EXP_POSITIVE()?

Well, it would not help much because Andrea wanted to use tst_brk(). I've been thinking for a while to add TST_EXP_*_BRK() variants.

Therefore it would need to check the result anyway:

TST_EXP_POSITIVE(keyctl(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0)); if (TST_PASS)

	tst_brk(TBROK | TTERRNO, "KEYCTL_GET_SECURITY failed");
Quoted 8 lines
Quoted 2 lines

(And I ignore that we don't have TST_EXP_POSITIVE_SILENT() and probably we don't want to call TST_EXP_POSITIVE_() to make it quiet on TPASS).

Why can't we just do:

	TST_EXP_POSITIVE(keyctl(KEYCTL_GET_SECURITY, key, (unsigned long)buf, sizeof(buf), 0));
	if (!TST_PASS)
		return;

Right, return would work here as well. And generally it would work unless code is more structured (i.e. test macro is not directly in .test_all/.test function. That should eliminate many of TST_*_BRK() potential use.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#21 lore raw

PATCH v2 8/33 keyctl16: Test KEYCTL_GET_SECURITY truncated copy

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_GET_SECURITY truncated copy behavior: verify that calling with a 1-byte buffer receives exactly one byte while the return value still reports the full label length.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl16.c | 74 +++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
runtest/syscalls +1 -0
index da901baae..89c8a95af 100644
@@ -733,6 +733,7 @@ keyctl12 keyctl12
 keyctl13 keyctl13
 keyctl14 keyctl14
 keyctl15 keyctl15
+keyctl16 keyctl16
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 852fee4ea..c351716d0 100644
@@ -13,3 +13,4 @@
 /keyctl13
 /keyctl14
 /keyctl15
+/keyctl16
testcases/kernel/syscalls/keyctl/keyctl16.c new file +74 -0

74 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#22 lore raw

Re: [LTP] [PATCH v2 08/33] keyctl16: Test KEYCTL_GET_SECURITY truncated copy

Hi!

Quoted 15 lines
testcases/kernel/syscalls/keyctl/keyctl16.c new file +15 -0
+static void run(void)
+{
+	size_t i;
+
+	memset(buf, 0xAA, sizeof(buf));
+	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_GET_SECURITY, key,
+				    (unsigned long)buf, 1, 0), sec_len);
+	if (!TST_PASS)
+		return;
+
+	if (buf[0] == (char)0xAA) {
+		tst_res(TFAIL, "nothing was copied into the buffer");
+		return;
+	}
+

testcases/kernel/syscalls/keyctl/keyctl16.c line 68

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl16.c new file +10 -0
+	for (i = 1; i < sizeof(buf); i++) {
+		if (buf[i] != (char)0xAA) {
+			tst_res(TFAIL, "copy overran the buffer at offset %zu",
+				i);
+			return;
+		}
+	}
+
+	tst_res(TPASS, "exactly one byte copied, full length %ld returned",
+		sec_len);

Here as well, we can loop over all truncated lengths.

Quoted 13 lines
testcases/kernel/syscalls/keyctl/keyctl16.c new file +6 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+};
Signature · 6 lines
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#23 lore raw

PATCH v2 9/33 keyctl17: Negative tests for KEYCTL_GET_SECURITY

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test error conditions of KEYCTL_GET_SECURITY using a parameterized tcase table: verify ENOKEY on a bogus key id and ENOKEY when View permission is missing (due to the kernel request-key auth token fallback path).

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl17.c | 55 +++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)
runtest/syscalls +1 -0
index 89c8a95af..fcc1d58a8 100644
@@ -734,6 +734,7 @@ keyctl13 keyctl13
 keyctl14 keyctl14
 keyctl15 keyctl15
 keyctl16 keyctl16
+keyctl17 keyctl17
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index c351716d0..dddb45f85 100644
@@ -14,3 +14,4 @@
 /keyctl14
 /keyctl15
 /keyctl16
+/keyctl17
testcases/kernel/syscalls/keyctl/keyctl17.c new file +55 -0

55 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#25 lore raw

PATCH v2 10/33 keyctl18: Test basic KEYCTL_MOVE

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test basic moving of a key between two keyrings with KEYCTL_MOVE:
verify the key is moved to the destination and no longer found in the source keyring.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl18.c | 60 +++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
runtest/syscalls +1 -0
index fcc1d58a8..895dd0fc4 100644
@@ -735,6 +735,7 @@ keyctl14 keyctl14
 keyctl15 keyctl15
 keyctl16 keyctl16
 keyctl17 keyctl17
+keyctl18 keyctl18
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index dddb45f85..808cd2d23 100644
@@ -15,3 +15,4 @@
 /keyctl15
 /keyctl16
 /keyctl17
+/keyctl18
testcases/kernel/syscalls/keyctl/keyctl18.c new file +60 -0

60 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#26 lore raw

Re: [LTP] [PATCH v2 10/33] keyctl18: Test basic KEYCTL_MOVE

Hi!

Quoted 8 lines
testcases/kernel/syscalls/keyctl/keyctl18.c new file +8 -0
+static key_serial_t ring_a, ring_b;
+static key_serial_t key;
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	ring_a = new_ring(RING_A_DESC);

testcases/kernel/syscalls/keyctl/keyctl18.c line 39

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl18.c new file +10 -0
+	ring_b = new_ring(RING_B_DESC);
+	key = new_user_key(KEY_DESC, PAYLOAD, sizeof(PAYLOAD), ring_a);
+}
+
+static void reset_state(void)
+{
+	SAFE_KEYCTL(KEYCTL_LINK, key, ring_a, 0, 0);
+	TEST(keyctl(KEYCTL_UNLINK, key, ring_b, 0, 0));
+	if (TST_RET == -1 && TST_ERR != ENOENT)
+		tst_brk(TBROK | TTERRNO, "failed to unlink key from ring_b");

We are trying to avoid hypotetical TBROK here in the case that the MOVE didn't work right? I'm not sure it's worth the trouble.

Quoted 4 lines
testcases/kernel/syscalls/keyctl/keyctl18.c new file +4 -0
+}
+
+static void run(void)
+{

testcases/kernel/syscalls/keyctl/keyctl18.c line 53

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl18.c new file +10 -0
+	reset_state();
+
+	TST_EXP_PASS(keyctl(KEYCTL_MOVE, key, ring_a, ring_b, 0));
+	if (!TST_PASS)
+		return;
+
+	TST_EXP_EQ_LI(search_ring(ring_b, "user", KEY_DESC), key);
+
+	TST_EXP_FAIL2(search_ring(ring_a, "user", KEY_DESC), ENOKEY,
+		      "key no longer found in the source keyring");

Here the search_string() function actually hides the syscall being used. I would prefer having the keyctl() call in these two.

Quoted 14 lines
testcases/kernel/syscalls/keyctl/keyctl18.c new file +7 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.min_kver = "5.3",
+};
Signature · 6 lines
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#27 lore raw

PATCH v2 11/33 keyctl19: Test KEYCTL_MOVE with same source and destination

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_MOVE when the source keyring equals the destination
keyring: verify the operation succeeds as a no-op and the key remains linked in the keyring.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl19.c | 43 +++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)
runtest/syscalls +1 -0
index 895dd0fc4..1935bee31 100644
@@ -736,6 +736,7 @@ keyctl15 keyctl15
 keyctl16 keyctl16
 keyctl17 keyctl17
 keyctl18 keyctl18
+keyctl19 keyctl19
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 808cd2d23..f32107923 100644
@@ -16,3 +16,4 @@
 /keyctl16
 /keyctl17
 /keyctl18
+/keyctl19
testcases/kernel/syscalls/keyctl/keyctl19.c new file +43 -0

43 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#29 lore raw

PATCH v2 12/33 keyctl20: Test KEYCTL_MOVE displacement

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_MOVE displacement behavior: verify moving a key without KEYCTL_MOVE_EXCL into a destination holding a matching key displaces the existing key.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl20.c | 62 +++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
runtest/syscalls +1 -0
index 1935bee31..bfe4090a0 100644
@@ -737,6 +737,7 @@ keyctl16 keyctl16
 keyctl17 keyctl17
 keyctl18 keyctl18
 keyctl19 keyctl19
+keyctl20 keyctl20
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index f32107923..acddfa79e 100644
@@ -17,3 +17,4 @@
 /keyctl17
 /keyctl18
 /keyctl19
+/keyctl20
testcases/kernel/syscalls/keyctl/keyctl20.c new file +62 -0

62 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#30 lore raw

Re: [LTP] [PATCH v2 12/33] keyctl20: Test KEYCTL_MOVE displacement

Hi!

Quoted 18 lines
testcases/kernel/syscalls/keyctl/keyctl20.c new file +18 -0
+#define RING_A_DESC	"ltpkeyctl20_a"
+#define RING_B_DESC	"ltpkeyctl20_b"
+#define KEY_DESC	"k"
+#define PAYLOAD		"payload"
+
+static key_serial_t ring_a, ring_b;
+static key_serial_t key_a, key_excl;
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	ring_a = new_ring(RING_A_DESC);
+	ring_b = new_ring(RING_B_DESC);
+
+	key_a = new_user_key(KEY_DESC, PAYLOAD, sizeof(PAYLOAD), ring_a);
+	key_excl = new_user_key(KEY_DESC, PAYLOAD, sizeof(PAYLOAD), ring_b);
+

testcases/kernel/syscalls/keyctl/keyctl20.c line 44

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl20.c new file +10 -0
+	/* Keep key_excl in session keyring so displacement does not destroy it */
+	SAFE_KEYCTL(KEYCTL_LINK, key_excl, KEY_SPEC_SESSION_KEYRING, 0, 0);
+}
+
+static void reset_state(void)
+{
+	SAFE_KEYCTL(KEYCTL_LINK, key_a, ring_a, 0, 0);
+	TEST(keyctl(KEYCTL_UNLINK, key_a, ring_b, 0, 0));
+	if (TST_RET == -1 && TST_ERR != ENOENT)
+		tst_brk(TBROK | TTERRNO, "failed to unlink key_a from ring_b");

Here as well, not sure if this is worth the trouble.

testcases/kernel/syscalls/keyctl/keyctl20.c line 55

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl20.c new file +10 -0
+	SAFE_KEYCTL(KEYCTL_LINK, key_excl, ring_b, 0, 0);
+}
+
+static void run(void)
+{
+	reset_state();
+
+	TST_EXP_PASS(keyctl(KEYCTL_MOVE, key_a, ring_a, ring_b, 0));
+
+	TST_EXP_EQ_LI(search_ring(ring_b, "user", KEY_DESC), key_a);

And here as well.

Quoted 14 lines
testcases/kernel/syscalls/keyctl/keyctl20.c new file +7 -0
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.min_kver = "5.3",
+};
Signature · 6 lines
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#31 lore raw

PATCH v2 13/33 keyctl21: Negative and boundary tests for KEYCTL_MOVE

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test error and boundary conditions of KEYCTL_MOVE using a parameterized tcase table: KEYCTL_MOVE_EXCL (EEXIST), unknown flag bits (EINVAL), bogus IDs (ENOKEY), non-keyrings (ENOTDIR), unlinked key (ENOENT), keyring cycle (EDEADLK), and destination without Write permission (EACCES).

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl21.c | 111 ++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
runtest/syscalls +1 -0
index bfe4090a0..b95264564 100644
@@ -738,6 +738,7 @@ keyctl17 keyctl17
 keyctl18 keyctl18
 keyctl19 keyctl19
 keyctl20 keyctl20
+keyctl21 keyctl21
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index acddfa79e..e8c71e79e 100644
@@ -18,3 +18,4 @@
 /keyctl18
 /keyctl19
 /keyctl20
+/keyctl21
testcases/kernel/syscalls/keyctl/keyctl21.c new file +111 -0

111 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#32 lore raw

Re: [LTP] [PATCH v2 13/33] keyctl21: Negative and boundary tests for KEYCTL_MOVE

Hi!

Quoted 116 lines

Test error and boundary conditions of KEYCTL_MOVE using a parameterized tcase table: KEYCTL_MOVE_EXCL (EEXIST), unknown flag bits (EINVAL), bogus IDs (ENOKEY), non-keyrings (ENOTDIR), unlinked key (ENOENT), keyring cycle (EDEADLK), and destination without Write permission (EACCES).

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl21.c | 111 ++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+)
runtest/syscalls +1 -0
index bfe4090a0..b95264564 100644
@@ -738,6 +738,7 @@ keyctl17 keyctl17
 keyctl18 keyctl18
 keyctl19 keyctl19
 keyctl20 keyctl20
+keyctl21 keyctl21
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index acddfa79e..e8c71e79e 100644
@@ -18,3 +18,4 @@
 /keyctl18
 /keyctl19
 /keyctl20
+/keyctl21
testcases/kernel/syscalls/keyctl/keyctl21.c new file +76 -0
new file mode 100644
index 000000000..a2db5a406
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * Negative and boundary test cases for ``KEYCTL_MOVE`` of :manpage:`keyctl(2)`.
+ *
+ * [Algorithm]
+ *
+ * - ``KEYCTL_MOVE_EXCL`` fails with ``EEXIST`` when the destination already
+ *   holds a matching key
+ * - unknown flag bits are rejected with ``EINVAL``
+ * - bogus key or keyring ids fail with ``ENOKEY``
+ * - a plain key used as source or destination keyring fails with ``ENOTDIR``
+ * - moving a key that is not linked in the source fails with ``ENOENT``
+ * - moving a keyring into itself fails with ``EDEADLK`` from the keyring
+ *   cycle detection
+ * - moving into a keyring without Write permission fails with ``EACCES``
+ */
+
+#include "keyctl_common.h"
+
+#define RING_A_DESC	"ltpkeyctl21_a"
+#define RING_B_DESC	"ltpkeyctl21_b"
+#define RING_C_DESC	"ltpkeyctl21_c"
+#define KEY_A_DESC	"ka"
+#define KEY_B_DESC	"kb"
+#define PAYLOAD		"payload"
+
+static key_serial_t ring_a, ring_b, ring_c, ring_no_write;
+static key_serial_t key_a, key_b, key_excl;
+static key_serial_t bogus_id = INT32_MAX;
+
+static struct tcase {
+	key_serial_t *keyid;
+	key_serial_t *from;
+	key_serial_t *to;
+	unsigned int flags;
+	int exp_errno;
+	const char *desc;
+} tcases[] = {
+	{ &key_a, &ring_a, &ring_b, KEYCTL_MOVE_EXCL,
+	  EEXIST, "KEYCTL_MOVE_EXCL on existing key" },
+
+	{ &key_a, &ring_a, &ring_b, 0x2,
+	  EINVAL, "unknown flag bits" },
+
+	{ &bogus_id, &ring_a, &ring_b, 0,
+	  ENOKEY, "bogus key id" },
+
+	{ &key_a, &bogus_id, &ring_b, 0,
+	  ENOKEY, "bogus source keyring" },
+
+	{ &key_a, &ring_a, &bogus_id, 0,
+	  ENOKEY, "bogus destination keyring" },
+
+	{ &key_a, &key_b, &ring_b, 0,
+	  ENOTDIR, "plain key as source keyring" },
+
+	{ &key_a, &ring_a, &key_b, 0,
+	  ENOTDIR, "plain key as destination keyring" },
+
+	{ &key_b, &ring_a, &ring_b, 0,
+	  ENOENT, "key not linked in the source keyring" },
+
+	{ &ring_c, &ring_b, &ring_c, 0,
+	  EDEADLK, "keyring into itself" },
+
+	{ &key_a, &ring_a, &ring_no_write, 0,
+	  EACCES, "destination without Write permission" },
+};
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);

testcases/kernel/syscalls/keyctl/keyctl21.c line 86

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl21.c new file +10 -0
+
+	ring_a = new_ring(RING_A_DESC);
+	ring_b = new_ring(RING_B_DESC);
+	ring_c = new_ring(RING_C_DESC);
+	ring_no_write = new_ring("ltpkeyctl21_nowrite");
+	SAFE_KEYCTL(KEYCTL_SETPERM, ring_no_write, KEY_PERM_NO_WRITE, 0, 0);
+
+	key_a = new_user_key(KEY_A_DESC, PAYLOAD, sizeof(PAYLOAD), ring_a);
+	key_b = new_user_key(KEY_B_DESC, PAYLOAD, sizeof(PAYLOAD), ring_b);
+	key_excl = new_user_key(KEY_A_DESC, PAYLOAD, sizeof(PAYLOAD), ring_b);

Same here, the new_ring and new_user_key should have been SAFE_.. macros.

Other than that it looks fine.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#33 lore raw

PATCH v2 14/33 keyctl22: Test KEYCTL_RESTRICT_KEYRING reject-all

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_RESTRICT_KEYRING reject-all restriction: verify that restricting a keyring with NULL type and NULL restriction succeeds, and subsequent link and add_key attempts fail with EPERM.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl22.c | 54 +++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)
runtest/syscalls +1 -0
index b95264564..262ef967d 100644
@@ -739,6 +739,7 @@ keyctl18 keyctl18
 keyctl19 keyctl19
 keyctl20 keyctl20
 keyctl21 keyctl21
+keyctl22 keyctl22
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index e8c71e79e..82a74e4a3 100644
@@ -19,3 +19,4 @@
 /keyctl19
 /keyctl20
 /keyctl21
+/keyctl22
testcases/kernel/syscalls/keyctl/keyctl22.c new file +54 -0

54 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#34 lore raw

Re: [LTP] [PATCH v2 14/33] keyctl22: Test KEYCTL_RESTRICT_KEYRING reject-all

Hi!

Quoted 14 lines
testcases/kernel/syscalls/keyctl/keyctl22.c new file +14 -0
+/*\
+ * Test ``KEYCTL_RESTRICT_KEYRING`` reject-all of :manpage:`keyctl(2)`,
+ * added in Linux 4.12.
+ *
+ * [Algorithm]
+ *
+ * - restrict a keyring with ``NULL`` type and ``NULL`` restriction (reject all links),
+ *   verify subsequent links and add_key fail with ``EPERM``
+ */
+
+#include "keyctl_common.h"
+
+#define PAYLOAD		"payload"
+

testcases/kernel/syscalls/keyctl/keyctl22.c line 29

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl22.c new file +10 -0
+static key_serial_t ring_reject;
+static key_serial_t user_key;
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	ring_reject = new_ring("ltpkeyctl22_reject");
+	user_key = new_user_key("k", PAYLOAD, sizeof(PAYLOAD),
+				KEY_SPEC_PROCESS_KEYRING);

Here as well.

Otherwise it looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#35 lore raw

PATCH v2 15/33 keyctl23: Test KEYCTL_RESTRICT_KEYRING builtin_trusted

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_RESTRICT_KEYRING builtin_trusted restriction: verify that restricting a keyring with asymmetric builtin_trusted allows only trusted asymmetric keys, rejecting user keys with EOPNOTSUPP and untrusted certs with ENOKEY.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl23.c | 142 ++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
runtest/syscalls +1 -0
index 262ef967d..f7c4830a9 100644
@@ -740,6 +740,7 @@ keyctl19 keyctl19
 keyctl20 keyctl20
 keyctl21 keyctl21
 keyctl22 keyctl22
+keyctl23 keyctl23
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 82a74e4a3..803e4e94c 100644
@@ -20,3 +20,4 @@
 /keyctl20
 /keyctl21
 /keyctl22
+/keyctl23
testcases/kernel/syscalls/keyctl/keyctl23.c new file +142 -0

142 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#36 lore raw

Re: [LTP] [PATCH v2 15/33] keyctl23: Test KEYCTL_RESTRICT_KEYRING builtin_trusted

Hi!

Quoted 140 lines

Test KEYCTL_RESTRICT_KEYRING builtin_trusted restriction: verify that restricting a keyring with asymmetric builtin_trusted allows only trusted asymmetric keys, rejecting user keys with EOPNOTSUPP and untrusted certs with ENOKEY.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl23.c | 142 ++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
runtest/syscalls +1 -0
index 262ef967d..f7c4830a9 100644
@@ -740,6 +740,7 @@ keyctl19 keyctl19
 keyctl20 keyctl20
 keyctl21 keyctl21
 keyctl22 keyctl22
+keyctl23 keyctl23
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 82a74e4a3..803e4e94c 100644
@@ -20,3 +20,4 @@
 /keyctl20
 /keyctl21
 /keyctl22
+/keyctl23
testcases/kernel/syscalls/keyctl/keyctl23.c new file +101 -0
new file mode 100644
index 000000000..76e0f8954
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * Test ``KEYCTL_RESTRICT_KEYRING`` builtin_trusted of :manpage:`keyctl(2)`.
+ *
+ * Requires root (CAP_SYS_MODULE) to load the ``x509_key_parser`` module.
+ *
+ * [Algorithm]
+ *
+ * - restrict a keyring with ``asymmetric`` and ``builtin_trusted``, verify
+ *   linking a user key fails with ``EOPNOTSUPP`` and adding an untrusted
+ *   cert fails with ``ENOKEY``
+ */
+
+#include "keyctl_common.h"
+#include "tst_module.h"
+
+#define PAYLOAD		"payload"
+
+/*
+ * Self-signed RSA-2048 X.509 certificate in DER format generated using:
+ * openssl req -x509 -newkey rsa:2048 -subj "/CN=ltp-keyctl23-untrusted" \
+ *     -days 36500 -nodes -batch -outform der
+ *
+ * Used only as an untrusted certificate to verify that add_key() on a
+ * keyring restricted with builtin_trusted rejects it with ENOKEY.
+ */
+static const unsigned char untrusted_cert[] = {
+	0x30, 0x82, 0x03, 0x25, 0x30, 0x82, 0x02, 0x0d, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x14, 0x52,
+	0xad, 0xef, 0x01, 0xca, 0xbb, 0x64, 0x17, 0xa7, 0x1a, 0xa7, 0xcb, 0x2f, 0x82, 0x44, 0x6e, 0xec,
+	0x5a, 0x2e, 0x2c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
+	0x05, 0x00, 0x30, 0x21, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x6c,
+	0x74, 0x70, 0x2d, 0x6b, 0x65, 0x79, 0x63, 0x74, 0x6c, 0x32, 0x33, 0x2d, 0x75, 0x6e, 0x74, 0x72,
+	0x75, 0x73, 0x74, 0x65, 0x64, 0x30, 0x20, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x39, 0x30, 0x32, 0x30,
+	0x39, 0x32, 0x33, 0x34, 0x39, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x32, 0x36, 0x30, 0x38, 0x30, 0x39,
+	0x30, 0x39, 0x32, 0x33, 0x34, 0x39, 0x5a, 0x30, 0x21, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55,
+	0x04, 0x03, 0x0c, 0x16, 0x6c, 0x74, 0x70, 0x2d, 0x6b, 0x65, 0x79, 0x63, 0x74, 0x6c, 0x32, 0x33,
+	0x2d, 0x75, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d,
+	0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
+	0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xd5, 0xee, 0x8d, 0xec, 0x85,
+	0x8e, 0x29, 0xc7, 0xe7, 0xf8, 0x3f, 0xed, 0xc8, 0x82, 0xb2, 0x17, 0x95, 0xf4, 0xe0, 0x99, 0x02,
+	0x84, 0xc5, 0xb3, 0x46, 0x62, 0x8c, 0x8a, 0xd3, 0x89, 0xd5, 0x62, 0x25, 0xa7, 0xc8, 0x92, 0xcc,
+	0xc5, 0x64, 0x20, 0x80, 0xb7, 0xf3, 0xc2, 0x40, 0xdc, 0xf0, 0xf0, 0xd8, 0x85, 0x5f, 0x58, 0x61,
+	0x77, 0xd6, 0xd5, 0x3a, 0x32, 0xec, 0x81, 0x15, 0x25, 0xb4, 0x08, 0x21, 0x6d, 0xf3, 0xd6, 0x80,
+	0xa6, 0x91, 0x5a, 0x53, 0x9e, 0x54, 0x49, 0x5b, 0x91, 0x6b, 0x74, 0x0b, 0xb5, 0x99, 0xd5, 0x49,
+	0x46, 0x41, 0x56, 0x67, 0xb4, 0xed, 0x17, 0x82, 0x96, 0x03, 0x40, 0xd7, 0x0d, 0x0a, 0x00, 0x95,
+	0x3c, 0xb7, 0x75, 0x9e, 0x61, 0xab, 0xe9, 0x10, 0x4a, 0xa9, 0x90, 0x21, 0xd2, 0xb4, 0x3d, 0xd0,
+	0x83, 0x48, 0x0c, 0x59, 0xa9, 0xd7, 0xbe, 0x7b, 0x4c, 0x75, 0xf0, 0xd1, 0x8a, 0x29, 0x1c, 0x06,
+	0x35, 0x29, 0x6d, 0x3c, 0x6e, 0xb9, 0xce, 0x11, 0xa9, 0x1b, 0x4d, 0xf7, 0xfd, 0x6d, 0x2e, 0x02,
+	0x7f, 0xbe, 0x45, 0xb7, 0x11, 0xae, 0x1d, 0xbb, 0x70, 0x02, 0xae, 0xc1, 0xb3, 0x31, 0x3d, 0x99,
+	0xd9, 0x70, 0x01, 0xbd, 0xea, 0xd3, 0x0d, 0x04, 0xe0, 0x2f, 0xac, 0x79, 0xe4, 0xb2, 0x0c, 0x96,
+	0xba, 0x66, 0x9e, 0xcf, 0x72, 0x13, 0xa3, 0x37, 0x44, 0x03, 0x2d, 0xe9, 0x5c, 0x71, 0x6f, 0x35,
+	0x71, 0xf8, 0xdc, 0x58, 0xa3, 0x1f, 0x57, 0x88, 0x59, 0x79, 0xe6, 0x7e, 0x37, 0x9b, 0xc9, 0xa3,
+	0x36, 0x03, 0x5c, 0xcb, 0x30, 0x92, 0x5e, 0x9e, 0x43, 0x48, 0xa2, 0x3e, 0x7f, 0xdc, 0xb8, 0xe3,
+	0x6a, 0xe6, 0x8c, 0x18, 0xb2, 0x42, 0x4c, 0xbb, 0x2d, 0x6a, 0x6c, 0x5f, 0xd1, 0xc1, 0xd5, 0x33,
+	0x3b, 0xdb, 0x8c, 0x3c, 0xa2, 0xec, 0xaa, 0xed, 0xce, 0xe1, 0xd1, 0x02, 0x03, 0x01, 0x00, 0x01,
+	0xa3, 0x53, 0x30, 0x51, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xd3,
+	0x8d, 0xd1, 0xe4, 0x77, 0x4e, 0xe2, 0xb2, 0xb6, 0xab, 0x31, 0x58, 0x69, 0x7b, 0x27, 0x31, 0xce,
+	0x00, 0xcd, 0x60, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14,
+	0xd3, 0x8d, 0xd1, 0xe4, 0x77, 0x4e, 0xe2, 0xb2, 0xb6, 0xab, 0x31, 0x58, 0x69, 0x7b, 0x27, 0x31,
+	0xce, 0x00, 0xcd, 0x60, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05,
+	0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
+	0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x1e, 0xb9, 0x52, 0x16, 0xf2, 0xef, 0xca,
+	0xbc, 0x35, 0x93, 0xb4, 0x38, 0xb8, 0xab, 0xfe, 0x73, 0x1a, 0x06, 0x50, 0x99, 0x58, 0xc4, 0xa8,
+	0xf4, 0x26, 0xb1, 0xe1, 0x8e, 0x0b, 0xd3, 0xe7, 0xa8, 0x8d, 0x1f, 0xa0, 0x79, 0x4c, 0x9f, 0xdd,
+	0x3a, 0xf0, 0xb7, 0xf2, 0x18, 0xfc, 0x99, 0x11, 0x45, 0x8f, 0xeb, 0xc9, 0xf2, 0x48, 0x2e, 0x4a,
+	0x7b, 0x24, 0x37, 0xa4, 0xbc, 0x52, 0x96, 0x80, 0x76, 0x46, 0x59, 0x27, 0xb5, 0xa0, 0x07, 0x5b,
+	0x6c, 0x38, 0x5c, 0xde, 0x95, 0x76, 0xfc, 0x21, 0xb8, 0x1e, 0x7e, 0x13, 0x3e, 0x59, 0x95, 0xf9,
+	0x39, 0xdb, 0xd5, 0x41, 0x3d, 0x8d, 0xfd, 0x4c, 0x1a, 0x4b, 0xdd, 0x41, 0x3b, 0x27, 0x58, 0xf8,
+	0x72, 0xa3, 0x70, 0x97, 0xc6, 0xb9, 0x0e, 0x4e, 0x3c, 0x08, 0xba, 0x2f, 0xa9, 0x55, 0x6d, 0x23,
+	0xdd, 0xc4, 0x0a, 0x43, 0xad, 0x20, 0x75, 0x0d, 0xea, 0xbc, 0x49, 0x6c, 0xd2, 0x87, 0x59, 0x46,
+	0x72, 0x3e, 0x77, 0x9b, 0x29, 0x63, 0x38, 0x0a, 0x2f, 0x61, 0xcc, 0xda, 0xd0, 0x21, 0x47, 0x6f,
+	0x9f, 0x19, 0x26, 0x0c, 0xbb, 0x77, 0x22, 0x8d, 0xc7, 0x65, 0x01, 0x25, 0x4b, 0x69, 0x38, 0xae,
+	0x6e, 0x16, 0x4f, 0x70, 0x35, 0xab, 0xea, 0x76, 0xe4, 0x37, 0xe4, 0x92, 0x6b, 0xf0, 0x6e, 0xc5,
+	0x4c, 0xc1, 0x37, 0xc1, 0x28, 0xa6, 0x78, 0xc7, 0x90, 0xb4, 0xea, 0xbb, 0x8d, 0x12, 0xe1, 0x30,
+	0xe1, 0x7b, 0x76, 0xc3, 0x65, 0xc3, 0x99, 0x7b, 0xb3, 0xb1, 0x9a, 0xe9, 0x73, 0xb2, 0x4d, 0x08,
+	0x2a, 0xa4, 0x67, 0x42, 0xef, 0x7c, 0xf5, 0x67, 0x3e, 0xa4, 0x78, 0xe1, 0x04, 0x93, 0x5e, 0x1b,
+	0xf9, 0xae, 0xe1, 0x5a, 0x7f, 0x42, 0x38, 0xb7, 0x93, 0xfb, 0x27, 0xff, 0x1c, 0x7e, 0xdd, 0x8a,
+	0x71, 0x10, 0xcb, 0x65, 0xc9, 0xf2, 0x0f, 0x9e, 0x7d,
+};
+
+static key_serial_t ring_builtin;
+static key_serial_t user_key;
+static int asym_supported;
+
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	tst_modprobe("x509_key_parser", NULL);
+
+	ring_builtin = new_ring("ltpkeyctl23_builtin");
+
+	user_key = new_user_key("k", PAYLOAD, sizeof(PAYLOAD),
+				KEY_SPEC_PROCESS_KEYRING);
+
+	/* Probe if asymmetric key type is supported */
+	TEST(keyctl(KEYCTL_RESTRICT_KEYRING, ring_builtin,

testcases/kernel/syscalls/keyctl/keyctl23.c line 111

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl23.c new file +10 -0
+		    (unsigned long)"asymmetric", (unsigned long)"bogus", 0));
+	asym_supported = (TST_RET != -1 || TST_ERR != ENODEV);
+}
+
+static void run(void)
+{
+	if (!asym_supported) {
+		tst_res(TCONF, "asymmetric key type not supported");
+		return;
+	}

We can tst_brk(TCONF, "") directly in the test setup.

testcases/kernel/syscalls/keyctl/keyctl23.c line 118

Quoted 7 lines
testcases/kernel/syscalls/keyctl/keyctl23.c new file +7 -0
+	TEST(keyctl(KEYCTL_RESTRICT_KEYRING, ring_builtin,
+		    (unsigned long)"asymmetric",
+		    (unsigned long)"builtin_trusted", 0));
+	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) {
+		tst_res(TCONF, "builtin_trusted restriction not supported");
+		return;
+	}

Again, can be tst_brk(TCONF, "") there is no reason to continue at this point.

testcases/kernel/syscalls/keyctl/keyctl23.c line 128

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl23.c new file +10 -0
+	if (TST_RET == 0)
+		tst_res(TPASS, "KEYCTL_RESTRICT_KEYRING builtin_trusted passed");
+	else if (TST_RET == -1 && TST_ERR == EEXIST)
+		tst_res(TPASS, "KEYCTL_RESTRICT_KEYRING builtin_trusted already active");
+	else
+		tst_res(TFAIL | TTERRNO, "KEYCTL_RESTRICT_KEYRING builtin_trusted failed");
+
+	TST_EXP_FAIL(keyctl(KEYCTL_LINK, user_key, ring_builtin, 0, 0),
+		     EOPNOTSUPP,
+		     "KEYCTL_LINK of non-asymmetric key on builtin_trusted restricted keyring");

Hmm, we have this pattern in the tests more than once. The second iteration is a test on it's own.

One easy solution to this is to run the test with two iterations in the default run. I have a patch that adds the -i default value to the tst_test structure I proposed for the runtest generator, if we wire that in we can just set .iterations = 2 in the tst_test struct and be done with it:

Subject: [PATCH 08/13] lib: tst_test: Move the iterations to struct tst_test

This allows us to set the default number of iterations in the tst_test structure.

---
 include/tst_test.h | 4 ++++
 lib/tst_test.c     | 8 +++++---
 2 files changed, 9 insertions(+), 3 deletions(-)
include/tst_test.h +4 -0
index 4afe4cbe0..6befb7787 100644
@@ -478,6 +478,9 @@ struct tst_fs {
  *           probabilistic or fuzzy synchronization tests).
  *           If not set, a default minimum of 1 second is enforced.
  *
+ * @iterations: The default value for the number of test iterations, i.e. the
+ *               -i command line parameter.
+ *
  * @setup: Setup callback is called once at the start of the test in order to
  *         prepare the test environment.
  *
@@ -608,6 +611,7 @@ struct tst_fs {
        int timeout;
        int runtime;
        int min_runtime;
+       unsigned int iterations;
 
        void (*setup)(void);
        void (*cleanup)(void);
lib/tst_test.c +5 -3
index 5c3607016..e1166c0c6 100644
@@ -64,7 +64,6 @@ const char *TCID __attribute__((weak));
 struct tst_test *tst_test;
 
 static const char *tcid;
-static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
 static int reproducible_output;
@@ -834,7 +833,7 @@ static void parse_opts(int argc, char *argv[])
                        print_test_tags();
                        exit(0);
                case 'i':
-                       iterations = SAFE_STRTOL(optarg, 0, INT_MAX);
+                       tst_test->iterations = SAFE_STRTOL(optarg, 0, UINT_MAX);
                break;
                case 'I':
                        if (tst_test->runtime > 0)
@@ -1484,6 +1483,9 @@ static void do_setup(int argc, char *argv[])
                }
        }
 
+       if (tst_test->iterations == 0)
+               tst_test->iterations = 1;
+
        if (tst_test->mount_device)
                tst_test->format_device = 1;
 
@@ -1770,7 +1772,7 @@ static void testrun(void)
        for (;;) {
                cont = 0;
 
-               if (i < (unsigned int)iterations) {
+               if (i < tst_test->iterations) {
                        i++;
                        cont = 1;
                }
Quoted 18 lines
testcases/kernel/syscalls/keyctl/keyctl23.c new file +11 -0
+	TST_EXP_FAIL2(add_key("asymmetric", "cert", untrusted_cert,
+			      sizeof(untrusted_cert), ring_builtin), ENOKEY,
+		      "add_key of untrusted cert on builtin_trusted restricted keyring");
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.min_kver = "4.12",
+	.needs_root = 1,
+};
Signature · 6 lines
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#37 lore raw

Re: [LTP] [PATCH v2 15/33] keyctl23: Test KEYCTL_RESTRICT_KEYRING builtin_trusted

Hi Cyril,

...

Quoted 14 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+	if (TST_RET == 0)
+		tst_res(TPASS, "KEYCTL_RESTRICT_KEYRING builtin_trusted passed");
+	else if (TST_RET == -1 && TST_ERR == EEXIST)
+		tst_res(TPASS, "KEYCTL_RESTRICT_KEYRING builtin_trusted already active");
+	else
+		tst_res(TFAIL | TTERRNO, "KEYCTL_RESTRICT_KEYRING builtin_trusted failed");
+
+	TST_EXP_FAIL(keyctl(KEYCTL_LINK, user_key, ring_builtin, 0, 0),
+		     EOPNOTSUPP,
+		     "KEYCTL_LINK of non-asymmetric key on builtin_trusted restricted keyring");

Hmm, we have this pattern in the tests more than once. The second iteration is a test on it's own.

Quoted 7 lines

One easy solution to this is to run the test with two iterations in the default run. I have a patch that adds the -i default value to the tst_test structure I proposed for the runtest generator, if we wire that in we can just set .iterations = 2 in the tst_test struct and be done with it:

Subject: [PATCH 08/13] lib: tst_test: Move the iterations to struct tst_test

...

+1, I'll add it to the v3 patchset.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#38 lore raw

PATCH v2 16/33 keyctl24: Negative tests for KEYCTL_RESTRICT_KEYRING

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test error conditions of KEYCTL_RESTRICT_KEYRING using a parameterized tcase table: invalid type/restriction combinations (EINVAL), non-keyrings (ENOTDIR), unknown key type (ENOKEY), key type without lookup (ENOENT), invalid restriction string (EINVAL), bogus key serial (ENOKEY), already restricted (EEXIST), self-chain cycle (EDEADLK), and missing Setattr (EACCES).

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl24.c | 173 ++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+)
runtest/syscalls +1 -0
index f7c4830a9..be35e9f93 100644
@@ -741,6 +741,7 @@ keyctl20 keyctl20
 keyctl21 keyctl21
 keyctl22 keyctl22
 keyctl23 keyctl23
+keyctl24 keyctl24
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 803e4e94c..767ccf61a 100644
@@ -21,3 +21,4 @@
 /keyctl21
 /keyctl22
 /keyctl23
+/keyctl24
testcases/kernel/syscalls/keyctl/keyctl24.c new file +173 -0

173 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#39 lore raw

Re: [LTP] [PATCH v2 16/33] keyctl24: Negative tests for KEYCTL_RESTRICT_KEYRING

Quoted 113 lines
testcases/kernel/syscalls/keyctl/keyctl24.c new file +113 -0
+/*
+ * A tcase with .id = NULL asks verify_negative() to allocate a fresh
+ * unrestricted keyring for the case and unlink it afterwards, so that a
+ * false-positive result cannot restrict a ring shared with later cases.
+ * .self_cycle asks for a "key_or_keyring:<fresh>:chain" restriction string
+ * pointing back at that fresh ring, needed for the EDEADLK check.
+ */
+static struct tcase {
+	key_serial_t *id;
+	int self_cycle;
+	const char *type;
+	const char *restriction;
+	int exp_errno;
+	int needs_asym;
+	const char *desc;
+} tcases[] = {
+	{
+		.restriction = "builtin_trusted",
+		.exp_errno = EINVAL,
+		.desc = "NULL type and non-NULL restriction",
+	},
+	{
+		.type = "asymmetric",
+		.exp_errno = EINVAL,
+		.desc = "non-NULL type and NULL restriction",
+	},
+	{
+		.id = &user_key,
+		.exp_errno = ENOTDIR,
+		.desc = "non-keyring key",
+	},
+	{
+		.type = "nosuchtype",
+		.restriction = "builtin_trusted",
+		.exp_errno = ENOKEY,
+		.desc = "unknown key type",
+	},
+	{
+		.type = "user",
+		.restriction = "builtin_trusted",
+		.exp_errno = ENOENT,
+		.desc = "key type having no lookup_restriction",
+	},
+	{
+		.type = "asymmetric",
+		.restriction = "bogus",
+		.exp_errno = EINVAL,
+		.needs_asym = 1,
+		.desc = "asymmetric with invalid restriction string",
+	},
+	{
+		.type = "asymmetric",
+		.restriction = "key_or_keyring:2147483647",
+		.exp_errno = ENOKEY,
+		.needs_asym = 1,
+		.desc = "asymmetric with bogus key serial",
+	},
+	{
+		.id = &ring_reject,
+		.exp_errno = EEXIST,
+		.desc = "already restricted keyring",
+	},
+	{
+		.self_cycle = 1,
+		.type = "asymmetric",
+		.exp_errno = EDEADLK,
+		.needs_asym = 1,
+		.desc = "self-referencing key_or_keyring chain",
+	},
+	{
+		.id = &ring_no_setattr,
+		.exp_errno = EACCES,
+		.desc = "keyring without Setattr permission",
+	},
+};
+
+static void setup(void)
+{
+	key_serial_t probe_ring;
+
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	ring_reject = new_ring("ltpkeyctl24_reject");
+	ring_no_setattr = new_ring("ltpkeyctl24_no_setattr");
+	SAFE_KEYCTL(KEYCTL_SETPERM, ring_no_setattr, KEY_PERM_NO_SETATTR, 0, 0);
+
+	/* Permanently restrict ring_reject with reject-all for EEXIST test */
+	SAFE_KEYCTL(KEYCTL_RESTRICT_KEYRING, ring_reject, 0, 0, 0);
+
+	user_key = new_user_key("k", "payload", 7, KEY_SPEC_PROCESS_KEYRING);
+
+	/* Probe asymmetric support on a throwaway ring so we cannot poison
+	 * any ring reused later by the tcase table.
+	 */
+	probe_ring = new_ring("ltpkeyctl24_probe");
+	TEST(keyctl(KEYCTL_RESTRICT_KEYRING, probe_ring,
+		    (unsigned long)"asymmetric", (unsigned long)"bogus", 0));
+	asym_supported = (TST_RET != -1 || TST_ERR != ENODEV);
+	keyctl(KEYCTL_UNLINK, probe_ring, KEY_SPEC_PROCESS_KEYRING, 0, 0);
+}
+
+static void verify_negative(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	key_serial_t id, fresh_ring = 0;
+	const char *restriction = tc->restriction;
+	char cycle_buf[64];
+
+	if (tc->needs_asym && !asym_supported) {
+		tst_res(TCONF, "asymmetric key type not supported");
+		return;
+	}
+

testcases/kernel/syscalls/keyctl/keyctl24.c line 154

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl24.c new file +10 -0
+	if (tc->id) {
+		id = *tc->id;
+	} else {
+		fresh_ring = new_ring("ltpkeyctl24_fresh");
+		id = fresh_ring;
+		if (tc->self_cycle) {
+			snprintf(cycle_buf, sizeof(cycle_buf),
+				 "key_or_keyring:%d:chain", fresh_ring);
+			restriction = cycle_buf;
+		}

Maybe it would have been better if we moved the self cycle test to a seprate testcase, instead of adding special cases to this test...

Quoted 26 lines
testcases/kernel/syscalls/keyctl/keyctl24.c new file +19 -0
+	}
+
+	TST_EXP_FAIL(keyctl(KEYCTL_RESTRICT_KEYRING, (unsigned long)id,
+			    (unsigned long)tc->type,
+			    (unsigned long)restriction, 0),
+		     tc->exp_errno,
+		     "KEYCTL_RESTRICT_KEYRING with %s", tc->desc);
+
+	if (fresh_ring)
+		keyctl(KEYCTL_UNLINK, fresh_ring, KEY_SPEC_PROCESS_KEYRING,
+		       0, 0);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_negative,
+	.tcnt = ARRAY_SIZE(tcases),
+	.min_kver = "4.12",
+};
Signature · 6 lines
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#40 lore raw

PATCH v2 17/33 keyctl25: Test KEYCTL_DH_COMPUTE shared secret computation

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_DH_COMPUTE shared secret computation: verify that computing a 256-byte DH shared secret with RFC 7919 FFDHE-2048 parameters matches the precomputed mathematical value.

---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore       |  1 +
 testcases/kernel/syscalls/keyctl/keyctl25.c       | 66 ++++++++++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl_dh_data.h | 74 +++++++++++++++++++++++
 4 files changed, 142 insertions(+)
runtest/syscalls +1 -0
index be35e9f93..1b059f652 100644
@@ -742,6 +742,7 @@ keyctl21 keyctl21
 keyctl22 keyctl22
 keyctl23 keyctl23
 keyctl24 keyctl24
+keyctl25 keyctl25
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 767ccf61a..4cf772558 100644
@@ -22,3 +22,4 @@
 /keyctl22
 /keyctl23
 /keyctl24
+/keyctl25
testcases/kernel/syscalls/keyctl/keyctl25.c new file +66 -0

66 lines not on this page · raw message

testcases/kernel/syscalls/keyctl/keyctl_dh_data.h new file +74 -0

74 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#41 lore raw

Re: [LTP] [PATCH v2 17/33] keyctl25: Test KEYCTL_DH_COMPUTE shared secret computation

Hi!

testcases/kernel/syscalls/keyctl/keyctl25.c line 26

Quoted 6 lines
testcases/kernel/syscalls/keyctl/keyctl25.c new file +6 -0
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	dh_params->priv = new_user_key("dh_priv", dh_priv, sizeof(dh_priv),
+				       KEY_SPEC_PROCESS_KEYRING);

Here as well, should have been SAVE_USER_KEY() otherwise it looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#42 lore raw

PATCH v2 18/33 keyctl26: Test KEYCTL_DH_COMPUTE size query

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_DH_COMPUTE buffer size query: verify that calling with buflen 0 returns the required output buffer size (256) without writing to userspace.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl26.c | 53 +++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
runtest/syscalls +1 -0
index 1b059f652..108efa4a8 100644
@@ -743,6 +743,7 @@ keyctl22 keyctl22
 keyctl23 keyctl23
 keyctl24 keyctl24
 keyctl25 keyctl25
+keyctl26 keyctl26
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 4cf772558..dd282b7ce 100644
@@ -23,3 +23,4 @@
 /keyctl23
 /keyctl24
 /keyctl25
+/keyctl26
testcases/kernel/syscalls/keyctl/keyctl26.c new file +53 -0

53 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#43 lore raw

Re: [LTP] [PATCH v2 18/33] keyctl26: Test KEYCTL_DH_COMPUTE size query

Hi!

testcases/kernel/syscalls/keyctl/keyctl26.c line 28

Quoted 5 lines
testcases/kernel/syscalls/keyctl/keyctl26.c new file +5 -0
+	dh_params->priv = new_user_key("dh_priv", dh_priv, sizeof(dh_priv),
+				       KEY_SPEC_PROCESS_KEYRING);
+	dh_params->prime = new_user_key("dh_prime", dh_prime, sizeof(dh_prime),
+					KEY_SPEC_PROCESS_KEYRING);
+	dh_params->base = new_user_key("dh_base", dh_base, sizeof(dh_base),

And same here.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#44 lore raw

Re: [LTP] [PATCH v2 18/33] keyctl26: Test KEYCTL_DH_COMPUTE size query

In reply to Andrea Cervesato

Hi Andrea,

Quoted 3 lines

Test KEYCTL_DH_COMPUTE buffer size query: verify that calling with buflen 0 returns the required output buffer size (256) without writing to userspace.

...

testcases/kernel/syscalls/keyctl/keyctl26.c line 25

Quoted 6 lines
testcases/kernel/syscalls/keyctl/keyctl26.c new file +6 -0
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	dh_params->priv = new_user_key("dh_priv", dh_priv, sizeof(dh_priv),
+				       KEY_SPEC_PROCESS_KEYRING);

Unfortunately Leap 42.2 (which we still support) does not have struct keyctl_dh_params priv support - added in v4.20-rc1 in
2ecefa0a15fd0 ("keys: Fix the use of the C++ keyword "private" in uapi/linux/keyctl.h")

keyctl26.c:24:11: error: dereferencing pointer to incomplete type
dh_params->priv = new_user_key("dh_priv", dh_priv, sizeof(dh_priv),

           ^
keyctl26.c:26:11: error: dereferencing pointer to incomplete type
  dh_params->prime = new_user_key("dh_prime", dh_prime, sizeof(dh_prime),
           ^
keyctl26.c:28:11: error: dereferencing pointer to incomplete type
  dh_params->base = new_user_key("dh_base", dh_base, sizeof(dh_base),
           ^
keyctl26.c: At top level:
keyctl26.c:50:31: error: dereferencing pointer to incomplete type
   {&dh_params, .size = sizeof(*dh_params)},
                               ^

We need AC_CHECK_MEMBERS check.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#45 lore raw

PATCH v2 19/33 keyctl27: Test KEYCTL_DH_COMPUTE KDF key derivation

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_DH_COMPUTE SP800-56A KDF key derivation: verify that deriving a key using SHA-256 and otherinfo matches the precomputed mathematical test vector.

---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore       |  1 +
 testcases/kernel/syscalls/keyctl/keyctl27.c       | 78 +++++++++++++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl_dh_data.h |  5 ++
 4 files changed, 85 insertions(+)
runtest/syscalls +1 -0
index 108efa4a8..d23461c4b 100644
@@ -744,6 +744,7 @@ keyctl23 keyctl23
 keyctl24 keyctl24
 keyctl25 keyctl25
 keyctl26 keyctl26
+keyctl27 keyctl27
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index dd282b7ce..720ba1de6 100644
@@ -24,3 +24,4 @@
 /keyctl24
 /keyctl25
 /keyctl26
+/keyctl27
testcases/kernel/syscalls/keyctl/keyctl27.c new file +78 -0

78 lines not on this page · raw message

testcases/kernel/syscalls/keyctl/keyctl_dh_data.h +5 -0
index bc1432dc3..7ac7876a0 100644
@@ -71,4 +71,9 @@ static const unsigned char dh_expected_secret[] = {
 	0xfb, 0xeb, 0xdd, 0x18, 0x54, 0x0d, 0x4c, 0xa7, 0x65, 0xc1, 0x0c, 0x11, 0xad, 0xea, 0x83, 0x9f,
 };
 
+static const unsigned char dh_kdf_expected[] = {
+	0x66, 0x39, 0xec, 0x41, 0x31, 0x33, 0xe6, 0xc0, 0x61, 0x67, 0x28, 0x51, 0x61, 0xf7, 0x8c, 0xd7,
+	0xc0, 0x55, 0xc9, 0xcc, 0x83, 0x46, 0xf3, 0xaa, 0x62, 0xed, 0xca, 0x90, 0x99, 0x2d, 0xc4, 0x07,
+};
+
 #endif /* KEYCTL_DH_DATA_H__ */
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#46 lore raw

Re: [LTP] [PATCH v2 19/33] keyctl27: Test KEYCTL_DH_COMPUTE KDF key derivation

Hi!

testcases/kernel/syscalls/keyctl/keyctl27.c line 34

Quoted 5 lines
testcases/kernel/syscalls/keyctl/keyctl27.c new file +5 -0
+	dh_params->priv = new_user_key("dh_priv", dh_priv, sizeof(dh_priv),
+				       KEY_SPEC_PROCESS_KEYRING);
+	dh_params->prime = new_user_key("dh_prime", dh_prime, sizeof(dh_prime),
+					KEY_SPEC_PROCESS_KEYRING);
+	dh_params->base = new_user_key("dh_base", dh_base, sizeof(dh_base),

Here as well.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#47 lore raw

PATCH v2 20/33 keyctl28: Negative and boundary tests for KEYCTL_DH_COMPUTE

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test error and boundary conditions of KEYCTL_DH_COMPUTE using a parameterized tcase table: buffer smaller than secret (EOVERFLOW), bogus prime key (ENOKEY), non-user key (EOPNOTSUPP), NULL buffer (EINVAL), non-zero __spare (EINVAL), buflen > 1024 (EMSGSIZE), otherinfolen > 64 (EMSGSIZE), and unknown KDF hash name (ENOENT).

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl28.c | 140 ++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+)
runtest/syscalls +1 -0
index d23461c4b..6fdbbea17 100644
@@ -745,6 +745,7 @@ keyctl24 keyctl24
 keyctl25 keyctl25
 keyctl26 keyctl26
 keyctl27 keyctl27
+keyctl28 keyctl28
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 720ba1de6..139e480b3 100644
@@ -25,3 +25,4 @@
 /keyctl25
 /keyctl26
 /keyctl27
+/keyctl28
testcases/kernel/syscalls/keyctl/keyctl28.c new file +140 -0

140 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#48 lore raw

Re: [LTP] [PATCH v2 20/33] keyctl28: Negative and boundary tests for KEYCTL_DH_COMPUTE

Hi!
Looks good apart from the new_user_key().

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#49 lore raw

PATCH v2 21/33 lapi/keyctl.h: Add fallback definitions for public key ops

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Add fallback definitions for KEYCTL_PKEY_QUERY, KEYCTL_PKEY_ENCRYPT, KEYCTL_PKEY_DECRYPT, KEYCTL_PKEY_SIGN, KEYCTL_PKEY_VERIFY, and KEYCTL_SUPPORTS_*, as well as fallback structs keyctl_pkey_query and keyctl_pkey_params when built without keyutils.h or linux/keyctl.h.

---
 include/lapi/keyctl.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
include/lapi/keyctl.h +56 -0
index 1c6627f55..2574c3168 100644
@@ -78,6 +78,30 @@ struct keyctl_kdf_params {
 };
 #endif
 
+#ifndef HAVE_STRUCT_KEYCTL_PKEY_QUERY
+struct keyctl_pkey_query {
+	uint32_t	supported_ops;
+	uint32_t	key_size;
+	uint16_t	max_data_size;
+	uint16_t	max_sig_size;
+	uint16_t	max_enc_size;
+	uint16_t	max_dec_size;
+	uint32_t	__spare[10];
+};
+#endif
+
+#ifndef HAVE_STRUCT_KEYCTL_PKEY_PARAMS
+struct keyctl_pkey_params {
+	int32_t		key_id;
+	uint32_t	in_len;
+	union {
+		uint32_t	out_len;
+		uint32_t	in2_len;
+	};
+	uint32_t	__spare[7];
+};
+#endif
+
 /* special process keyring shortcut IDs */
 #ifndef KEY_SPEC_THREAD_KEYRING
 # define KEY_SPEC_THREAD_KEYRING -1
@@ -202,6 +226,33 @@ struct keyctl_kdf_params {
 # define KEYCTL_MOVE_EXCL 0x00000001 /* do not displace from the to-keyring */
 #endif
 
+#ifndef KEYCTL_PKEY_QUERY
+# define KEYCTL_PKEY_QUERY 24
+#endif
+
+#ifndef KEYCTL_PKEY_ENCRYPT
+# define KEYCTL_PKEY_ENCRYPT 25
+#endif
+
+#ifndef KEYCTL_PKEY_DECRYPT
+# define KEYCTL_PKEY_DECRYPT 26
+#endif
+
+#ifndef KEYCTL_PKEY_SIGN
+# define KEYCTL_PKEY_SIGN 27
+#endif
+
+#ifndef KEYCTL_PKEY_VERIFY
+# define KEYCTL_PKEY_VERIFY 28
+#endif
+
+#ifndef KEYCTL_SUPPORTS_ENCRYPT
+# define KEYCTL_SUPPORTS_ENCRYPT 0x01
+# define KEYCTL_SUPPORTS_DECRYPT 0x02
+# define KEYCTL_SUPPORTS_SIGN    0x04
+# define KEYCTL_SUPPORTS_VERIFY  0x08
+#endif
+
 /* key permissions */
 #ifndef KEY_POS_VIEW
 # define KEY_POS_VIEW    0x01000000
@@ -262,6 +313,11 @@ static inline long safe_keyctl(const char *file, const int lineno,
 	case KEYCTL_GET_SECURITY:
 	case KEYCTL_GET_PERSISTENT:
 	case KEYCTL_DH_COMPUTE:
+	case KEYCTL_PKEY_QUERY:
+	case KEYCTL_PKEY_ENCRYPT:
+	case KEYCTL_PKEY_DECRYPT:
+	case KEYCTL_PKEY_SIGN:
+	case KEYCTL_PKEY_VERIFY:
 		if (rval < 0)
 			failure = 1;
 		break;
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#50 lore raw

PATCH v2 22/33 keyctl29: Test KEYCTL_PKEY_QUERY on public key

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_PKEY_QUERY operation on an RSA-2048 X.509 public key
certificate: verify key_size is 2048, supported_ops contains ENCRYPT and VERIFY, and max_enc_size/max_sig_size are 256.

---
 runtest/syscalls                                   |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore        |  1 +
 testcases/kernel/syscalls/keyctl/keyctl29.c        | 90 ++++++++++++++++++++++
 testcases/kernel/syscalls/keyctl/keyctl_common.h   | 20 +++++
 .../kernel/syscalls/keyctl/keyctl_pkey_data.h      | 68 ++++++++++++++++
 5 files changed, 180 insertions(+)
runtest/syscalls +1 -0
index 6fdbbea17..432369e63 100644
@@ -746,6 +746,7 @@ keyctl25 keyctl25
 keyctl26 keyctl26
 keyctl27 keyctl27
 keyctl28 keyctl28
+keyctl29 keyctl29
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 139e480b3..91310b001 100644
@@ -26,3 +26,4 @@
 /keyctl26
 /keyctl27
 /keyctl28
+/keyctl29
testcases/kernel/syscalls/keyctl/keyctl29.c new file +90 -0

90 lines not on this page · raw message

testcases/kernel/syscalls/keyctl/keyctl_common.h +20 -0
index c7290cc6e..723fe228b 100644
@@ -50,4 +50,24 @@ static inline key_serial_t search_ring(key_serial_t ring, const char *type,
 		      (unsigned long)desc, 0);
 }
 
+static inline key_serial_t add_asymmetric_key_or_tconf(const char *desc,
+						       const void *payload,
+						       size_t plen,
+						       const char *parser_kconfig)
+{
+	TEST(add_key("asymmetric", desc, payload, plen, KEY_SPEC_PROCESS_KEYRING));
+	if (TST_RET >= 0)
+		return TST_RET;
+
+	if (TST_ERR == ENODEV)
+		tst_brk(TCONF, "kernel does not support asymmetric keys");
+	if (TST_ERR == EBADMSG)
+		tst_brk(TCONF, "missing asymmetric parser (%s)", parser_kconfig);
+	if (TST_ERR == ENOENT)
+		tst_brk(TCONF, "missing crypto RSA / SHA256 algorithms");
+
+	tst_brk(TBROK | TTERRNO, "failed to add asymmetric key '%s'", desc);
+	return -1;
+}
+
 #endif /* KEYCTL_COMMON_H__ */
testcases/kernel/syscalls/keyctl/keyctl_pkey_data.h new file +68 -0

68 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#51 lore raw

Re: [LTP] [PATCH v2 22/33] keyctl29: Test KEYCTL_PKEY_QUERY on public key

Hi!

Quoted 17 lines
testcases/kernel/syscalls/keyctl/keyctl_common.h +9 -0
index c7290cc6e..723fe228b 100644
@@ -50,4 +50,24 @@ static inline key_serial_t search_ring(key_serial_t ring, const char *type,
 		      (unsigned long)desc, 0);
 }
 
+static inline key_serial_t add_asymmetric_key_or_tconf(const char *desc,
+						       const void *payload,
+						       size_t plen,
+						       const char *parser_kconfig)
+{
+	TEST(add_key("asymmetric", desc, payload, plen, KEY_SPEC_PROCESS_KEYRING));
+	if (TST_RET >= 0)
+		return TST_RET;
+

testcases/kernel/syscalls/keyctl/keyctl_common.h static inline key_serial_t search_ring(key_serial_t ring, const char *type, · line 71

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl_common.h +10 -0
+	if (TST_ERR == ENODEV)
+		tst_brk(TCONF, "kernel does not support asymmetric keys");
+	if (TST_ERR == EBADMSG)
+		tst_brk(TCONF, "missing asymmetric parser (%s)", parser_kconfig);
+	if (TST_ERR == ENOENT)
+		tst_brk(TCONF, "missing crypto RSA / SHA256 algorithms");
+
+	tst_brk(TBROK | TTERRNO, "failed to add asymmetric key '%s'", desc);
+	return -1;
+}

Shall we turn this into a SAFE_MACRO() as well? Safe macros exitting the test with TCONF are estabilished pattern as well.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#52 lore raw

PATCH v2 23/33 keyctl30: Test KEYCTL_PKEY_QUERY on private key

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_PKEY_QUERY operation on an RSA-2048 PKCS#8 private key:
verify key_size is 2048, supported_ops contains DECRYPT and SIGN, and max_dec_size/max_sig_size are 256.

---
 runtest/syscalls                                   |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore        |  1 +
 testcases/kernel/syscalls/keyctl/keyctl30.c        | 86 ++++++++++++++++++++++
 .../kernel/syscalls/keyctl/keyctl_pkey_data.h      | 84 +++++++++++++++++++++
 4 files changed, 172 insertions(+)
runtest/syscalls +1 -0
index 432369e63..15f8c892c 100644
@@ -747,6 +747,7 @@ keyctl26 keyctl26
 keyctl27 keyctl27
 keyctl28 keyctl28
 keyctl29 keyctl29
+keyctl30 keyctl30
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 91310b001..d5b6955f3 100644
@@ -27,3 +27,4 @@
 /keyctl27
 /keyctl28
 /keyctl29
+/keyctl30
testcases/kernel/syscalls/keyctl/keyctl30.c new file +86 -0

86 lines not on this page · raw message

testcases/kernel/syscalls/keyctl/keyctl_pkey_data.h +84 -0

88 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#53 lore raw

Re: [LTP] [PATCH v2 23/33] keyctl30: Test KEYCTL_PKEY_QUERY on private key

Hi!

testcases/kernel/syscalls/keyctl/keyctl30.c line 36

Quoted 9 lines
testcases/kernel/syscalls/keyctl/keyctl30.c new file +9 -0
+static void setup(void)
+{
+	SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
+
+	tst_modprobe("pkcs8_key_parser", NULL);
+
+	priv_key = add_asymmetric_key_or_tconf("priv", rsa2048_pkcs8,
+					       sizeof(rsa2048_pkcs8),
+					       "CONFIG_PKCS8_PRIVATE_KEY_PARSER");

Aparat from this that should have been SAFE_ADD_KEY() the test looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#54 lore raw

PATCH v2 24/33 keyctl31: Test KEYCTL_PKEY_ENCRYPT and KEYCTL_PKEY_DECRYPT

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test public key encryption and private key decryption with KEYCTL_PKEY_ENCRYPT and KEYCTL_PKEY_DECRYPT: encrypt a 32-byte plaintext using an RSA-2048 X.509 public key with enc=pkcs1, decrypt with the matching PKCS#8 private key, and verify the decrypted output matches the original plaintext.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl31.c | 110 ++++++++++++++++++++++++++++
 3 files changed, 112 insertions(+)
runtest/syscalls +1 -0
index 15f8c892c..e43dd02ab 100644
@@ -748,6 +748,7 @@ keyctl27 keyctl27
 keyctl28 keyctl28
 keyctl29 keyctl29
 keyctl30 keyctl30
+keyctl31 keyctl31
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index d5b6955f3..025dc27fc 100644
@@ -28,3 +28,4 @@
 /keyctl28
 /keyctl29
 /keyctl30
+/keyctl31
testcases/kernel/syscalls/keyctl/keyctl31.c new file +110 -0

110 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#55 lore raw

PATCH v2 25/33 keyctl32: Test KEYCTL_PKEY_SIGN and VERIFY

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test public key signature creation and verification with KEYCTL_PKEY_SIGN and KEYCTL_PKEY_VERIFY: sign a 32-byte digest using an RSA-2048 PKCS#8 private key with enc=pkcs1, verify the 256-byte signature with the matching X.509 public key, and verify that a mismatched digest fails with EKEYREJECTED.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl32.c | 121 ++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+)
runtest/syscalls +1 -0
index e43dd02ab..d4007f7a6 100644
@@ -749,6 +749,7 @@ keyctl28 keyctl28
 keyctl29 keyctl29
 keyctl30 keyctl30
 keyctl31 keyctl31
+keyctl32 keyctl32
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 025dc27fc..8b1627bee 100644
@@ -29,3 +29,4 @@
 /keyctl29
 /keyctl30
 /keyctl31
+/keyctl32
testcases/kernel/syscalls/keyctl/keyctl32.c new file +121 -0

121 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#56 lore raw

PATCH v2 26/33 keyctl33: Negative tests for KEYCTL_PKEY_*

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Add negative and boundary test cases for KEYCTL_PKEY_* operations (QUERY, ENCRYPT, DECRYPT, SIGN, VERIFY), testing invalid key serials, unsupported key types, invalid info strings, and buffer size limits.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl33.c | 247 ++++++++++++++++++++++++++++
 3 files changed, 249 insertions(+)
runtest/syscalls +1 -0
index d4007f7a6..7658ac859 100644
@@ -750,6 +750,7 @@ keyctl29 keyctl29
 keyctl30 keyctl30
 keyctl31 keyctl31
 keyctl32 keyctl32
+keyctl33 keyctl33
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 8b1627bee..0f209d7e0 100644
@@ -30,3 +30,4 @@
 /keyctl30
 /keyctl31
 /keyctl32
+/keyctl33
testcases/kernel/syscalls/keyctl/keyctl33.c new file +247 -0

247 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#57 lore raw

PATCH v2 27/33 lapi/keyctl.h: Add capability fallback defines

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Add fallback definitions for KEYCTL_CAPABILITIES, KEYCTL_CAPS0_*, and KEYCTL_CAPS1_* constants, and update safe_keyctl to handle KEYCTL_CAPABILITIES.

---
 include/lapi/keyctl.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
include/lapi/keyctl.h +49 -0
index 2574c3168..6feca63be 100644
@@ -226,6 +226,10 @@ struct keyctl_pkey_params {
 # define KEYCTL_MOVE_EXCL 0x00000001 /* do not displace from the to-keyring */
 #endif
 
+#ifndef KEYCTL_CAPABILITIES
+# define KEYCTL_CAPABILITIES 31
+#endif
+
 #ifndef KEYCTL_PKEY_QUERY
 # define KEYCTL_PKEY_QUERY 24
 #endif
@@ -253,6 +257,50 @@ struct keyctl_pkey_params {
 # define KEYCTL_SUPPORTS_VERIFY  0x08
 #endif
 
+#ifndef KEYCTL_CAPS0_CAPABILITIES
+# define KEYCTL_CAPS0_CAPABILITIES		0x01
+#endif
+
+#ifndef KEYCTL_CAPS0_PERSISTENT_KEYRINGS
+# define KEYCTL_CAPS0_PERSISTENT_KEYRINGS	0x02
+#endif
+
+#ifndef KEYCTL_CAPS0_DIFFIE_HELLMAN
+# define KEYCTL_CAPS0_DIFFIE_HELLMAN		0x04
+#endif
+
+#ifndef KEYCTL_CAPS0_PUBLIC_KEY
+# define KEYCTL_CAPS0_PUBLIC_KEY		0x08
+#endif
+
+#ifndef KEYCTL_CAPS0_BIG_KEY
+# define KEYCTL_CAPS0_BIG_KEY			0x10
+#endif
+
+#ifndef KEYCTL_CAPS0_INVALIDATE
+# define KEYCTL_CAPS0_INVALIDATE		0x20
+#endif
+
+#ifndef KEYCTL_CAPS0_RESTRICT_KEYRING
+# define KEYCTL_CAPS0_RESTRICT_KEYRING		0x40
+#endif
+
+#ifndef KEYCTL_CAPS0_MOVE
+# define KEYCTL_CAPS0_MOVE			0x80
+#endif
+
+#ifndef KEYCTL_CAPS1_NS_KEYRING_NAME
+# define KEYCTL_CAPS1_NS_KEYRING_NAME		0x01
+#endif
+
+#ifndef KEYCTL_CAPS1_NS_KEY_TAG
+# define KEYCTL_CAPS1_NS_KEY_TAG		0x02
+#endif
+
+#ifndef KEYCTL_CAPS1_NOTIFICATIONS
+# define KEYCTL_CAPS1_NOTIFICATIONS		0x04
+#endif
+
 /* key permissions */
 #ifndef KEY_POS_VIEW
 # define KEY_POS_VIEW    0x01000000
@@ -318,6 +366,7 @@ static inline long safe_keyctl(const char *file, const int lineno,
 	case KEYCTL_PKEY_DECRYPT:
 	case KEYCTL_PKEY_SIGN:
 	case KEYCTL_PKEY_VERIFY:
+	case KEYCTL_CAPABILITIES:
 		if (rval < 0)
 			failure = 1;
 		break;
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#58 lore raw

PATCH v2 28/33 keyctl34: Test KEYCTL_CAPABILITIES flag retrieval

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test keyrings subsystem capabilities retrieval with KEYCTL_CAPABILITIES and verify standard capability bits (CAPABILITIES, INVALIDATE, RESTRICT_KEYRING, MOVE, NS_KEYRING_NAME, NS_KEY_TAG).

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl34.c | 62 +++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)
runtest/syscalls +1 -0
index 7658ac859..08877ff49 100644
@@ -751,6 +751,7 @@ keyctl30 keyctl30
 keyctl31 keyctl31
 keyctl32 keyctl32
 keyctl33 keyctl33
+keyctl34 keyctl34
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 0f209d7e0..f2ce330d7 100644
@@ -31,3 +31,4 @@
 /keyctl31
 /keyctl32
 /keyctl33
+/keyctl34
testcases/kernel/syscalls/keyctl/keyctl34.c new file +62 -0

62 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#59 lore raw

Re: [LTP] [PATCH v2 28/33] keyctl34: Test KEYCTL_CAPABILITIES flag retrieval

Hi Andrea,

Quoted 3 lines

Test keyrings subsystem capabilities retrieval with KEYCTL_CAPABILITIES and verify standard capability bits (CAPABILITIES, INVALIDATE, RESTRICT_KEYRING, MOVE, NS_KEYRING_NAME, NS_KEY_TAG).

...

Quoted 1 line

+++ b/testcases/kernel/syscalls/keyctl/keyctl34.c

...

Quoted 15 lines
testcases/kernel/syscalls/keyctl/keyctl34.c new file +15 -0
+static void run(void)
+{
+	memset(caps, 0, sizeof(caps));
+
+	TEST(keyctl(KEYCTL_CAPABILITIES, (unsigned long)caps, sizeof(caps), 0, 0));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "KEYCTL_CAPABILITIES failed");
+
+	if (TST_RET < 2) {
+		tst_res(TFAIL, "KEYCTL_CAPABILITIES returned %ld, expected at least 2",
+			TST_RET);
+		return;
+	}
+
+	TST_EXP_EXPR(caps[0] & KEYCTL_CAPS0_CAPABILITIES,

testcases/kernel/syscalls/keyctl/keyctl34.c line 50

Quoted 10 lines
testcases/kernel/syscalls/keyctl/keyctl34.c new file +10 -0
+		     "KEYCTL_CAPS0_CAPABILITIES is set");
+	TST_EXP_EXPR(caps[0] & KEYCTL_CAPS0_INVALIDATE,
+		     "KEYCTL_CAPS0_INVALIDATE is set");
+	TST_EXP_EXPR(caps[0] & KEYCTL_CAPS0_RESTRICT_KEYRING,
+		     "KEYCTL_CAPS0_RESTRICT_KEYRING is set");
+	TST_EXP_EXPR(caps[0] & KEYCTL_CAPS0_MOVE,
+		     "KEYCTL_CAPS0_MOVE is set");
+
+	TST_EXP_EXPR(caps[1] & KEYCTL_CAPS1_NS_KEYRING_NAME,
+		     "KEYCTL_CAPS1_NS_KEYRING_NAME is set");

We also need KEYCTL_CAPS1_NS_KEYRING_NAME fallback added in v5.9-rc1 b206f281d0ee1 ("keys: Namespace keyring names")

(trivial fix)

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#60 lore raw

PATCH v2 29/33 keyctl35: Test KEYCTL_CAPABILITIES size query

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test that calling KEYCTL_CAPABILITIES with a NULL buffer and buflen of 0 returns the total size in bytes of the keyrings subsystem capability array without faulting.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl35.c | 49 +++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)
runtest/syscalls +1 -0
index 08877ff49..67d626c22 100644
@@ -752,6 +752,7 @@ keyctl31 keyctl31
 keyctl32 keyctl32
 keyctl33 keyctl33
 keyctl34 keyctl34
+keyctl35 keyctl35
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index f2ce330d7..58ebb452f 100644
@@ -32,3 +32,4 @@
 /keyctl32
 /keyctl33
 /keyctl34
+/keyctl35
testcases/kernel/syscalls/keyctl/keyctl35.c new file +49 -0

49 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#61 lore raw

PATCH v2 30/33 keyctl36: Test KEYCTL_CAPABILITIES buffer sizing

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_CAPABILITIES with short buffer (verifying partial copy without overrun) and oversized buffer (verifying trailing space is zero-filled while returning the full capability length).

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl36.c | 88 +++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+)
runtest/syscalls +1 -0
index 67d626c22..8ad8f0fe5 100644
@@ -753,6 +753,7 @@ keyctl32 keyctl32
 keyctl33 keyctl33
 keyctl34 keyctl34
 keyctl35 keyctl35
+keyctl36 keyctl36
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 58ebb452f..a4da8ae80 100644
@@ -33,3 +33,4 @@
 /keyctl33
 /keyctl34
 /keyctl35
+/keyctl36
testcases/kernel/syscalls/keyctl/keyctl36.c new file +88 -0

88 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#62 lore raw

PATCH v2 31/33 keyctl37: Negative tests for KEYCTL_CAPABILITIES

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Add negative test cases for KEYCTL_CAPABILITIES verifying that passing a NULL buffer with a non-zero length or an invalid buffer pointer fails with EFAULT.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl37.c | 63 +++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)
runtest/syscalls +1 -0
index 8ad8f0fe5..66215afd7 100644
@@ -754,6 +754,7 @@ keyctl33 keyctl33
 keyctl34 keyctl34
 keyctl35 keyctl35
 keyctl36 keyctl36
+keyctl37 keyctl37
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index a4da8ae80..7ee6b9098 100644
@@ -34,3 +34,4 @@
 /keyctl34
 /keyctl35
 /keyctl36
+/keyctl37
testcases/kernel/syscalls/keyctl/keyctl37.c new file +63 -0

63 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#63 lore raw

PATCH v2 32/33 keyctl38: Test KEYCTL_WATCH_KEY add and remove

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Test KEYCTL_WATCH_KEY by opening a watch queue notification pipe and adding then removing watches on both a user key and the session keyring.

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/keyctl/.gitignore |  1 +
 testcases/kernel/syscalls/keyctl/keyctl38.c | 91 +++++++++++++++++++++++++++++
 3 files changed, 93 insertions(+)
runtest/syscalls +1 -0
index 66215afd7..e9d47b5c4 100644
@@ -755,6 +755,7 @@ keyctl34 keyctl34
 keyctl35 keyctl35
 keyctl36 keyctl36
 keyctl37 keyctl37
+keyctl38 keyctl38
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index 7ee6b9098..c0a18dd77 100644
@@ -35,3 +35,4 @@
 /keyctl35
 /keyctl36
 /keyctl37
+/keyctl38
testcases/kernel/syscalls/keyctl/keyctl38.c new file +91 -0

91 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#64 lore raw

PATCH v2 33/33 keyctl39: Negative tests for KEYCTL_WATCH_KEY

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Add negative test cases for KEYCTL_WATCH_KEY verifying invalid watch_id values, bogus key ids, missing View permission, invalid file descriptors, non-watch-queue pipes, and removal of watches on unwatched keys.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/keyctl/.gitignore |   1 +
 testcases/kernel/syscalls/keyctl/keyctl39.c | 149 ++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+)
runtest/syscalls +1 -0
index e9d47b5c4..538449a81 100644
@@ -756,6 +756,7 @@ keyctl35 keyctl35
 keyctl36 keyctl36
 keyctl37 keyctl37
 keyctl38 keyctl38
+keyctl39 keyctl39
 
 kcmp01 kcmp01
 kcmp02 kcmp02
testcases/kernel/syscalls/keyctl/.gitignore +1 -0
index c0a18dd77..8de3d46c2 100644
@@ -36,3 +36,4 @@
 /keyctl36
 /keyctl37
 /keyctl38
+/keyctl39
testcases/kernel/syscalls/keyctl/keyctl39.c new file +149 -0

149 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp