[LTP] [PATCH v2 7/8] Add ioctl_pidfd05 test

Andrea Cervesato andrea.cervesato@suse.de
Fri Jul 4 13:30:45 CEST 2025


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

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 | 58 +++++++++++++++++++++++++
 3 files changed, 60 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index a28f4857ffccc070665361f2741ddbaa480d1153..91908312df82f677e6fa711653b56de8e5ccf016 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -616,6 +616,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 b6203828f324647ccf5d809e80e2ada515817006..4658173eac337a8e9cae1844340f9ecc0e55218f 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -33,3 +33,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..c5bec82f12a067283c7ea286f36b6f651c8f1ffd
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.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 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);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.min_kver = "6.15",
+	.bufs = (struct tst_buffers []) {
+		{&args, .size = sizeof(*args)},
+		{&info_invalid, .size = sizeof(*info_invalid)},
+		{}
+	}
+};

-- 
2.50.0



More information about the ltp mailing list