[LTP] [PATCH v3 32/36] keyctl35: Test KEYCTL_CAPABILITIES size query
Petr Vorel
pvorel@suse.cz
Wed Sep 16 16:03:58 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.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
[ pvorel: use SAFE_KEYCTL() ]
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/keyctl/.gitignore | 1 +
testcases/kernel/syscalls/keyctl/keyctl35.c | 46 +++++++++++++++++++++
3 files changed, 48 insertions(+)
create mode 100644 testcases/kernel/syscalls/keyctl/keyctl35.c
diff --git a/runtest/syscalls b/runtest/syscalls
index e5450ff173..55299bd7c0 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 f2ce330d77..58ebb452fa 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 0000000000..cc0054813e
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl35.c
@@ -0,0 +1,46 @@
+// 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)
+{
+ int size;
+
+ size = SAFE_KEYCTL(KEYCTL_CAPABILITIES, (unsigned long)NULL, 0, 0, 0);
+
+ if (size < 2) {
+ tst_res(TFAIL, "KEYCTL_CAPABILITIES size query returned %d, expected >= 2",
+ size);
+ return;
+ }
+
+ tst_res(TPASS, "KEYCTL_CAPABILITIES size query returned %d", 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.55.0
More information about the ltp
mailing list