linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christian Brauner <brauner@kernel.org>,
	Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>,
	Aleksa Sarai <cyphar@cyphar.com>,
	Seth Forshee <sforshee@kernel.org>,
	linux-fsdevel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] file: always lock position
Date: Sat, 2 Sep 2023 05:44:11 +0100	[thread overview]
Message-ID: <20230902044411.GI3390869@ZenIV> (raw)
In-Reply-To: <CAHk-=whtPzpL1D-VMHU9M6jbwSqFuXsc5u_6ePanVkBCNAYjMQ@mail.gmail.com>

On Mon, Jul 24, 2023 at 09:51:05AM -0700, Linus Torvalds wrote:
> On Mon, 24 Jul 2023 at 09:36, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > There are magic rules with "total_refs == inflight_refs", and that
> > total_refs thing is very much the file count, ie
> >
> >                 total_refs = file_count(u->sk.sk_socket->file);
> >
> > where we had some nasty bugs with files coming back to life.
> 
> Ok, I don't think this is an issue here. It really is that "only
> in-flight refs remaining" that is a special case, and even
> pidfd_getfd() shouldn't be able to change that.
> 
> But the magic code is all in fget_task(), and those need to be checked.
> 
> You can see how proc does things properly: it does do "fget_task()",
> but then it only uses it to copy the path part, and just does fput()
> afterwards.
> 
> The bpf code does something like that too, and seems ok (ie it gets
> the file in order to copy data from it, not to install it).

Aside of fget_task() use, it has this:
        rcu_read_lock();
        for (;; curr_fd++) {
                struct file *f;
                f = task_lookup_next_fd_rcu(curr_task, &curr_fd);
                if (!f)
                        break;
                if (!get_file_rcu(f))
                        continue;

                /* set info->fd */
                info->fd = curr_fd;
                rcu_read_unlock();
                return f;
        }

curr_task is not cached current here - it can be an arbitrary thread.
And what we do to the file reference we get here is

        ctx.meta = &meta;
        ctx.task = info->task;
        ctx.fd = info->fd;
        ctx.file = file;
        return bpf_iter_run_prog(prog, &ctx);

I think it can't be used to shove it into any descriptor table, but
then there's forming an SCM_RIGHTS datagram and sending it, etc. -
it might be worth looking into.

  reply	other threads:[~2023-09-02  4:44 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
2023-07-24 16:36     ` Linus Torvalds
2023-07-24 16:51       ` Linus Torvalds
2023-09-02  4:44         ` Al Viro [this message]
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=20230902044411.GI3390869@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --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 \
    /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).