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:04:47 +0100 [thread overview]
Message-ID: <20180607220446.GX30522@ZenIV.linux.org.uk> (raw)
In-Reply-To: <CAM_iQpUpBYC0MpjOsYLn5ZnsjS3pSHbZo2AE=trfrsJNxQYyxA@mail.gmail.com>
On Thu, Jun 07, 2018 at 02:45:58PM -0700, Cong Wang wrote:
> On Thu, Jun 7, 2018 at 2:26 PM, Al Viro <viro@zeniv•linux.org.uk> wrote:
> > On Thu, Jun 07, 2018 at 01:39:49PM -0700, Cong Wang wrote:
> >> fchownat() doesn't even hold refcnt of fd until it figures out
> >> fd is really needed (otherwise is ignored) and releases it after
> >> it resolves the path. This means sock_close() could race with
> >> sockfs_setattr(), which leads to a NULL pointer dereference
> >> since typically we set sock->sk to NULL in ->release().
> >>
> >> As pointed out by Al, this is unique to sockfs. So we can fix this
> >> in socket layer by acquiring inode_lock in sock_close() and
> >> checking against NULL in sockfs_setattr().
> >
> > That looks like a massive overkill - it's way heavier than it should be.
>
> I don't see any other quick way to fix this. My initial thought is
> to keep that refcnt until path_put(), apparently you don't like it
> either.
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?
next prev parent reply other threads:[~2018-06-07 22:04 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 [this message]
2018-06-07 22:15 ` Cong Wang
2018-06-07 22:32 ` Al Viro
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=20180607220446.GX30522@ZenIV.linux.org.uk \
--to=viro@zeniv$(echo .)linux.org.uk \
--cc=lorenzo@google$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=penguin-kernel@i-love$(echo .)sakura.ne.jp \
--cc=shankarapailoor@gmail$(echo .)com \
--cc=xiyou.wangcong@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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