From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754753AbdBGOUo (ORCPT ); Tue, 7 Feb 2017 09:20:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35884 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754265AbdBGOUm (ORCPT ); Tue, 7 Feb 2017 09:20:42 -0500 Date: Tue, 7 Feb 2017 15:20:35 +0100 From: Mateusz Guzik To: Cong Wang Cc: Dmitry Vyukov , Al Viro , "linux-fsdevel@vger.kernel.org" , LKML , David Miller , Rainer Weikusat , Hannes Frederic Sowa , netdev , Eric Dumazet , syzkaller Subject: Re: fs, net: deadlock between bind/splice on af_unix Message-ID: <20170207142035.vfnyrbggb6kbfzgd@dhcp-1-212.brq.redhat.com> References: <20161209064144.GZ1555@ZenIV.linux.org.uk> <20170126232912.rgh6undqxd4tofqj@dhcp-1-212.brq.redhat.com> <20170127064143.ddyt43iglu2odlld@dhcp-1-212.brq.redhat.com> <20170131181411.cq3o7yxrnhq6thpt@dhcp-1-212.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 07 Feb 2017 14:20:43 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 05, 2017 at 11:22:12PM -0800, Cong Wang wrote: > On Tue, Jan 31, 2017 at 10:14 AM, Mateusz Guzik wrote: > > On Mon, Jan 30, 2017 at 10:44:03PM -0800, Cong Wang wrote: > >> Mind being more specific? > > > > Consider 2 threads which bind the same socket, but with different paths. > > > > Currently exactly one file will get created, the one used to bind. > > > > With your patch both threads can succeed creating their respective > > files, but only one will manage to bind. The other one must error out, > > but it already created a file it is unclear what to do with. > > In this case, it simply puts the path back: > > err = -EINVAL; > if (u->addr) > goto out_up; > [...] > > out_up: > mutex_unlock(&u->bindlock); > out_put: > if (err) > path_put(&path); > out: > return err; > > > Which is what unix_release_sock() does too: > > if (path.dentry) > path_put(&path); Yes, but unix_release_sock is expected to leave the file behind. Note I'm not claiming there is a leak, but that racing threads will be able to trigger a condition where you create a file and fail to bind it. What to do with the file now? Untested, but likely a working solution would rework the code so that e.g. a flag is set and the lock can be dropped.