All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 00/33] Improve coverage for keyctl() syscall
@ 2026-09-04 12:08 Andrea Cervesato
  2026-09-04 12:08 ` [LTP] [PATCH v2 01/33] lapi/keyctl.h: Add fallback definitions for extended ops Andrea Cervesato
                   ` (32 more replies)
  0 siblings, 33 replies; 61+ messages in thread
From: Andrea Cervesato @ 2026-09-04 12:08 UTC (permalink / raw)
  To: Linux Test Project

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#

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v2:
- fix build
- Link to v1: https://lore.kernel.org/20260902-keyctl_coverage-v1-0-d29dfa2ebcef@suse.com

To: Linux Test Project <ltp@lists.linux.it>

---
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,
--  
Andrea Cervesato <andrea.cervesato@suse.com>


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

^ permalink raw reply	[flat|nested] 61+ messages in thread
* [LTP] [PATCH 02/33] keyctl10: Test KEYCTL_DESCRIBE format parsing
@ 2026-09-02 11:04 Andrea Cervesato
  2026-09-02 14:07 ` [LTP] lapi/keyctl.h: Add fallback definitions for extended ops linuxtestproject.agent
  0 siblings, 1 reply; 61+ messages in thread
From: Andrea Cervesato @ 2026-09-02 11:04 UTC (permalink / raw)
  To: Linux Test Project

From: Andrea Cervesato <andrea.cervesato@suse.com>

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.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 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(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 737c63e31..bf4c0d46e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -727,6 +727,7 @@ keyctl06 keyctl06
 keyctl07 keyctl07
 keyctl08 keyctl08
 keyctl09 keyctl09
+keyctl10 keyctl10
 
 kcmp01 kcmp01
 kcmp02 kcmp02
diff --git a/testcases/kernel/syscalls/keyctl/.gitignore b/testcases/kernel/syscalls/keyctl/.gitignore
index f9948c176..08b2d101d 100644
--- a/testcases/kernel/syscalls/keyctl/.gitignore
+++ b/testcases/kernel/syscalls/keyctl/.gitignore
@@ -7,3 +7,4 @@
 /keyctl07
 /keyctl08
 /keyctl09
+/keyctl10
diff --git a/testcases/kernel/syscalls/keyctl/keyctl10.c b/testcases/kernel/syscalls/keyctl/keyctl10.c
new file mode 100644
index 000000000..105daa63d
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl10.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test the format parsing of ``KEYCTL_DESCRIBE`` of :manpage:`keyctl(2)`.
+ *
+ * ``KEYCTL_DESCRIBE`` formats a key description as
+ * "type;uid;gid;perm;description" and returns the full length of the
+ * string including the terminating NUL byte.
+ *
+ * [Algorithm]
+ *
+ * - describe a valid key and verify all five fields of the description
+ *   match the key's attributes
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include "keyctl_common.h"
+
+#define KEY_DESC	"ltpkeyctl10"
+#define PAYLOAD		"payload"
+#define BUF_SIZE	64
+
+static key_serial_t key;
+static long desc_len;
+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);
+
+	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;
+}
+
+static void run(void)
+{
+	char type[32], desc[BUF_SIZE];
+	unsigned int uid, gid, perm;
+
+	memset(buf, 0, sizeof(buf));
+	TST_EXP_EQ_LI_SILENT(keyctl(KEYCTL_DESCRIBE, key, (unsigned long)buf,
+				    sizeof(buf), 0), desc_len);
+	if (!TST_PASS)
+		return;
+
+	TST_EXP_EQ_SZ_SILENT((size_t)desc_len, strlen(buf) + 1);
+	if (!TST_PASS) {
+		tst_res(TINFO, "unexpected description '%s'", buf);
+		return;
+	}
+
+	if (sscanf(buf, "%31[^;];%u;%u;%x;%63[^\n]",
+		   type, &uid, &gid, &perm, desc) != 5) {
+		tst_res(TFAIL, "malformed description '%s'", buf);
+		return;
+	}
+
+	if (strcmp(type, "user")) {
+		tst_res(TFAIL, "wrong key type '%s', expected 'user'", type);
+		return;
+	}
+
+	if (uid != getuid() || gid != getgid()) {
+		tst_res(TFAIL, "wrong owner uid %u gid %u, expected %u %u",
+			uid, gid, getuid(), getgid());
+		return;
+	}
+
+	if (perm != KEY_PERM_SET) {
+		tst_res(TFAIL, "wrong permissions %08x, expected %08x",
+			perm, KEY_PERM_SET);
+		return;
+	}
+
+	if (strcmp(desc, KEY_DESC)) {
+		tst_res(TFAIL, "wrong description '%s', expected '%s'",
+			desc, KEY_DESC);
+		return;
+	}
+
+	tst_res(TPASS, "described the key correctly");
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/keyctl/keyctl_common.h b/testcases/kernel/syscalls/keyctl/keyctl_common.h
new file mode 100644
index 000000000..c7290cc6e
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl_common.h
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#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;
+}
+
+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;
+}
+
+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);
+}
+
+#endif /* KEYCTL_COMMON_H__ */

-- 
2.51.0


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

^ permalink raw reply related	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2026-09-11 19:24 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 12:08 [LTP] [PATCH v2 00/33] Improve coverage for keyctl() syscall Andrea Cervesato
2026-09-04 12:08 ` [LTP] [PATCH v2 01/33] lapi/keyctl.h: Add fallback definitions for extended ops Andrea Cervesato
2026-09-04 15:18   ` [LTP] " linuxtestproject.agent
2026-09-11  7:31   ` [LTP] [PATCH v2 01/33] " Cyril Hrubis
2026-09-11  8:58     ` Petr Vorel
2026-09-04 12:08 ` [LTP] [PATCH v2 02/33] keyctl10: Test KEYCTL_DESCRIBE format parsing Andrea Cervesato
2026-09-11  7:54   ` Cyril Hrubis
2026-09-04 12:08 ` [LTP] [PATCH v2 03/33] keyctl11: Test KEYCTL_DESCRIBE with exact buffer size Andrea Cervesato
2026-09-11  8:01   ` Cyril Hrubis
2026-09-04 12:08 ` [LTP] [PATCH v2 04/33] keyctl12: Test KEYCTL_DESCRIBE with too small buffer Andrea Cervesato
2026-09-11  8:09   ` Cyril Hrubis
2026-09-04 12:08 ` [LTP] [PATCH v2 05/33] keyctl13: Test KEYCTL_DESCRIBE size query Andrea Cervesato
2026-09-04 12:08 ` [LTP] [PATCH v2 06/33] keyctl14: Negative tests for KEYCTL_DESCRIBE Andrea Cervesato
2026-09-11  8:17   ` Cyril Hrubis
2026-09-04 12:08 ` [LTP] [PATCH v2 07/33] keyctl15: Test KEYCTL_GET_SECURITY label retrieval Andrea Cervesato
2026-09-11  8:20   ` Cyril Hrubis
2026-09-11  9:11     ` Petr Vorel
2026-09-11 15:34       ` Cyril Hrubis
2026-09-11 19:24         ` Petr Vorel
2026-09-04 12:08 ` [LTP] [PATCH v2 08/33] keyctl16: Test KEYCTL_GET_SECURITY truncated copy Andrea Cervesato
2026-09-11  8:30   ` Cyril Hrubis
2026-09-04 12:08 ` [LTP] [PATCH v2 09/33] keyctl17: Negative tests for KEYCTL_GET_SECURITY Andrea Cervesato
2026-09-11  8:40   ` Cyril Hrubis
2026-09-04 12:08 ` [LTP] [PATCH v2 10/33] keyctl18: Test basic KEYCTL_MOVE Andrea Cervesato
2026-09-11 11:48   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 11/33] keyctl19: Test KEYCTL_MOVE with same source and destination Andrea Cervesato
2026-09-11 11:52   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 12/33] keyctl20: Test KEYCTL_MOVE displacement Andrea Cervesato
2026-09-11 12:00   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 13/33] keyctl21: Negative and boundary tests for KEYCTL_MOVE Andrea Cervesato
2026-09-11 12:11   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 14/33] keyctl22: Test KEYCTL_RESTRICT_KEYRING reject-all Andrea Cervesato
2026-09-11 12:13   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 15/33] keyctl23: Test KEYCTL_RESTRICT_KEYRING builtin_trusted Andrea Cervesato
2026-09-11 12:34   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 16/33] keyctl24: Negative tests for KEYCTL_RESTRICT_KEYRING Andrea Cervesato
2026-09-11 14:36   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 17/33] keyctl25: Test KEYCTL_DH_COMPUTE shared secret computation Andrea Cervesato
2026-09-11 14:53   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 18/33] keyctl26: Test KEYCTL_DH_COMPUTE size query Andrea Cervesato
2026-09-11 14:54   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 19/33] keyctl27: Test KEYCTL_DH_COMPUTE KDF key derivation Andrea Cervesato
2026-09-11 15:05   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 20/33] keyctl28: Negative and boundary tests for KEYCTL_DH_COMPUTE Andrea Cervesato
2026-09-11 15:17   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 21/33] lapi/keyctl.h: Add fallback definitions for public key ops Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 22/33] keyctl29: Test KEYCTL_PKEY_QUERY on public key Andrea Cervesato
2026-09-11 15:35   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 23/33] keyctl30: Test KEYCTL_PKEY_QUERY on private key Andrea Cervesato
2026-09-11 15:37   ` Cyril Hrubis
2026-09-04 12:09 ` [LTP] [PATCH v2 24/33] keyctl31: Test KEYCTL_PKEY_ENCRYPT and KEYCTL_PKEY_DECRYPT Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 25/33] keyctl32: Test KEYCTL_PKEY_SIGN and VERIFY Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 26/33] keyctl33: Negative tests for KEYCTL_PKEY_* Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 27/33] lapi/keyctl.h: Add capability fallback defines Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 28/33] keyctl34: Test KEYCTL_CAPABILITIES flag retrieval Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 29/33] keyctl35: Test KEYCTL_CAPABILITIES size query Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 30/33] keyctl36: Test KEYCTL_CAPABILITIES buffer sizing Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 31/33] keyctl37: Negative tests for KEYCTL_CAPABILITIES Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 32/33] keyctl38: Test KEYCTL_WATCH_KEY add and remove Andrea Cervesato
2026-09-04 12:09 ` [LTP] [PATCH v2 33/33] keyctl39: Negative tests for KEYCTL_WATCH_KEY Andrea Cervesato
  -- strict thread matches above, loose matches on Subject: below --
2026-09-02 11:04 [LTP] [PATCH 02/33] keyctl10: Test KEYCTL_DESCRIBE format parsing Andrea Cervesato
2026-09-02 14:07 ` [LTP] lapi/keyctl.h: Add fallback definitions for extended ops linuxtestproject.agent

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.