From: Al Viro <viro@zeniv.linux.org.uk>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>,
jack@suse.cz, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [MEH PATCH] fs: sort out a stale comment about races between fd alloc and dup2
Date: Tue, 10 Dec 2024 18:15:39 +0000 [thread overview]
Message-ID: <20241210181539.GE3387508@ZenIV> (raw)
In-Reply-To: <CAGudoHH76NYH2O-TQw6ZPjZF5ht76HgiKtsG=owYdLZarGRwcA@mail.gmail.com>
On Tue, Dec 10, 2024 at 05:48:40AM +0100, Mateusz Guzik wrote:
> Oh huh. I had seen that code before, did not mentally register there
> may be repeat file alloc/free calls due to repeat path_openat.
>
> Indeed it would be nice if someone(tm) sorted it out, but I don't see
> how this has any relation to installing the file early and thus having
> fget worry about it.
Other than the former being an obvious prereq for the latter? Not much...
> Suppose the "embryo"/"larval" file pointer is to be installed early
> and populated later. I don't see a benefit but do see a downside: this
> requires protection against close() on the fd (on top of dup2 needed
> now).
> The options that I see are:
> - install the file with a refcount of 2, let dup2/close whack it, do a
> fput in open to bring back to 1 or get rid of it if it raced (yuck)
> (freebsd is doing this)
> - dup2 is already special casing to not mess with it, add that to
> close as well (also yuck imo)
As a possibility (again, I'm not sold on the benefits of that scheme,
just looking into feasibility):
dup2() when evicting an embryo:
mark it evicted
remove from descriptor table
do nothing to refcount (in effect, transfer it to open())
then proceed as if it hadn't been there
[== pretend that dup2() always loses the race]
close() when running into an embryo
return -EBADF
[== pretend that close() always loses the race]
open() when it's done setting file up:
if opening failed
if not marked evicted
remove from descriptor table
fput()
return whatever error we've got
else
if marked evicted
fput()
return the descriptor
[== pretend that open() always wins the race]
"open" in the above stands for everything that opens a descriptor - socket(2),
pipe(2), eventfd(2), whatever.
> >From userspace side the only programs which can ever see EBUSY are
> buggy or trying to screw the kernel, so not a concern on that front.
Agreed. I'm not saying we should go that way.
prev parent reply other threads:[~2024-12-10 18:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-05 15:47 [MEH PATCH] fs: sort out a stale comment about races between fd alloc and dup2 Mateusz Guzik
2024-12-06 12:13 ` Christian Brauner
2024-12-09 19:56 ` Al Viro
2024-12-10 4:48 ` Mateusz Guzik
2024-12-10 10:18 ` Christian Brauner
2024-12-10 18:15 ` Al Viro [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=20241210181539.GE3387508@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
/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