[LTP] [PATCH 5/6] Add ioctl_pidfd03 test
Andrea Cervesato
andrea.cervesato@suse.de
Thu Jun 26 14:34:42 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that ioctl() returns ESRCH when a process attempts to access
the exit status of an isolated child using `PIDFD_GET_INFO` and
`PIDFD_INFO_EXIT` is not defined in `struct pidfd_info`.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_pidfd03.c | 50 +++++++++++++++++++++++++
3 files changed, 52 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 23f335846663d62a39e6de3a8f6948c1b0acf8a5..8eec613a941a83b1fed25f96cdce617da0b0ef34 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -614,6 +614,7 @@ ioctl_fiemap01 ioctl_fiemap01
ioctl_pidfd01 ioctl_pidfd01
ioctl_pidfd02 ioctl_pidfd02
+ioctl_pidfd03 ioctl_pidfd03
inotify_init1_01 inotify_init1_01
inotify_init1_02 inotify_init1_02
diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
index 1c81c2bed8db952af0c93fb1ce5bfbad82794b60..08387dc8f2bc43f8f3a75264841da4beee28bfac 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -31,3 +31,4 @@
/ioctl_fiemap01
/ioctl_pidfd01
/ioctl_pidfd02
+/ioctl_pidfd03
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd03.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd03.c
new file mode 100644
index 0000000000000000000000000000000000000000..0fef9e671d29f9a0a07e3f62973364cf365ac014
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd03.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that ioctl() returns ESRCH when a process attempts to access the
+ * exit status of an isolated child using `PIDFD_GET_INFO` and
+ * `PIDFD_INFO_EXIT` is not defined in `struct pidfd_info`.
+ */
+
+#include "tst_test.h"
+#include "lapi/pidfd.h"
+#include "lapi/sched.h"
+
+static struct tst_clone_args *args;
+static struct pidfd_info *info;
+
+static void run(void)
+{
+ int status;
+ int pidfd = 0;
+ pid_t pid_child;
+
+ memset(args, 0, sizeof(struct tst_clone_args));
+
+ args->flags = CLONE_PIDFD | CLONE_NEWUSER | CLONE_NEWPID;
+ args->pidfd = (uint64_t)&pidfd;
+ args->exit_signal = SIGCHLD;
+
+ pid_child = SAFE_CLONE(args);
+ if (!pid_child)
+ exit(100);
+
+ SAFE_WAITPID(pid_child, &status, 0);
+
+ TST_EXP_FAIL(ioctl(pidfd, PIDFD_GET_INFO, info), ESRCH);
+ TST_EXP_EQ_LI(info->mask & PIDFD_INFO_EXIT, 0);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .forks_child = 1,
+ .min_kver = "6.15",
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(*args)},
+ {&info, .size = sizeof(*info)},
+ {}
+ }
+};
--
2.50.0
More information about the ltp
mailing list