From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3 3/8] Add ioctl_pidfd01 test
Date: Wed, 9 Jul 2025 11:16:50 +0200 [thread overview]
Message-ID: <aG4zgpB-4WDW5fbj@yuki.lan> (raw)
In-Reply-To: <20250707-ioctl_pidfd_suite-v3-3-22ba4d15ee02@suse.com>
Hi!
> 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 | 38 ++++++++++++++++
> testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c | 58 +++++++++++++++++++++++++
> 4 files changed, 99 insertions(+)
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 582422ac9ca8ccae598c626a11cf6ee7c30f0e3a..7f6312ce5fa241a778d8dda7f8ee9edd0a8800e6 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -612,6 +612,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 53a82bb5770ba196811965150fd262ec5d4a6e01..aa952c1a7bae0ae2dbb04de0595f10d508b6759a 100644
> --- a/testcases/kernel/syscalls/ioctl/.gitignore
> +++ b/testcases/kernel/syscalls/ioctl/.gitignore
> @@ -29,3 +29,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..1a87d90982c353d8ca75140e405b42a24be4408d
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> @@ -0,0 +1,38 @@
> +/* 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_supported(void)
This should be named ioctl_pidfd_info_exit_supported() since we are
checking specially for the IOCTL_INFO_EXIT flag.
> +{
> + int ret = 0;
> + pid_t pid;
> + int pidfd;
> + struct pidfd_info info;
We have to assume the support is in if the kernel is new enough,
otherwise we will not detect when the code in kernel breaks when it's
suposed to work:
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..d9231e79b15c0866bd4c965634f6b01c157da1ce
> --- /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_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.0
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-07-09 9:16 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 17:05 [LTP] [PATCH v3 0/8] ioctl_pidfd testing suite Andrea Cervesato
2025-07-07 17:05 ` [LTP] [PATCH v3 1/8] Provide pidfd parameter in tst_clone_args Andrea Cervesato
2025-07-07 17:05 ` [LTP] [PATCH v3 2/8] Fallback PIDFD_GET_INFO related definitions Andrea Cervesato
2025-07-07 17:05 ` [LTP] [PATCH v3 3/8] Add ioctl_pidfd01 test Andrea Cervesato
2025-07-09 9:16 ` Cyril Hrubis [this message]
2025-07-07 17:05 ` [LTP] [PATCH v3 4/8] Add ioctl_pidfd02 test Andrea Cervesato
2025-07-09 9:46 ` Cyril Hrubis
2025-07-07 17:05 ` [LTP] [PATCH v3 5/8] Add ioctl_pidfd03 test Andrea Cervesato
2025-07-09 10:22 ` Cyril Hrubis
2025-07-07 17:05 ` [LTP] [PATCH v3 6/8] Add ioctl_pidfd04 test Andrea Cervesato
2025-07-09 10:26 ` Cyril Hrubis
2025-07-07 17:05 ` [LTP] [PATCH v3 7/8] Add ioctl_pidfd05 test Andrea Cervesato
2025-07-09 12:01 ` Cyril Hrubis
2025-07-07 17:05 ` [LTP] [PATCH v3 8/8] Add ioctl_pidfd06 test Andrea Cervesato
2025-07-23 13:08 ` Cyril Hrubis
2025-07-23 13:59 ` Andrea Cervesato via ltp
2025-07-23 14:03 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aG4zgpB-4WDW5fbj@yuki.lan \
--to=chrubis@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox