[LTP] [PATCH v2 4/5] syscalls: add listns01 test for EFAULT on invalid address

Andrea Cervesato
2026-03-13T11:49:23Z

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

Verify that listns() returns EFAULT when given a completely invalid
address or a NULL pointer as the output buffer.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 ++
testcases/kernel/syscalls/listns/.gitignore | 1 +
testcases/kernel/syscalls/listns/Makefile | 7 ++++
testcases/kernel/syscalls/listns/listns01.c | 56 +++++++++++++++++++++++++++++
4 files changed, 66 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 2179e007c0d72fa2834a1a52b97d888a8ffb4578..769ce4a89a325ea09fdf2cfd42576697f23352c4 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -759,6 +759,8 @@ listmount02 listmount02
listmount03 listmount03
listmount04 listmount04

+listns01 listns01
+
listxattr01 listxattr01
listxattr02 listxattr02
listxattr03 listxattr03
diff --git a/testcases/kernel/syscalls/listns/.gitignore b/testcases/kernel/syscalls/listns/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..396d6b6fbfb3e34f17c79bfa3d5cc60f76477584
--- /dev/null
+++ b/testcases/kernel/syscalls/listns/.gitignore
@@ -0,0 +1 @@
+listns01
diff --git a/testcases/kernel/syscalls/listns/Makefile b/testcases/kernel/syscalls/listns/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..13755014997afbdc389e1a8fb1b0f0df36c81f21
--- /dev/null
+++ b/testcases/kernel/syscalls/listns/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2026 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/listns/listns01.c b/testcases/kernel/syscalls/listns/listns01.c
new file mode 100644
index 0000000000000000000000000000000000000000..e9211e0ef9baf68698fbd9f3500d0ec00cd13590
--- /dev/null
+++ b/testcases/kernel/syscalls/listns/listns01.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test listns() EFAULT error handling with invalid buffer pointers.
+ *
+ * Verify that listns() returns EFAULT when given a completely invalid
+ * address or a NULL pointer as the output buffer.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/listns.h"
+
+static struct tcase {
+ const char *desc;
+ uintptr_t bad_ptr_val;
+ size_t nr_ids;
+} tcases[] = {
+ {
+ .desc = "completely invalid pointer",
+ .bad_ptr_val = 0xdeadbeef,
+ .nr_ids = 10,
+ },
+ {
+ .desc = "NULL buffer",
+ .bad_ptr_val = 0,
+ .nr_ids = 10,
+ },
+};
+
+static void verify_listns(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+ struct listns_req req = { .size = NS_ID_REQ_SIZE_VER0 };
+
+ TST_EXP_FAIL2(listns(&req, (uint64_t *)tc->bad_ptr_val, tc->nr_ids, 0),
+ EFAULT, "listns() %s", tc->desc);
+}
+
+static void setup(void)
+{
+ struct listns_req req = { .size = NS_ID_REQ_SIZE_VER0 };
+
+ tst_syscall(__NR_listns, &req, NULL, 0, 0);
+}
+
+static struct tst_test test = {
+ .tcnt = ARRAY_SIZE(tcases),
+ .test = verify_listns,
+ .setup = setup,
+};

--
2.51.0