[LTP] [PATCH v2 29/33] keyctl35: Test KEYCTL_CAPABILITIES size query
Andrea Cervesato
andrea.cervesato@suse.de
Fri Sep 4 14:09:18 CEST 2026
From: Andrea Cervesato <andrea.cervesato@suse.com>
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.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/keyctl/.gitignore | 1 +
testcases/kernel/syscalls/keyctl/keyctl35.c | 49 +++++++++++++++++++++++++++++
3 files changed, 51 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 08877ff49..67d626c22 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -752,6 +752,7 @@ keyctl31 keyctl31
keyctl32 keyctl32
keyctl33 keyctl33
keyctl34 keyctl34
+keyctl35 keyctl35
kcmp01 kcmp01
kcmp02 kcmp02
diff --git a/testcases/kernel/syscalls/keyctl/.gitignore b/testcases/kernel/syscalls/keyctl/.gitignore
index f2ce330d7..58ebb452f 100644
--- a/testcases/kernel/syscalls/keyctl/.gitignore
+++ b/testcases/kernel/syscalls/keyctl/.gitignore
@@ -32,3 +32,4 @@
/keyctl32
/keyctl33
/keyctl34
+/keyctl35
diff --git a/testcases/kernel/syscalls/keyctl/keyctl35.c b/testcases/kernel/syscalls/keyctl/keyctl35.c
new file mode 100644
index 000000000..43a8e2c7b
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl35.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test ``KEYCTL_CAPABILITIES`` size query of :manpage:`keyctl(2)`, added in Linux 5.3.
+ *
+ * [Algorithm]
+ *
+ * - call ``KEYCTL_CAPABILITIES`` with NULL buffer and ``buflen = 0``
+ * - verify the return value is at least 2 bytes
+ * - verify calling ``KEYCTL_CAPABILITIES`` with a valid buffer returns the
+ * same size
+ */
+
+#include "keyctl_common.h"
+
+static unsigned char buf[8];
+
+static void run(void)
+{
+ long size;
+
+ TEST(keyctl(KEYCTL_CAPABILITIES, (unsigned long)NULL, 0, 0, 0));
+ if (TST_RET < 0)
+ tst_brk(TBROK | TTERRNO, "KEYCTL_CAPABILITIES size query failed");
+
+ size = TST_RET;
+ if (size < 2) {
+ tst_res(TFAIL, "KEYCTL_CAPABILITIES size query returned %ld, expected >= 2",
+ size);
+ return;
+ }
+
+ tst_res(TPASS, "KEYCTL_CAPABILITIES size query returned %ld", size);
+
+ TST_EXP_VAL(keyctl(KEYCTL_CAPABILITIES, (unsigned long)buf, sizeof(buf), 0, 0),
+ size);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .min_kver = "5.3",
+ .needs_kconfigs = (const char *[]) {
+ "CONFIG_KEYS=y",
+ NULL
+ },
+};
--
2.51.0
More information about the ltp
mailing list