All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
	shankarapailoor <shankarapailoor@gmail.com>,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
	Lorenzo Colitti <lorenzo@google.com>
Subject: Re: [Patch net] socket: close race condition between sock_close() and sockfs_setattr()
Date: Thu, 7 Jun 2018 23:32:43 +0100	[thread overview]
Message-ID: <20180607223242.GY30522@ZenIV.linux.org.uk> (raw)
In-Reply-To: <CAM_iQpWs8pLANoQhUBsJLfwJc6V5db69v1SFeLg_Uu0LdgJzMA@mail.gmail.com>

On Thu, Jun 07, 2018 at 03:15:15PM -0700, Cong Wang wrote:

> > You do realize that the same ->setattr() can be called by way of
> > chown() on /proc/self/fd/<n>, right?  What would you do there -
> > bump refcount on that struct file when traversing that symlink and
> > hold it past the end of pathname resolution, until... what exactly?
> 
> I was thinking about this:
> 
>         error = user_path_at(dfd,....); // hold dfd when needed
> 
>         if (!error) {
>                 error = chown_common(&path, mode);
>                 path_put(&path);      // release dfd if held
> 
> With this, we can guarantee ->release() is only possibly called
> after chown_common() which is after ->setattr() too.

No, we can't.  You are assuming that there *is* dfd and that it points
to the opened socket we are going to operate upon.  That is not guaranteed.
At all.  If e.g. 42 is a file descriptor of an opened socket, plain chown(2)
on /proc/self/fd/42 will trigger that ->setattr().  No dfd in sight.
We do run across an opened file at some point, all right - when we traverse
the symlink in procfs.  You can't bump ->f_count there.  Even leaving aside
the "where would I stash the reference to that file?" and "how long would I
hold it?", you can't bump ->f_count on other process' files.  That would
bugger the expectations of close(2) callers.

  reply	other threads:[~2018-06-07 22:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07 20:39 [Patch net] socket: close race condition between sock_close() and sockfs_setattr() Cong Wang
2018-06-07 21:26 ` Al Viro
2018-06-07 21:45   ` Cong Wang
2018-06-07 22:04     ` Al Viro
2018-06-07 22:15       ` Cong Wang
2018-06-07 22:32         ` Al Viro [this message]
2018-06-10 19:27 ` David Miller
2018-06-10 19:43   ` Cong Wang

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=20180607223242.GY30522@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=lorenzo@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=shankarapailoor@gmail.com \
    --cc=xiyou.wangcong@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 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.