[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKgNAki3uoai+FWTQv6+DdQjCF3nc+7HoUZrLSC5dEf3ob9uRA@mail.gmail.com>
Date: Wed, 22 Apr 2020 08:06:30 +0200
From: "Michael Kerrisk (man-pages)" <mtk.manpages@...il.com>
To: Josh Triplett <josh@...htriplett.org>
Cc: io-uring@...r.kernel.org,
"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
lkml <linux-kernel@...r.kernel.org>,
Alexander Viro <viro@...iv.linux.org.uk>,
Arnd Bergmann <arnd@...db.de>, Jens Axboe <axboe@...nel.dk>,
Aleksa Sarai <cyphar@...har.com>,
linux-man <linux-man@...r.kernel.org>,
Linux API <linux-api@...r.kernel.org>
Subject: Re: [PATCH v5 3/3] fs: pipe2: Support O_SPECIFIC_FD
[CC += linux-api]
On Wed, 22 Apr 2020 at 07:20, Josh Triplett <josh@...htriplett.org> wrote:
>
> This allows the caller of pipe2 to specify one or both file descriptors
> rather than having them automatically use the lowest available file
> descriptor. The caller can specify either file descriptor as -1 to
> allow that file descriptor to use the lowest available.
>
> Signed-off-by: Josh Triplett <josh@...htriplett.org>
> ---
> fs/pipe.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/fs/pipe.c b/fs/pipe.c
> index 16fb72e9abf7..4681a0d1d587 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -936,19 +936,19 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags)
> int error;
> int fdw, fdr;
>
> - if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT))
> + if (flags & ~(O_CLOEXEC | O_NONBLOCK | O_DIRECT | O_SPECIFIC_FD))
> return -EINVAL;
>
> error = create_pipe_files(files, flags);
> if (error)
> return error;
>
> - error = get_unused_fd_flags(flags);
> + error = get_specific_unused_fd_flags(fd[0], flags);
> if (error < 0)
> goto err_read_pipe;
> fdr = error;
>
> - error = get_unused_fd_flags(flags);
> + error = get_specific_unused_fd_flags(fd[1], flags);
> if (error < 0)
> goto err_fdr;
> fdw = error;
> @@ -969,7 +969,11 @@ static int __do_pipe_flags(int *fd, struct file **files, int flags)
> int do_pipe_flags(int *fd, int flags)
> {
> struct file *files[2];
> - int error = __do_pipe_flags(fd, files, flags);
> + int error;
> +
> + if (flags & O_SPECIFIC_FD)
> + return -EINVAL;
> + error = __do_pipe_flags(fd, files, flags);
> if (!error) {
> fd_install(fd[0], files[0]);
> fd_install(fd[1], files[1]);
> @@ -987,6 +991,10 @@ static int do_pipe2(int __user *fildes, int flags)
> int fd[2];
> int error;
>
> + if (flags & O_SPECIFIC_FD)
> + if (copy_from_user(fd, fildes, sizeof(fd)))
> + return -EFAULT;
> +
> error = __do_pipe_flags(fd, files, flags);
> if (!error) {
> if (unlikely(copy_to_user(fildes, fd, sizeof(fd)))) {
> --
> 2.26.2
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Powered by blists - more mailing lists