* [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite
@ 2025-07-23 14:15 Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 1/8] Provide pidfd parameter in tst_clone_args Andrea Cervesato
` (8 more replies)
0 siblings, 9 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
The testing suite has been created to cover the new feature
PIDFD_INFO_EXIT provided by kernel 6.15.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v4:
- use ioctl_pidfd_info_exit_supported() name and check for minimum
kernel version inside it
- close pidfd at the end of tests
- fix wrong import in autoconf for sys/linux.h
- Link to v3: https://lore.kernel.org/r/20250707-ioctl_pidfd_suite-v3-0-22ba4d15ee02@suse.com
Changes in v3:
- ioctl_pidfd02: compare exit_code with status from waitpid()
- check for PIDFD_INFO_EXIT support ioctl_pidfd.h
ioctl_pidfd_suite-v1-0-165b9abf0296
- Link to v2: https://lore.kernel.org/r/20250704-ioctl_pidfd_suite-v2-0-88a6466d9f62@suse.com
Changes in v2:
- ioctl_pidfd02: check all flags of info before and after process being
reaped. Include a fork() test
- ioctl_pidfd03: verify process info before being reaped
- add more error tests
- Link to v1: https://lore.kernel.org/r/20250626-ioctl_pidfd_suite-v1-0-165b9abf0296@suse.com
---
Andrea Cervesato (8):
Provide pidfd parameter in tst_clone_args
Fallback PIDFD_GET_INFO related definitions
Add ioctl_pidfd01 test
Add ioctl_pidfd02 test
Add ioctl_pidfd03 test
Add ioctl_pidfd04 test
Add ioctl_pidfd05 test
Add ioctl_pidfd06 test
configure.ac | 2 +
include/lapi/pidfd.h | 39 +++++++++++-
include/tst_clone.h | 1 +
lib/tst_clone.c | 1 +
runtest/syscalls | 7 ++
testcases/kernel/syscalls/ioctl/.gitignore | 6 ++
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 41 ++++++++++++
testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c | 58 +++++++++++++++++
testcases/kernel/syscalls/ioctl/ioctl_pidfd02.c | 85 +++++++++++++++++++++++++
testcases/kernel/syscalls/ioctl/ioctl_pidfd03.c | 64 +++++++++++++++++++
testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c | 71 +++++++++++++++++++++
testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c | 59 +++++++++++++++++
testcases/kernel/syscalls/ioctl/ioctl_pidfd06.c | 66 +++++++++++++++++++
13 files changed, 499 insertions(+), 1 deletion(-)
---
base-commit: bf14e296a9bc5f18cdc7f91d8e005297ab2ae2a2
change-id: 20250626-ioctl_pidfd_suite-322aa2375c42
Best regards,
--
Andrea Cervesato <andrea.cervesato@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 1/8] Provide pidfd parameter in tst_clone_args
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 2/8] Fallback PIDFD_GET_INFO related definitions Andrea Cervesato
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_clone.h | 1 +
lib/tst_clone.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/include/tst_clone.h b/include/tst_clone.h
index a57d761ca56dc113dde81a0ed17f15e8f2e58924..a07689c78f575ae6ca87c0952b3e48b3a626012c 100644
--- a/include/tst_clone.h
+++ b/include/tst_clone.h
@@ -12,6 +12,7 @@
/* The parts of clone3's clone_args we support */
struct tst_clone_args {
uint64_t flags;
+ uint64_t pidfd;
uint64_t exit_signal;
uint64_t cgroup;
};
diff --git a/lib/tst_clone.c b/lib/tst_clone.c
index 2aa00beb1a191d8c4a68a96ba529fc48d3777e84..8638052e2ecac2af3a290f01106e10dc8cdc62d1 100644
--- a/lib/tst_clone.c
+++ b/lib/tst_clone.c
@@ -14,6 +14,7 @@ pid_t tst_clone(const struct tst_clone_args *tst_args)
{
struct clone_args args = {
.flags = tst_args->flags,
+ .pidfd = tst_args->pidfd,
.exit_signal = tst_args->exit_signal,
.cgroup = tst_args->cgroup,
};
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 2/8] Fallback PIDFD_GET_INFO related definitions
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 1/8] Provide pidfd parameter in tst_clone_args Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 3/8] Add ioctl_pidfd01 test Andrea Cervesato
` (6 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
configure.ac | 2 ++
include/lapi/pidfd.h | 39 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index cf37c58be9ebcdc5cf78c17afb00ffb91d55304a..8ec37639c140088065390887426b1adaacd15395 100644
--- a/configure.ac
+++ b/configure.ac
@@ -261,6 +261,8 @@ AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>])
AC_CHECK_TYPES([struct mnt_id_req],,,[#include <sys/mount.h>])
AC_CHECK_TYPES([struct statmount],,,[#include <sys/mount.h>])
+AC_CHECK_TYPES([struct pidfd_info],,,[#include <sys/pidfd.h>])
+
# Tools knobs
# Bash
diff --git a/include/lapi/pidfd.h b/include/lapi/pidfd.h
index 9ca8e5aa23626646ebb2f18880abd5e52298bfc6..a3205032cf7d702fd8a014456933f8495f5984e2 100644
--- a/include/lapi/pidfd.h
+++ b/include/lapi/pidfd.h
@@ -8,14 +8,51 @@
#define LAPI_PIDFD_H__
#include <fcntl.h>
+#include <stdint.h>
+#include <sys/ioctl.h>
+
#ifdef HAVE_SYS_PIDFD_H
# include <sys/pidfd.h>
#endif
+
#include "config.h"
#include "lapi/syscalls.h"
+#ifndef HAVE_STRUCT_PIDFD_INFO
+struct pidfd_info {
+ uint64_t mask;
+ uint64_t cgroupid;
+ uint32_t pid;
+ uint32_t tgid;
+ uint32_t ppid;
+ uint32_t ruid;
+ uint32_t rgid;
+ uint32_t euid;
+ uint32_t egid;
+ uint32_t suid;
+ uint32_t sgid;
+ uint32_t fsuid;
+ uint32_t fsgid;
+ int32_t exit_code;
+ uint32_t coredump_mask;
+ uint32_t __spare1;
+};
+#endif
+
#ifndef PIDFD_NONBLOCK
-#define PIDFD_NONBLOCK O_NONBLOCK
+# define PIDFD_NONBLOCK O_NONBLOCK
+#endif
+
+#ifndef PIDFS_IOCTL_MAGIC
+# define PIDFS_IOCTL_MAGIC 0xFF
+#endif
+
+#ifndef PIDFD_GET_INFO
+# define PIDFD_GET_INFO _IOWR(PIDFS_IOCTL_MAGIC, 11, struct pidfd_info)
+#endif
+
+#ifndef PIDFD_INFO_EXIT
+# define PIDFD_INFO_EXIT (1UL << 3)
#endif
static inline void pidfd_send_signal_supported(void)
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 3/8] Add ioctl_pidfd01 test
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 1/8] Provide pidfd parameter in tst_clone_args Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 2/8] Fallback PIDFD_GET_INFO related definitions Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 4/8] Add ioctl_pidfd02 test Andrea Cervesato
` (5 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that ioctl() raises the right errors when an application provides
the wrong file descriptor.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 41 +++++++++++++++++
testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c | 58 +++++++++++++++++++++++++
4 files changed, 102 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 3531c2a3c730ac2d8e3118ea32275dc90e95c0b1..2075c5d908c04bf31fcf57bba5cdf7af3e432237 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -613,6 +613,8 @@ ioctl_ficlonerange01 ioctl_ficlonerange01
ioctl_ficlonerange02 ioctl_ficlonerange02
ioctl_fiemap01 ioctl_fiemap01
+ioctl_pidfd01 ioctl_pidfd01
+
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 d10bf0a24bbc21057f399d14aef95f814b54f58d..72d6a309ee0dcbd185a0248b9ffc79fc83b7f04f 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -30,3 +30,4 @@
/ioctl_ficlonerange01
/ioctl_ficlonerange02
/ioctl_fiemap01
+/ioctl_pidfd01
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
new file mode 100644
index 0000000000000000000000000000000000000000..8249ac753cf7fb8a3b749d55c7f0c3b30482c114
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef IOCTL_PIDFD_H
+#define IOCTL_PIDFD_H
+
+#include "tst_test.h"
+#include "lapi/pidfd.h"
+
+static inline int ioctl_pidfd_info_exit_supported(void)
+{
+ int ret = 0;
+ pid_t pid;
+ int pidfd;
+ struct pidfd_info info;
+
+ if (tst_kvercmp(6, 15, 0) >= 0)
+ return 1;
+
+ memset(&info, 0, sizeof(struct pidfd_info));
+ info.mask = PIDFD_INFO_EXIT;
+
+ pid = SAFE_FORK();
+ if (!pid)
+ exit(100);
+
+ pidfd = SAFE_PIDFD_OPEN(pid, 0);
+ SAFE_WAITPID(pid, NULL, 0);
+
+ SAFE_IOCTL(pidfd, PIDFD_GET_INFO, &info);
+ SAFE_CLOSE(pidfd);
+
+ if (info.mask & PIDFD_INFO_EXIT)
+ ret = 1;
+
+ return ret;
+}
+
+#endif
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c
new file mode 100644
index 0000000000000000000000000000000000000000..92c51c6c0d0dcbb2308c1a8d82b2a92650f3a6b3
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that ioctl() raises the right errors when an application provides
+ * the wrong file descriptor.
+ */
+
+#include "ioctl_pidfd.h"
+
+static int exp_errnos[] = {
+ EINVAL,
+ EBADF,
+ ENOTTY,
+};
+
+static struct pidfd_info *info;
+
+static void test_bad_pidfd(struct tst_fd *fd_in)
+{
+ if (fd_in->type == TST_FD_PIDFD) {
+ tst_res(TINFO, "Skipping pidfd: SUCCESS");
+ return;
+ }
+
+ TST_EXP_FAIL_ARR(ioctl(fd_in->fd, PIDFD_GET_INFO, info),
+ exp_errnos, ARRAY_SIZE(exp_errnos),
+ "ioctl(%s, PIDFD_GET_INFO, info)",
+ tst_fd_desc(fd_in));
+}
+
+static void run(void)
+{
+ TST_FD_FOREACH(fd) {
+ tst_res(TINFO, "%s -> ...", tst_fd_desc(&fd));
+ test_bad_pidfd(&fd);
+ }
+}
+
+static void setup(void)
+{
+ if (!ioctl_pidfd_info_exit_supported())
+ tst_brk(TCONF, "PIDFD_INFO_EXIT is not supported by ioctl()");
+
+ info->mask = PIDFD_INFO_EXIT;
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .forks_child = 1,
+ .bufs = (struct tst_buffers []) {
+ {&info, .size = sizeof(*info)},
+ {}
+ }
+};
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 4/8] Add ioctl_pidfd02 test
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
` (2 preceding siblings ...)
2025-07-23 14:15 ` [LTP] [PATCH v4 3/8] Add ioctl_pidfd01 test Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 5/8] Add ioctl_pidfd03 test Andrea Cervesato
` (4 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Check if the ioctl() function allows retrieval of a child's exit code
using PIDFD_INFO_EXIT from a process that can be isolated or not from
the child.
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_pidfd02.c | 85 +++++++++++++++++++++++++
3 files changed, 87 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 2075c5d908c04bf31fcf57bba5cdf7af3e432237..fbb38b1a52ed9d7f6634336d83c226b5cce522e8 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -614,6 +614,7 @@ ioctl_ficlonerange02 ioctl_ficlonerange02
ioctl_fiemap01 ioctl_fiemap01
ioctl_pidfd01 ioctl_pidfd01
+ioctl_pidfd02 ioctl_pidfd02
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 72d6a309ee0dcbd185a0248b9ffc79fc83b7f04f..a984744a67173b70872446823a6fdeb6a44fe2c8 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -31,3 +31,4 @@
/ioctl_ficlonerange02
/ioctl_fiemap01
/ioctl_pidfd01
+/ioctl_pidfd02
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd02.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd02.c
new file mode 100644
index 0000000000000000000000000000000000000000..858ec461af373667c1fea1a16f7cb5e4f516b758
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd02.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Check if the ioctl() function allows retrieval of a child's exit code
+ * using PIDFD_INFO_EXIT from a process that can be isolated or not from the
+ * child.
+ */
+
+#include "ioctl_pidfd.h"
+#include "lapi/sched.h"
+
+static struct tst_clone_args *args;
+static struct pidfd_info *info0, *info1;
+
+static void run(unsigned int isolate)
+{
+ int status;
+ int pidfd = 0;
+ pid_t pid_child;
+
+ memset(args, 0, sizeof(struct tst_clone_args));
+ memset(info0, 0, sizeof(struct pidfd_info));
+ memset(info1, 0, sizeof(struct pidfd_info));
+
+ if (isolate) {
+ args->flags = CLONE_PIDFD | CLONE_NEWUSER | CLONE_NEWPID;
+ args->pidfd = (uint64_t)&pidfd;
+ args->exit_signal = SIGCHLD;
+
+ pid_child = SAFE_CLONE(args);
+ } else {
+ pid_child = SAFE_FORK();
+ }
+
+ if (!pid_child) {
+ TST_CHECKPOINT_WAIT(0);
+ exit(100);
+ }
+
+ if (!isolate)
+ pidfd = SAFE_PIDFD_OPEN(pid_child, 0);
+
+ /* child is not reaped and ioctl() won't provide any exit status info */
+ info0->mask = PIDFD_INFO_EXIT;
+ SAFE_IOCTL(pidfd, PIDFD_GET_INFO, info0);
+ TST_EXP_EQ_LI(info0->mask & PIDFD_INFO_EXIT, 0);
+ TST_EXP_EQ_LI(info0->exit_code, 0);
+
+ TST_CHECKPOINT_WAKE(0);
+
+ SAFE_WAITPID(pid_child, &status, 0);
+
+ /* child is now reaped and ioctl() will provide the exit status */
+ info1->mask = PIDFD_INFO_EXIT;
+ SAFE_IOCTL(pidfd, PIDFD_GET_INFO, info1);
+ SAFE_CLOSE(pidfd);
+
+ TST_EXP_EQ_LI(info1->mask & PIDFD_INFO_EXIT, PIDFD_INFO_EXIT);
+ TST_EXP_EQ_LI(info1->exit_code, status);
+
+ TST_EXP_EQ_LI(WEXITSTATUS(info1->exit_code), 100);
+}
+
+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 = run,
+ .setup = setup,
+ .tcnt = 2,
+ .forks_child = 1,
+ .needs_checkpoints = 1,
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(*args)},
+ {&info0, .size = sizeof(*info0)},
+ {&info1, .size = sizeof(*info1)},
+ {}
+ }
+};
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 5/8] Add ioctl_pidfd03 test
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
` (3 preceding siblings ...)
2025-07-23 14:15 ` [LTP] [PATCH v4 4/8] Add ioctl_pidfd02 test Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 6/8] Add ioctl_pidfd04 test Andrea Cervesato
` (3 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
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`.
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_pidfd03.c | 64 +++++++++++++++++++++++++
3 files changed, 66 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index fbb38b1a52ed9d7f6634336d83c226b5cce522e8..7e019675216a59919b137b84b023ebb2969efcdb 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -615,6 +615,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 a984744a67173b70872446823a6fdeb6a44fe2c8..393ec47fecaed101f413284f28646aeff76cc30b 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -32,3 +32,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..eca4b90f4b5fb9f209c30752ab583a20a31518bc
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd03.c
@@ -0,0 +1,64 @@
+// 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 "ioctl_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);
+
+ info->mask = 0;
+
+ /* child is not reaped, so ioctl() will pass */
+ SAFE_IOCTL(pidfd, PIDFD_GET_INFO, info);
+ TST_EXP_EQ_LI(info->mask & PIDFD_INFO_EXIT, 0);
+
+ SAFE_WAITPID(pid_child, &status, 0);
+
+ /* child is now reaped, so we get ESRCH */
+ TST_EXP_FAIL(ioctl(pidfd, PIDFD_GET_INFO, info), ESRCH);
+ TST_EXP_EQ_LI(info->mask & PIDFD_INFO_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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 6/8] Add ioctl_pidfd04 test
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
` (4 preceding siblings ...)
2025-07-23 14:15 ` [LTP] [PATCH v4 5/8] Add ioctl_pidfd03 test Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 7/8] Add ioctl_pidfd05 test Andrea Cervesato
` (2 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that ioctl() permits to obtain the exit code of an isolated
signaled child via PIDFD_INFO_EXIT from within a process.
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_pidfd04.c | 71 +++++++++++++++++++++++++
3 files changed, 73 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 7e019675216a59919b137b84b023ebb2969efcdb..3d0789bee7d4723f6af549eace1e14e358e17220 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -616,6 +616,7 @@ ioctl_fiemap01 ioctl_fiemap01
ioctl_pidfd01 ioctl_pidfd01
ioctl_pidfd02 ioctl_pidfd02
ioctl_pidfd03 ioctl_pidfd03
+ioctl_pidfd04 ioctl_pidfd04
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 393ec47fecaed101f413284f28646aeff76cc30b..b92cb5d33fe05652874c5ba4027c8521528f8ecc 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -33,3 +33,4 @@
/ioctl_pidfd01
/ioctl_pidfd02
/ioctl_pidfd03
+/ioctl_pidfd04
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c
new file mode 100644
index 0000000000000000000000000000000000000000..e5f582414acce8158aaf487d38b74f137f8f3088
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that ioctl() permits to obtain the exit code of an isolated signaled
+ * child via PIDFD_INFO_EXIT from within a process.
+ */
+
+#include "ioctl_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));
+ 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) {
+ TST_CHECKPOINT_WAKE_AND_WAIT(0);
+ exit(1);
+ }
+
+ TST_CHECKPOINT_WAIT(0);
+
+ SAFE_KILL(pid_child, SIGKILL);
+ SAFE_WAITPID(pid_child, &status, 0);
+
+ SAFE_IOCTL(pidfd, PIDFD_GET_INFO, info);
+ SAFE_CLOSE(pidfd);
+
+ TST_EXP_EQ_LI(info->mask & PIDFD_INFO_EXIT, PIDFD_INFO_EXIT);
+ TST_EXP_EQ_LI(WIFSIGNALED(info->exit_code), WIFSIGNALED(status));
+ TST_EXP_EQ_LI(WEXITSTATUS(info->exit_code), WEXITSTATUS(status));
+ TST_EXP_EQ_LI(WTERMSIG(info->exit_code), WTERMSIG(status));
+
+ TST_EXP_EXPR(WIFSIGNALED(info->exit_code) &&
+ WTERMSIG(info->exit_code) == SIGKILL);
+}
+
+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,
+ .needs_checkpoints = 1,
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(*args)},
+ {&info, .size = sizeof(*info)},
+ {}
+ }
+};
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 7/8] Add ioctl_pidfd05 test
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
` (5 preceding siblings ...)
2025-07-23 14:15 ` [LTP] [PATCH v4 6/8] Add ioctl_pidfd04 test Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 8/8] Add ioctl_pidfd06 test Andrea Cervesato
2025-07-23 14:21 ` [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Cyril Hrubis
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that ioctl() raises an EINVAL error when PIDFD_GET_INFO
is used. This happens when:
- info parameter is NULL
- info parameter is providing the wrong size
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_pidfd05.c | 59 +++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 3d0789bee7d4723f6af549eace1e14e358e17220..118a863ba8d86e1d8a7d3cff3e7fa09d0e137413 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -617,6 +617,7 @@ ioctl_pidfd01 ioctl_pidfd01
ioctl_pidfd02 ioctl_pidfd02
ioctl_pidfd03 ioctl_pidfd03
ioctl_pidfd04 ioctl_pidfd04
+ioctl_pidfd05 ioctl_pidfd05
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 b92cb5d33fe05652874c5ba4027c8521528f8ecc..09963c3896fb124ef1149bbd743537dd691400ee 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -34,3 +34,4 @@
/ioctl_pidfd02
/ioctl_pidfd03
/ioctl_pidfd04
+/ioctl_pidfd05
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
new file mode 100644
index 0000000000000000000000000000000000000000..c379717b3bea70bcf11195abf967b555914a64cd
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that ioctl() raises an EINVAL error when PIDFD_GET_INFO is used. This
+ * happens when:
+ *
+ * - info parameter is NULL
+ * - info parameter is providing the wrong size
+ */
+
+#include "tst_test.h"
+#include "lapi/pidfd.h"
+#include "lapi/sched.h"
+#include "lapi/ioctl.h"
+
+struct pidfd_info_invalid {
+ uint32_t dummy;
+};
+
+#define PIDFD_GET_INFO_SHORT _IOWR(PIDFS_IOCTL_MAGIC, 11, struct pidfd_info_invalid)
+
+static struct tst_clone_args *args;
+static struct pidfd_info_invalid *info_invalid;
+
+static void run(void)
+{
+ int pidfd = 0;
+ pid_t pid_child;
+
+ memset(args, 0, sizeof(struct tst_clone_args));
+
+ info_invalid->dummy = 1;
+
+ 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(0);
+
+ TST_EXP_FAIL(ioctl(pidfd, PIDFD_GET_INFO, NULL), EINVAL);
+ TST_EXP_FAIL(ioctl(pidfd, PIDFD_GET_INFO_SHORT, info_invalid), EINVAL);
+
+ SAFE_CLOSE(pidfd);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .forks_child = 1,
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(*args)},
+ {&info_invalid, .size = sizeof(*info_invalid)},
+ {}
+ }
+};
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH v4 8/8] Add ioctl_pidfd06 test
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
` (6 preceding siblings ...)
2025-07-23 14:15 ` [LTP] [PATCH v4 7/8] Add ioctl_pidfd05 test Andrea Cervesato
@ 2025-07-23 14:15 ` Andrea Cervesato
2025-07-23 14:21 ` [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Cyril Hrubis
8 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato @ 2025-07-23 14:15 UTC (permalink / raw)
To: ltp
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
` (7 preceding siblings ...)
2025-07-23 14:15 ` [LTP] [PATCH v4 8/8] Add ioctl_pidfd06 test Andrea Cervesato
@ 2025-07-23 14:21 ` Cyril Hrubis
2025-07-23 14:55 ` Andrea Cervesato via ltp
8 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2025-07-23 14:21 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
I guess that this can go in as long as the CI turns green.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite
2025-07-23 14:21 ` [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Cyril Hrubis
@ 2025-07-23 14:55 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 11+ messages in thread
From: Andrea Cervesato via ltp @ 2025-07-23 14:55 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
Merged thanks!
- Andrea
On 7/23/25 4:21 PM, Cyril Hrubis wrote:
> Hi!
> I guess that this can go in as long as the CI turns green.
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-07-23 14:56 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 14:15 [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 1/8] Provide pidfd parameter in tst_clone_args Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 2/8] Fallback PIDFD_GET_INFO related definitions Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 3/8] Add ioctl_pidfd01 test Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 4/8] Add ioctl_pidfd02 test Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 5/8] Add ioctl_pidfd03 test Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 6/8] Add ioctl_pidfd04 test Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 7/8] Add ioctl_pidfd05 test Andrea Cervesato
2025-07-23 14:15 ` [LTP] [PATCH v4 8/8] Add ioctl_pidfd06 test Andrea Cervesato
2025-07-23 14:21 ` [LTP] [PATCH v4 0/8] ioctl_pidfd testing suite Cyril Hrubis
2025-07-23 14:55 ` Andrea Cervesato via ltp
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.