From: Josh Triplett <[email protected]>
To: [email protected], [email protected],
[email protected], [email protected]
Cc: Alexander Viro <[email protected]>,
Arnd Bergmann <[email protected]>, Jens Axboe <[email protected]>,
Aleksa Sarai <[email protected]>
Subject: [PATCH v4 3/3] fs: pipe2: Support O_SPECIFIC_FD
Date: Mon, 13 Apr 2020 19:16:01 -0700 [thread overview]
Message-ID: <2993aae005b70f51636553d1522baa063ea01a26.1586830316.git.josh@joshtriplett.org> (raw)
In-Reply-To: <[email protected]>
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 <[email protected]>
---
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.0
prev parent reply other threads:[~2020-04-14 2:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-14 2:14 [PATCH v4 0/3] Support userspace-selected fds Josh Triplett
2020-04-14 2:15 ` [PATCH v4 1/3] fs: Support setting a minimum fd for "lowest available fd" allocation Josh Triplett
2020-04-14 2:15 ` [PATCH v4 2/3] fs: openat2: Extend open_how to allow userspace-selected fds Josh Triplett
2020-04-19 10:44 ` Aleksa Sarai
2020-04-19 21:18 ` David Laight
2020-04-19 22:22 ` Jens Axboe
2020-04-20 2:06 ` Aleksa Sarai
2020-04-20 21:14 ` Josh Triplett
[not found] ` <20200427135210.GB5770@shao2-debian>
2020-04-27 14:27 ` [LTP] [fs] ce436509a8: ltp.openat203.fail Cyril Hrubis
2020-04-28 0:51 ` Aleksa Sarai
2020-04-28 15:30 ` Cyril Hrubis
2020-04-28 15:35 ` Aleksa Sarai
2020-04-14 2:16 ` Josh Triplett [this message]
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=2993aae005b70f51636553d1522baa063ea01a26.1586830316.git.josh@joshtriplett.org \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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