Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp447509imm; Fri, 31 Aug 2018 04:55:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYlWo7RpoKeIFIsu2us2nxt5xVhd4tF73myoNDv0Z9j63Dqb0KwGwXJCPoVjBqb0guFTZKz X-Received: by 2002:a17:902:f20c:: with SMTP id gn12mr14948076plb.41.1535716511198; Fri, 31 Aug 2018 04:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535716511; cv=none; d=google.com; s=arc-20160816; b=bklIfxjplG2U3bd9dQat40Vnawqrvw2on75deei3ivCjvkEHtrTkqY0nj30C5z57EV ZPxwcmWDnIHGM05mmoZzxW7xoWS33ZFGZPCkbPW20AAjE7pOc2nVUnuem1PL7EDs9mMD MwDLPA/rFlLgJdKRdlBHzUvIkB2yviVK4pvMnFZC14mdvX+/54fkxnQhSoKgnkScDpWK OuBekSTTvfHFq8oLiyv9AqOi/2hz0BfZhBQTM1dISckISgSJvHCEO77tinfv3JT1+00G g2Yz9OYpe39Ria5YYhiE5/CCLhDjSkuE+W8DcZvHjxxxIe6rI2d8Uk3Z81IvMyyolBSj /zow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:arc-authentication-results; bh=dYa6654BpLZtVdNTYcKqt2YPOzeiwyexZkGCQsjIcKY=; b=uaj+HLOF13VL2ebPeEoOvoGaLkVw9RiQCJZkMOCMQKNwLmE4iqQBIDdVDyrdSUjKY+ NgCCF67cvBNawbz8sdKhICFYdZ8rdu0sXD5iMwK3V9w1txMdyAcRmKxk3+dy9+fuSivc Oz3vulzeuSp8LBsq66YIAtb7AFlFnFlCXDg7ak3MjNaakoliqC9aUdVkigTR3X8/niTp I3Sr7LQKvZeJ2ggE4v+Ej8J3E7MUyakIVo5iovCua1nH1519fTXEYWGQjIFIJZhYg7G8 JgZoz8HfOjaYmmGVua6RykU1R43vbx9CJAwLeEP18x+/NU9jg8uCX4Z14xdPP+fQ7J96 t11Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5-v6si9509187pgb.686.2018.08.31.04.54.56; Fri, 31 Aug 2018 04:55:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728027AbeHaPVj (ORCPT + 99 others); Fri, 31 Aug 2018 11:21:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:55694 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726990AbeHaPVj (ORCPT ); Fri, 31 Aug 2018 11:21:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D39C6ACC4; Fri, 31 Aug 2018 11:14:38 +0000 (UTC) Date: Fri, 31 Aug 2018 13:14:36 +0200 From: Petr Vorel To: Michal Kubecek , "David S. Miller" Cc: netdev@vger.kernel.org, WANG Cong , Rainer Weikusat , linux-kernel@vger.kernel.org, ltp@lists.linux.it, Cyril Hrubis , Junchi Chen Subject: Re: RFC: changed error code when binding unix socket twice Message-ID: <20180831111436.GA23780@dell5510> Reply-To: Petr Vorel References: <20170630073448.GA9546@unicorn.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170630073448.GA9546@unicorn.suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, > commit 0fb44559ffd6 ("af_unix: move unix_mknod() out of bindlock") moves > the special file creation in unix_bind() before u->bindlock is taken in > order to avoid an ABBA deadlock with do_splice(). As a side effect, it > also moves the check for existence of the special file (which would > result in -EADDRINUSE) before the check of u->addr (which would result > in -EINVAL if socket is already bound). This means that the error > returned for an attempt to bind a unix socket to the same path twice > changed from -EINVAL to -EADDRINUSE with this commit. > One way to restore the old error code is indicated below but before > submitting it, I would like to ask if we need/want it. > Pro: > - in general, we do not want to change return code for given testcase > - old error (-EINVAL) is consistent with AF_INET(6) > Con: > - both POSIX and Linux man page only list error conditions without > stating which should take precedence if more of them apply so > neither of them seems wrong, strictly speaking I'd be for restoring the original behavior (be conservative + looks like as not intended). Any comment from netdev maintainers? Kind regards, Petr > diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c > index 1a0c961f4ffe..509292bdf7ed 100644 > --- a/net/unix/af_unix.c > +++ b/net/unix/af_unix.c > @@ -992,7 +992,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) > struct unix_sock *u = unix_sk(sk); > struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; > char *sun_path = sunaddr->sun_path; > - int err; > + int err, mknod_err; > unsigned int hash; > struct unix_address *addr; > struct hlist_head *list; > @@ -1016,12 +1016,10 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) > if (sun_path[0]) { > umode_t mode = S_IFSOCK | > (SOCK_INODE(sock)->i_mode & ~current_umask()); > - err = unix_mknod(sun_path, mode, &path); > - if (err) { > - if (err == -EEXIST) > - err = -EADDRINUSE; > - goto out; > - } > + mknod_err = unix_mknod(sun_path, mode, &path); > + /* do not exit on error until after u->addr check */ > + if (mknod_err == -EEXIST) > + mknod_err = -EADDRINUSE; > } > err = mutex_lock_interruptible(&u->bindlock); > @@ -1031,6 +1029,10 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) > err = -EINVAL; > if (u->addr) > goto out_up; > + if (mknod_err) { > + err = mknod_err; > + goto out_up; > + } > err = -ENOMEM; > addr = kmalloc(sizeof(*addr)+addr_len, GFP_KERNEL);