linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: Mark Wielaard <mark@klomp.org>,
	io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, mtk.manpages@gmail.com,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Arnd Bergmann <arnd@arndb.de>, Jens Axboe <axboe@kernel.dk>,
	Aleksa Sarai <cyphar@cyphar.com>,
	linux-man@vger.kernel.org
Subject: Re: [PATCH v5 3/3] fs: pipe2: Support O_SPECIFIC_FD
Date: Wed, 22 Apr 2020 17:44:07 -0700	[thread overview]
Message-ID: <20200423004407.GB161058@localhost> (raw)
In-Reply-To: <877dy7ikyh.fsf@mid.deneb.enyo.de>

On Wed, Apr 22, 2020 at 05:44:38PM +0200, Florian Weimer wrote:
> * Josh Triplett:
> > 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@joshtriplett.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)))) {
> 
> Mark, I think this will need (or at least benefit from) some valgrind
> changes.

Yes, this makes pipe2 read the memory of its first argument from
userspace, if and only if its second argument contains the O_SPECIFIC_FD
flag.

- Josh Triplett

  reply	other threads:[~2020-04-23  0:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22  5:19 [PATCH v5 0/3] Support userspace-selected fds Josh Triplett
2020-04-22  5:19 ` [PATCH v5 1/3] fs: Support setting a minimum fd for "lowest available fd" allocation Josh Triplett
2020-04-22  6:06   ` Michael Kerrisk (man-pages)
2020-04-23  1:12   ` Dmitry V. Levin
2020-04-23  4:51     ` Josh Triplett
2020-04-23  9:24   ` Arnd Bergmann
2020-04-22  5:20 ` [PATCH v5 2/3] fs: openat2: Extend open_how to allow userspace-selected fds Josh Triplett
2020-04-22  6:06   ` Michael Kerrisk (man-pages)
2020-04-22  7:55     ` Miklos Szeredi
2020-04-23  0:48       ` Josh Triplett
2020-04-23  4:24         ` Miklos Szeredi
2020-04-23  4:42           ` Josh Triplett
2020-04-23  6:04             ` Miklos Szeredi
2020-04-23  7:33               ` Josh Triplett
2020-04-23  7:45                 ` Miklos Szeredi
2020-04-23  7:57                   ` Miklos Szeredi
2020-04-23  9:20                     ` Miklos Szeredi
2020-04-23  9:46                       ` Miklos Szeredi
2020-04-23  8:06                   ` Josh Triplett
2020-04-22  5:20 ` [PATCH v5 3/3] fs: pipe2: Support O_SPECIFIC_FD Josh Triplett
2020-04-22  6:06   ` Michael Kerrisk (man-pages)
2020-04-22 15:44   ` Florian Weimer
2020-04-23  0:44     ` Josh Triplett [this message]
2020-04-22  6:05 ` [PATCH v5 0/3] Support userspace-selected fds Michael Kerrisk (man-pages)

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=20200423004407.GB161058@localhost \
    --to=josh@joshtriplett.org \
    --cc=arnd@arndb.de \
    --cc=axboe@kernel.dk \
    --cc=cyphar@cyphar.com \
    --cc=fw@deneb.enyo.de \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mark@klomp.org \
    --cc=mtk.manpages@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).