From: Christian Brauner <brauner@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>,
Aleksa Sarai <cyphar@cyphar.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Seth Forshee <sforshee@kernel.org>,
linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] file: always lock position
Date: Mon, 24 Jul 2023 18:19:10 +0200 [thread overview]
Message-ID: <20230724-scheren-absegnen-8c807c760ba1@brauner> (raw)
In-Reply-To: <CAHk-=whfJhag+iEscftpVq=dHTeL7rQopCvH+Pcs8vJHCGNvXQ@mail.gmail.com>
On Mon, Jul 24, 2023 at 08:53:32AM -0700, Linus Torvalds wrote:
> So this was a case of "too much explanations make the explanation much
> harder to follow".
>
> I tend to enjoy your pull request explanations, but this one was just
> *way* too much.
>
> Please try to make the point you are making a bit more salient, so
> that it's a lot easier to follow.
Sure. The thing is though that I'm not doing this because it's fun to
write a lot of text. It's simply because I want to remember how I
arrived at that conclusion. I can keep this shorter for sure. The
problem is often just what can I assume the reader knows and what they
don't.
>
> On Mon, 24 Jul 2023 at 08:01, Christian Brauner <brauner@kernel.org> wrote:
> >
> > [..] the
> > file_count(file) greater than one optimization was already broken and
> > that concurrent read/write/getdents/seek calls are possible in the
> > regular system call api.
> >
> > The pidfd_getfd() system call allows a caller with ptrace_may_access()
> > abilities on another process to steal a file descriptor from this
> > process.
>
> I think the above is all you need to actually explain the problem and
> boil down the cause of the bug, and it means that the reader doesn't
> have to wade through a lot of other verbiage to figure it out.
>
> > if (file && (file->f_mode & FMODE_ATOMIC_POS)) {
> > - if (file_count(file) > 1) {
> > - v |= FDPUT_POS_UNLOCK;
> > - mutex_lock(&file->f_pos_lock);
> > - }
> > + v |= FDPUT_POS_UNLOCK;
> > + mutex_lock(&file->f_pos_lock);
> > }
>
> Ho humm. The patch is obviously correct.
>
> At the same time this is actually very annoying, because I played this
> very issue with the plain /proc/<pid>/fd/<xyz> interface long long
> ago, where it would just re-use the 'struct file' directly, and it was
> such a sh*t-show that I know it's much better to actually open a new
> file descriptor.
>
> I'm not sure that "share actual 'struct file' ever was part of a
> mainline kernel". I remember having it, but it was a "last century"
> kind of thing.
>
> The /proc interface hack was actually somewhat useful exactly because
> you'd see the file position change, but it really caused problems.
>
> The fact that pidfd_getfd() re-introduced that garbage and I never
> realized this just annoys me no end.
SCM_RIGHTS which have existed since 2.1 or sm allow you to do the same
thing just cooperatively. If you receive a bunch of fds from another
task including sockets and so on they refer to the same struct file.
In recent kernels we also have the seccomp notifier addfd ioctl which
let's you add a file descriptor into another process which can also be
used to create shared struct files.
next prev parent reply other threads:[~2023-07-24 16:19 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-24 15:00 [PATCH] file: always lock position Christian Brauner
2023-07-24 15:53 ` Linus Torvalds
2023-07-24 16:19 ` Christian Brauner [this message]
2023-07-24 16:36 ` Linus Torvalds
2023-07-24 16:51 ` Linus Torvalds
2023-09-02 4:44 ` Al Viro
2023-07-24 17:23 ` Christian Brauner
2023-07-24 17:34 ` Linus Torvalds
2023-07-24 17:46 ` Christian Brauner
2023-07-24 18:01 ` Linus Torvalds
2023-07-24 18:05 ` Jens Axboe
2023-07-24 18:27 ` Linus Torvalds
2023-07-24 18:48 ` Christian Brauner
2023-07-24 22:25 ` Linus Torvalds
2023-07-24 22:56 ` Jens Axboe
2023-07-25 18:30 ` Linus Torvalds
2023-07-25 20:41 ` Jens Axboe
2023-07-25 20:51 ` Linus Torvalds
2023-07-25 20:58 ` Jens Axboe
2023-07-26 8:36 ` Christian Brauner
2023-07-26 10:31 ` David Laight
2023-07-26 12:53 ` Christian Brauner
2023-07-26 8:07 ` Christian Brauner
2023-07-24 16:46 ` Christian Brauner
2023-07-24 16:59 ` Linus Torvalds
2023-07-24 17:18 ` Linus Torvalds
2023-08-03 9:53 ` Mateusz Guzik
2023-08-03 14:15 ` Christian Brauner
2023-08-03 15:17 ` Mateusz Guzik
2023-08-03 15:18 ` Mateusz Guzik
2023-08-03 15:45 ` Linus Torvalds
2023-08-03 17:54 ` Mateusz Guzik
2023-08-03 18:02 ` Christian Brauner
2023-08-03 18:35 ` Linus Torvalds
2023-08-04 13:43 ` Christian Brauner
2023-08-04 13:59 ` Christoph Hellwig
2023-09-02 3:43 ` Al Viro
[not found] <20230804-turnverein-helfer-ef07a4d7bbec@brauner>
2023-08-05 11:46 ` Christian Brauner
2023-08-05 18:47 ` Linus Torvalds
2023-08-05 19:46 ` Linus Torvalds
2023-08-06 6:10 ` Christian Brauner
2023-08-06 13:25 ` Christian Brauner
2023-08-06 17:48 ` Linus Torvalds
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=20230724-scheren-absegnen-8c807c760ba1@brauner \
--to=brauner@kernel.org \
--cc=axboe@kernel.dk \
--cc=cyphar@cyphar.com \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sforshee@kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--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).