From: Al Viro <viro@zeniv.linux.org.uk>
To: Jens Axboe <axboe@kernel.dk>
Cc: Max Kellermann <mk@cm4all.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] fs/io_uring: fix O_PATH fds in openat, openat2, statx
Date: Fri, 8 May 2020 00:31:32 +0100 [thread overview]
Message-ID: <20200507233132.GJ23230@ZenIV.linux.org.uk> (raw)
In-Reply-To: <e16125f2-c3ec-f029-c607-19bede54fa17@kernel.dk>
On Thu, May 07, 2020 at 05:03:17PM -0600, Jens Axboe wrote:
> On 5/7/20 4:44 PM, Al Viro wrote:
> > On Thu, May 07, 2020 at 04:25:24PM -0600, Jens Axboe wrote:
> >
> >> static int io_close(struct io_kiocb *req, bool force_nonblock)
> >> {
> >> + struct files_struct *files = current->files;
> >> int ret;
> >>
> >> req->close.put_file = NULL;
> >> - ret = __close_fd_get_file(req->close.fd, &req->close.put_file);
> >> + spin_lock(&files->file_lock);
> >> + if (req->file->f_op == &io_uring_fops ||
> >> + req->close.fd == req->ctx->ring_fd) {
> >> + spin_unlock(&files->file_lock);
> >> + return -EBADF;
> >> + }
> >> +
> >> + ret = __close_fd_get_file_locked(files, req->close.fd,
> >> + &req->close.put_file);
> >
> > Pointless. By that point req->file might have nothing in common with
> > anything in any descriptor table.
>
> How about the below then? Stop using req->file, defer the lookup until
> we're in the handler instead. Not sure the 'fd' check makes sense
> at this point, but at least we should be consistent in terms of
> once we lookup the file and check the f_op.
Actually, what _is_ the reason for that check? Note, BTW, that if the
file in question happens to be an AF_UNIX socket, closing it will
close all references held in SCM_RIGHTS datagrams sitting in its queue,
which might very well include io_uring files.
IOW, if tries to avoid something really unpleasant, it's not enough.
And if it doesn't, then what is it for?
next prev parent reply other threads:[~2020-05-07 23:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-07 18:57 [PATCH] fs/io_uring: fix O_PATH fds in openat, openat2, statx Max Kellermann
2020-05-07 18:58 ` Jens Axboe
2020-05-07 19:01 ` Max Kellermann
2020-05-07 19:01 ` Al Viro
2020-05-07 19:05 ` Max Kellermann
2020-05-07 19:05 ` Jens Axboe
2020-05-07 19:12 ` Max Kellermann
2020-05-07 19:29 ` Al Viro
2020-05-07 19:37 ` Max Kellermann
2020-05-07 20:53 ` Jens Axboe
2020-05-07 22:06 ` Al Viro
2020-05-07 22:25 ` Jens Axboe
2020-05-07 22:44 ` Al Viro
2020-05-07 23:03 ` Jens Axboe
2020-05-07 23:31 ` Al Viro [this message]
2020-05-08 2:28 ` Jens Axboe
2020-05-08 2:53 ` Jens Axboe
[not found] ` <20200508152918.12340-1-hdanton@sina.com>
2020-05-08 15:33 ` Jens Axboe
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=20200507233132.GJ23230@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=axboe@kernel.dk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mk@cm4all.com \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.