[LTP] [PATCH v4 8/8] Add ioctl_pidfd06 test
Andrea Cervesato
andrea.cervesato@suse.de
Wed Jul 23 16:15:22 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that ioctl() doesn't allow to obtain the exit status of an
isolated process via PIDFD_INFO_EXIT in within an another isolated
process, which doesn't have any parent connection.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_pidfd06.c | 66 +++++++++++++++++++++++++
3 files changed, 68 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 118a863ba8d86e1d8a7d3cff3e7fa09d0e137413..4ef3ed04a208dcc4dcffa8d597ccf0f7db6887e1 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -618,6 +618,7 @@ ioctl_pidfd02 ioctl_pidfd02
ioctl_pidfd03 ioctl_pidfd03
ioctl_pidfd04 ioctl_pidfd04
ioctl_pidfd05 ioctl_pidfd05
+ioctl_pidfd06 ioctl_pidfd06
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 09963c3896fb124ef1149bbd743537dd691400ee..dac4583fa7c05a4cdd937e86bd8f935dd15aebc8 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -35,3 +35,4 @@
/ioctl_pidfd03
/ioctl_pidfd04
/ioctl_pidfd05
+/ioctl_pidfd06
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd06.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd06.c
new file mode 100644
index 0000000000000000000000000000000000000000..998f642e806b17a4d4770b2b2a3263560dd22644
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd06.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that ioctl() doesn't allow to obtain the exit status of an isolated
+ * process via PIDFD_INFO_EXIT in within an another isolated process, which
+ * doesn't have any parent connection.
+ */
+
+#include "ioctl_pidfd.h"
+#include "lapi/sched.h"
+
+static struct tst_clone_args *args;
+static struct pidfd_info *info;
+
+static void run(void)
+{
+ int pidfd;
+ pid_t pid_child;
+
+ memset(args, 0, sizeof(struct tst_clone_args));
+ memset(info, 0, sizeof(struct pidfd_info));
+
+ info->mask = PIDFD_INFO_EXIT;
+
+ 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, NULL, 0);
+
+ memset(args, 0, sizeof(struct tst_clone_args));
+
+ args->flags = CLONE_NEWUSER | CLONE_NEWPID;
+ args->exit_signal = SIGCHLD;
+
+ if (!SAFE_CLONE(args)) {
+ TST_EXP_FAIL(ioctl(pidfd, PIDFD_GET_INFO, info), ESRCH);
+ exit(0);
+ }
+
+ SAFE_CLOSE(pidfd);
+}
+
+static void setup(void)
+{
+ if (!ioctl_pidfd_info_exit_supported())
+ tst_brk(TCONF, "PIDFD_INFO_EXIT is not supported by ioctl()");
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .forks_child = 1,
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(*args)},
+ {&info, .size = sizeof(*info)},
+ {}
+ }
+};
--
2.50.1
More information about the ltp
mailing list