Skip to contentSkip to conversation

listns() testing suite

PATCH In review Andrea Cervesato 3 participants 15 messages Mar 13 – Mar 24

lore
Share & tools
lore
#0 lore raw

v2 cover listns() testing suite

This testing suite is focusing on basic listns() syscall functionalities, since most of the complex scenarios are already covered inside the kselftests at tools/testing/selftests/namespaces/.

This is the first testing suite where we started to use AI agents and claude configuration at https://github.com/acerv/agents-config

---
Changes in v2:
- link tests to runtest file
- listns02: don't reap children before exit the test
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrea Cervesato (5):
Update architectures syscalls identifiers
Add listns fallback header
Add NS_GET_ID fallback
syscalls: add listns01 test for EFAULT on invalid address
syscalls: add listns02 functionality test

 include/lapi/ioctl_ns.h                     |   3 +
 include/lapi/listns.h                       |  36 +++++++++
 include/lapi/syscalls/arc.in                |   2 +
 include/lapi/syscalls/arm.in                |   3 +-
 include/lapi/syscalls/arm64.in              |   2 +
 include/lapi/syscalls/i386.in               |   3 +-
 include/lapi/syscalls/loongarch64.in        |   3 +
 include/lapi/syscalls/mips64.in             |   4 +-
 include/lapi/syscalls/mips64n32.in          |   4 +-
 include/lapi/syscalls/mipso32.in            |   4 +-
 include/lapi/syscalls/parisc.in             |   3 +-
 include/lapi/syscalls/powerpc.in            |   3 +-
 include/lapi/syscalls/powerpc64.in          |   3 +-
 include/lapi/syscalls/s390.in               | 102 +++++++-------------------
 include/lapi/syscalls/s390x.in              |   4 +-
 include/lapi/syscalls/sh.in                 |   3 +-
 include/lapi/syscalls/sparc.in              |   4 +-
 include/lapi/syscalls/sparc64.in            |   4 +-
 include/lapi/syscalls/x86_64.in             |   4 +-
 runtest/syscalls                            |   3 +
 testcases/kernel/syscalls/listns/.gitignore |   2 +
 testcases/kernel/syscalls/listns/Makefile   |   7 ++
 testcases/kernel/syscalls/listns/listns01.c |  56 ++++++++++++++
 testcases/kernel/syscalls/listns/listns02.c | 109 ++++++++++++++++++++++++++++
 24 files changed, 277 insertions(+), 94 deletions(-)

---
base-commit: 712e6e47e9744a1cf60074bf90e45ef402cce90f
change-id: 20260312-listns-3f85a0d77cca

Best regards,

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


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

PATCH v2 1/5 Update architectures syscalls identifiers

From: Andrea Cervesato <[email protected]>

---
 include/lapi/syscalls/arc.in         |   2 +
 include/lapi/syscalls/arm.in         |   3 +-
 include/lapi/syscalls/arm64.in       |   2 +
 include/lapi/syscalls/i386.in        |   3 +-
 include/lapi/syscalls/loongarch64.in |   3 ++
 include/lapi/syscalls/mips64.in      |   4 +-
 include/lapi/syscalls/mips64n32.in   |   4 +-
 include/lapi/syscalls/mipso32.in     |   4 +-
 include/lapi/syscalls/parisc.in      |   3 +-
 include/lapi/syscalls/powerpc.in     |   3 +-
 include/lapi/syscalls/powerpc64.in   |   3 +-
 include/lapi/syscalls/s390.in        | 102 +++++++++--------------------------
 include/lapi/syscalls/s390x.in       |   4 +-
 include/lapi/syscalls/sh.in          |   3 +-
 include/lapi/syscalls/sparc.in       |   4 +-
 include/lapi/syscalls/sparc64.in     |   4 +-
 include/lapi/syscalls/x86_64.in      |   4 +-
 17 files changed, 61 insertions(+), 94 deletions(-)
include/lapi/syscalls/arc.in +2 -0
index 0f0fbef6be74d06abbf4f1bbf77eeaf72a1e6b71..89b04af1caf54e9b93b84c1e2bc1372f03a5d2a6 100644
@@ -347,3 +347,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/arm.in +2 -1
index d0238dec5ecbf3849dff3b2c91ec88866dfb440c..72e07584b9fe5e09ff8661cf88db3dffcfd89720 100644
@@ -109,7 +109,6 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
-_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
@@ -420,3 +419,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/arm64.in +2 -0
index c76930e20df02905c9c640a749b4ec2df421c665..46dc7bbfbbce035effd41274fd4757a116a07a03 100644
@@ -323,3 +323,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/i386.in +2 -1
index 38ea71fb282d9dc69914b863cba352349fd1c9b9..8905d7f43073f275f571846e900d48abe959c6d2 100644
@@ -145,7 +145,6 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
-_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
@@ -454,3 +453,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/loongarch64.in +3 -0
index 5407b86eaf738354f645f894bd95900ff614b3e1..60f77a7d1c84059f119bc1d988e9b6b89569e2f5 100644
@@ -297,6 +297,7 @@ quotactl_fd 443
 landlock_create_ruleset 444
 landlock_add_rule 445
 landlock_restrict_self 446
+memfd_secret 447
 process_mrelease 448
 futex_waitv 449
 set_mempolicy_home_node 450
@@ -319,3 +320,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/mips64.in +2 -2
index 436d5c681c21f32623d779268b9c3daaaac5b5e0..0375503686461386e70637f6a3cc3b69a48cf235 100644
@@ -150,7 +150,6 @@ mlockall 5148
 munlockall 5149
 vhangup 5150
 pivot_root 5151
-_sysctl 5152
 prctl 5153
 adjtimex 5154
 setrlimit 5155
@@ -272,7 +271,6 @@ ioprio_set 5273
 ioprio_get 5274
 utimensat 5275
 signalfd 5276
-timerfd 5277
 eventfd 5278
 fallocate 5279
 timerfd_create 5280
@@ -369,3 +367,5 @@ removexattrat 5466
 open_tree_attr 5467
 file_getattr 5468
 file_setattr 5469
+listns 5470
+rseq_slice_yield 5471
include/lapi/syscalls/mips64n32.in +2 -2
index 860a19c8b62866aeaf5b03c5c45ef5d6d58cab0f..0998b2bd8b0e318af44178762766a2e7cc7a2b63 100644
@@ -150,7 +150,6 @@ mlockall 6148
 munlockall 6149
 vhangup 6150
 pivot_root 6151
-_sysctl 6152
 prctl 6153
 adjtimex 6154
 setrlimit 6155
@@ -276,7 +275,6 @@ ioprio_set 6277
 ioprio_get 6278
 utimensat 6279
 signalfd 6280
-timerfd 6281
 eventfd 6282
 fallocate 6283
 timerfd_create 6284
@@ -393,3 +391,5 @@ removexattrat 6466
 open_tree_attr 6467
 file_getattr 6468
 file_setattr 6469
+listns 6470
+rseq_slice_yield 6471
include/lapi/syscalls/mipso32.in +2 -2
index 5e53e46ce1e47c4618ceeeda03130cbdd621b180..75ac1ef1e0d431fd154ca507dbb8cef07c3226b4 100644
@@ -144,7 +144,6 @@ cachectl 4148
 sysmips 4149
 getsid 4151
 fdatasync 4152
-_sysctl 4153
 mlock 4154
 munlock 4155
 mlockall 4156
@@ -307,7 +306,6 @@ ioprio_set 4314
 ioprio_get 4315
 utimensat 4316
 signalfd 4317
-timerfd 4318
 eventfd 4319
 fallocate 4320
 timerfd_create 4321
@@ -433,3 +431,5 @@ removexattrat 4466
 open_tree_attr 4467
 file_getattr 4468
 file_setattr 4469
+listns 4470
+rseq_slice_yield 4471
include/lapi/syscalls/parisc.in +2 -1
index 238756694d9a03bcb063c21d3644aaa2af47f3fc..8007565f571ec3a7673adbf20246ee335c221067 100644
@@ -142,7 +142,6 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
-_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
@@ -402,3 +401,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/powerpc.in +2 -1
index 6911f9af96247739a1ba7020aa3df77ef70ef55a..02a91ac46c6d6149282d2a2ec5fe8fd50a466ba6 100644
@@ -145,7 +145,6 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
-_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
@@ -444,3 +443,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/powerpc64.in +2 -1
index 98190ba266a1c7a6c3dbca1346e9d5e55783e271..931b95f69e7c1c150ef54d63956d42511ffabb50 100644
@@ -145,7 +145,6 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
-_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
@@ -416,3 +415,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/s390.in +25 -77

216 lines not on this page · raw message

include/lapi/syscalls/s390x.in +2 -2
index 31f3ec5532c8c3017188b60907f7666b41f44102..978092202738cd97f345fe9757d5b7355814d893 100644
@@ -107,7 +107,6 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
-_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
@@ -258,7 +257,6 @@ utimes 313
 fallocate 314
 utimensat 315
 signalfd 316
-timerfd 317
 eventfd 318
 timerfd_create 319
 timerfd_settime 320
@@ -385,3 +383,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/sh.in +2 -1
index ac281acf81ffe6770fa0d941d406714fbdce1bbd..e3cef0e77632f5c76af781384fa39406727ae826 100644
@@ -128,7 +128,6 @@ readv 145
 writev 146
 getsid 147
 fdatasync 148
-_sysctl 149
 mlock 150
 munlock 151
 mlockall 152
@@ -431,3 +430,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/sparc.in +3 -1
index ffc0d9f7abdaa8873ec73ed1a5e0ec98b5f8b1d7..20d58a5999172674c78585d0d1435024a65d0119 100644
@@ -246,7 +246,6 @@ sched_get_priority_min 247
 sched_rr_get_interval 248
 nanosleep 249
 mremap 250
-_sysctl 251
 getsid 252
 fdatasync 253
 nfsservctl 254
@@ -402,6 +401,7 @@ fsconfig 431
 fsmount 432
 fspick 433
 pidfd_open 434
+clone3 435
 close_range 436
 openat2 437
 pidfd_getfd 438
@@ -435,3 +435,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/sparc64.in +3 -1
index 992bd307deb07d50ff814c603406842b5aedb431..49419ef5d65d7f9bfb4cbc715bc671d2d387deef 100644
@@ -228,7 +228,6 @@ sched_get_priority_min 247
 sched_rr_get_interval 248
 nanosleep 249
 mremap 250
-_sysctl 251
 getsid 252
 fdatasync 253
 nfsservctl 254
@@ -365,6 +364,7 @@ fsconfig 431
 fsmount 432
 fspick 433
 pidfd_open 434
+clone3 435
 close_range 436
 openat2 437
 pidfd_getfd 438
@@ -398,3 +398,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
include/lapi/syscalls/x86_64.in +3 -1
index e9c0d0599e25e3fa408686544c5d80c5a3e876d7..a253bcfd7d2461634e0a3a1c1e1c312fef682a66 100644
@@ -154,7 +154,6 @@ munlockall 152
 vhangup 153
 modify_ldt 154
 pivot_root 155
-_sysctl 156
 prctl 157
 arch_prctl 158
 adjtimex 159
@@ -334,6 +333,7 @@ statx 332
 io_pgetevents 333
 rseq 334
 uretprobe 335
+uprobe 336
 pidfd_send_signal 424
 io_uring_setup 425
 io_uring_enter 426
@@ -380,3 +380,5 @@ removexattrat 466
 open_tree_attr 467
 file_getattr 468
 file_setattr 469
+listns 470
+rseq_slice_yield 471
Signature · 5 lines
2.51.0


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

Re: [LTP] [PATCH v2 1/5] Update architectures syscalls identifiers

Hi!

Quoted 4 lines
 include/lapi/syscalls/arc.in         |   2 +
 include/lapi/syscalls/arm.in         |   3 +-
 include/lapi/syscalls/arm64.in       |   2 +
 include/lapi/syscalls/i386.in        |   3 +-
Quoted 8 lines
 include/lapi/syscalls/loongarch64.in |   3 ++
 include/lapi/syscalls/mips64.in      |   4 +-
 include/lapi/syscalls/mips64n32.in   |   4 +-
 include/lapi/syscalls/mipso32.in     |   4 +-
 include/lapi/syscalls/parisc.in      |   3 +-
 include/lapi/syscalls/powerpc.in     |   3 +-
 include/lapi/syscalls/powerpc64.in   |   3 +-
 include/lapi/syscalls/s390.in        | 102 +++++++++--------------------------

Why do we change so much in the s390.in? I'm not saying it's wrong (I haven't checked) but even if it's correct it at least should have been explained in the commit message.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 1/5] Update architectures syscalls identifiers

Hi,

Quoted 14 lines

Hi!

Quoted 4 lines
 include/lapi/syscalls/arc.in         |   2 +
 include/lapi/syscalls/arm.in         |   3 +-
 include/lapi/syscalls/arm64.in       |   2 +
 include/lapi/syscalls/i386.in        |   3 +-
Quoted 8 lines
 include/lapi/syscalls/loongarch64.in |   3 ++
 include/lapi/syscalls/mips64.in      |   4 +-
 include/lapi/syscalls/mips64n32.in   |   4 +-
 include/lapi/syscalls/mipso32.in     |   4 +-
 include/lapi/syscalls/parisc.in      |   3 +-
 include/lapi/syscalls/powerpc.in     |   3 +-
 include/lapi/syscalls/powerpc64.in   |   3 +-
 include/lapi/syscalls/s390.in        | 102 +++++++++--------------------------
Quoted 3 lines

Why do we change so much in the s390.in? I'm not saying it's wrong (I haven't checked) but even if it's correct it at least should have been explained in the commit message.

I generated it automatically with generate_arch.sh script, which is verifying that the defined syscalls are actually supported by the architecture. It's all good when it comes to 32/64 bit variants syscalls, but it looks weird for others.

I'm a bit puzzled as well..there is a risk that by touching so many syscalls numbers LTP will be out of sync with the underlying kernel. Maybe I will just add the syscalls which are really needed such as listns().

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

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

PATCH v2 2/5 Add listns fallback header

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Create include/lapi/listns.h header file for listns syscall related definitions.

---
 include/lapi/listns.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
include/lapi/listns.h new file +36 -0
new file mode 100644
index 0000000000000000000000000000000000000000..d242d3340ee4286fb8621b1633061c8087c54e7c
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2025 Linux Test Project
+ */
+
+#ifndef LAPI_LISTNS_H__
+#define LAPI_LISTNS_H__
+
+#include <stdint.h>
+#include "lapi/syscalls.h"
+#include "lapi/sched.h"
+
+#ifndef NS_ID_REQ_SIZE_VER0
+#define NS_ID_REQ_SIZE_VER0 32
+#endif
+
+#ifndef LISTNS_CURRENT_USER
+#define LISTNS_CURRENT_USER 0xffffffffffffffffULL
+#endif
+
+struct listns_req {
+	uint32_t size;
+	uint32_t spare;
+	uint64_t ns_id;
+	uint32_t ns_type;
+	uint32_t spare2;
+	uint64_t user_ns_id;
+};
+
+static inline int listns(struct listns_req *req, uint64_t *ns_ids,
+			 size_t nr_ns_ids, unsigned int flags)
+{
+	return tst_syscall(__NR_listns, req, ns_ids, nr_ns_ids, flags);
+}
+
+#endif /* LAPI_LISTNS_H__ */
Signature · 5 lines
2.51.0


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

Re: [LTP] [PATCH v2 2/5] Add listns fallback header

Hi!

include/lapi/listns.h line 34

Quoted 5 lines
include/lapi/listns.h new file +5 -0
+static inline int listns(struct listns_req *req, uint64_t *ns_ids,
+			 size_t nr_ns_ids, unsigned int flags)
+{
+	return tst_syscall(__NR_listns, req, ns_ids, nr_ns_ids, flags);
+}

Do we need a configure check in a case that glibc happens to eventually add listns() syscall?

Otherwise it looks good.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 2/5] Add listns fallback header

Hi!

Quoted 10 lines

Hi!

include/lapi/listns.h line 34

Quoted 5 lines
include/lapi/listns.h new file +5 -0
+static inline int listns(struct listns_req *req, uint64_t *ns_ids,
+			 size_t nr_ns_ids, unsigned int flags)
+{
+	return tst_syscall(__NR_listns, req, ns_ids, nr_ns_ids, flags);
+}

Do we need a configure check in a case that glibc happens to eventually add listns() syscall?

Does it make sense at this stage?

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

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

Re: [LTP] [PATCH v2 2/5] Add listns fallback header

Hi!

Quoted 11 lines
Quoted 9 lines

include/lapi/listns.h line 34

Quoted 5 lines
include/lapi/listns.h new file +5 -0
+static inline int listns(struct listns_req *req, uint64_t *ns_ids,
+			 size_t nr_ns_ids, unsigned int flags)
+{
+	return tst_syscall(__NR_listns, req, ns_ids, nr_ns_ids, flags);
+}

Do we need a configure check in a case that glibc happens to eventually add listns() syscall?

Does it make sense at this stage?

That really depends on if we want the next release to compile cleanly in a year or two.

Signature · 5 lines
Cyril Hrubis
[email protected]

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

Re: [LTP] [PATCH v2 2/5] Add listns fallback header

Quoted 2 lines

That really depends on if we want the next release to compile cleanly in a year or two.

A bit early to decide. I would keep it as it is and eventually update the test. WDYT?

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

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

PATCH v2 3/5 Add NS_GET_ID fallback

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

---
 include/lapi/ioctl_ns.h | 3 +++
 1 file changed, 3 insertions(+)
include/lapi/ioctl_ns.h +3 -0
index 37fc5371681995fad5d955838b80153d5dd227f1..753c7657101a2c4442dfff9f36a15fc4cb5b6607 100644
@@ -27,5 +27,8 @@
 #ifndef NS_GET_MNTNS_ID
 #define NS_GET_MNTNS_ID		_IOR(NSIO, 0x5, uint64_t)
 #endif
+#ifndef NS_GET_ID
+#define NS_GET_ID		_IOR(NSIO, 13, uint64_t)
+#endif
 
 #endif /* LAPI_IOCTL_NS_H__ */
Signature · 5 lines
2.51.0


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

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

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

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

---
 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(+)
runtest/syscalls +2 -0
index 2179e007c0d72fa2834a1a52b97d888a8ffb4578..769ce4a89a325ea09fdf2cfd42576697f23352c4 100644
@@ -759,6 +759,8 @@ listmount02 listmount02
 listmount03 listmount03
 listmount04 listmount04
 
+listns01 listns01
+
 listxattr01 listxattr01
 listxattr02 listxattr02
 listxattr03 listxattr03
testcases/kernel/syscalls/listns/.gitignore new file +1 -0
new file mode 100644
index 0000000000000000000000000000000000000000..396d6b6fbfb3e34f17c79bfa3d5cc60f76477584
@@ -0,0 +1 @@
+listns01
testcases/kernel/syscalls/listns/Makefile new file +7 -0
new file mode 100644
index 0000000000000000000000000000000000000000..13755014997afbdc389e1a8fb1b0f0df36c81f21
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/listns/listns01.c new file +56 -0

56 lines not on this page · raw message

Signature · 5 lines
2.51.0


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

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

Hi!

Quoted 17 lines

+++ b/testcases/kernel/syscalls/listns/listns01.c

testcases/kernel/syscalls/listns/listns01.c new file +15 -0
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * 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"

testcases/kernel/syscalls/listns/listns01.c line 25

Quoted 10 lines
testcases/kernel/syscalls/listns/listns01.c new file +10 -0
+#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",

^
Just "invalid pointer"

Keep messages short and to the point.

testcases/kernel/syscalls/listns/listns01.c line 26

Quoted 1 line
testcases/kernel/syscalls/listns/listns01.c new file +1 -0
+		.bad_ptr_val = 0xdeadbeef,

We do have a tst_get_bad_addr() function to generate an address that is 100% sure to be invalid on any platform.

Review line 27

Quoted 1 line
(quoted diff) +1 -0
+		.nr_ids = 10,

This is the same for bot cases, no need to put it into the struct.

Quoted 36 lines
testcases/kernel/syscalls/listns/listns01.c new file +29 -0
+	},
+	{
+		.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,
+};
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
#13 lore raw

PATCH v2 5/5 syscalls: add listns02 functionality test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Add a simple test that create a namespace and verifies that listns02 is listing it.

---
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/listns/.gitignore |   1 +
 testcases/kernel/syscalls/listns/listns02.c | 109 ++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)
runtest/syscalls +1 -0
index 769ce4a89a325ea09fdf2cfd42576697f23352c4..7d67f6ed2489e7281a07ae9f059b7485dd5f5f44 100644
@@ -760,6 +760,7 @@ listmount03 listmount03
 listmount04 listmount04
 
 listns01 listns01
+listns02 listns02
 
 listxattr01 listxattr01
 listxattr02 listxattr02
testcases/kernel/syscalls/listns/.gitignore +1 -0
index 396d6b6fbfb3e34f17c79bfa3d5cc60f76477584..26d31ae372c54e0031a71b56f68cad44f32e5962 100644
@@ -1 +1,2 @@
 listns01
+listns02
testcases/kernel/syscalls/listns/listns02.c new file +109 -0

109 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 5/5
#14 lore raw

Re: [LTP] [PATCH v2 5/5] syscalls: add listns02 functionality test

Hi!

testcases/kernel/syscalls/listns/listns02.c line 76

Quoted 8 lines
testcases/kernel/syscalls/listns/listns02.c new file +8 -0
+	if (TST_RET < 0) {
+		tst_res(TFAIL | TTERRNO, "listns() failed for %s", tc->desc);
+		return;
+	}
+
+	found = 0;
+	for (int i = 0; i < TST_RET; i++) {
+		tst_res(TDEBUG, "buf[%d] = %lu", i, buf[i]);

^
I would say that this is a bit cryptic.

If we want have debugging output I would add something as:

	tst_res(TDEBUG, "Looking for nsid=%lu", ns_id);

	for (int i ...) {
		tst_res(TDEBUG, "list %i. nsid=%lu", i, buf[i]);

	}

Otherwise it looks good:

Signature · 5 lines
Cyril Hrubis
[email protected]

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