From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: [Patch net] socket: close race condition between sock_close() and sockfs_setattr() Date: Thu, 7 Jun 2018 22:26:31 +0100 Message-ID: <20180607212631.GW30522@ZenIV.linux.org.uk> References: <20180607203949.16945-1-xiyou.wangcong@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: netdev@vger.kernel.org, shankarapailoor@gmail.com, Tetsuo Handa , Lorenzo Colitti To: Cong Wang Return-path: Received: from zeniv.linux.org.uk ([195.92.253.2]:56126 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbeFGV0f (ORCPT ); Thu, 7 Jun 2018 17:26:35 -0400 Content-Disposition: inline In-Reply-To: <20180607203949.16945-1-xiyou.wangcong@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: 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. And it's very likely to trigger shitloads of deadlock warnings, some possibly even true.