Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3360224imd; Mon, 29 Oct 2018 06:04:23 -0700 (PDT) X-Google-Smtp-Source: AJdET5dTFVt4vxxWiCxn1N746v4PF7NcxjxCvgYD1MHs3/xXGJN79z83AIHIynjJOIpwvAVzI952 X-Received: by 2002:a17:902:167:: with SMTP id 94-v6mr13936801plb.142.1540818263538; Mon, 29 Oct 2018 06:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540818263; cv=none; d=google.com; s=arc-20160816; b=eWt9Bhz7CU5dBlQ7GV0eD/Yq+F8z3W+x7pXFrPuDpbgs6E3LLi/vgEvfa4jGNth1V8 N+KLhtqVwz3j0H6fzP7dbTiYqkiRSuS1dW6+qpW+lZHzY/d/zB/91zV6B16/v+cbELWO D1dtTH3VYBq7qE4D9RZHqva1uLfSbdz4EE+5ZQfz4vsbJmr+CAv3EIRcU/x/gkxSdyAU bOp6Oh9gXA7x5erXBtD+OR8X/wGVGsqKxscVCL8nEM6sOuX+ERxgB0c1xNF9hHHXFLa5 bwOlGPCfhPhxyi2MBWJ4ysc2nbPo/uptkBfdBUkJxxbOYQnOphDAX4gCy9D0I0figdTi ZrlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=SS8S9dnRxUWD38Fs9fu7hAdf1KDQ/28YbR5SSVzO0uo=; b=rz+EcCtXSKZowNbciSGbDnIr9AY/Fq7O0Nnm4zAQqG+9VvlQuoxr69l3f2//geJQNm ZL0jXC7ocwfXolptppbqOOW9KySIENRE4YR2iJOsPX3OkCyDrPsC9EuPYxBefU00kOuP tyvACA9rkkirlZADA8//dChHQPDyZlegNEi5s7g3R5JB60iuMLzfSQCpn2ceQ+Z90vou wKxAJj/ypsa5PFaobj3UPL2XoLf9gI8FFAEhz3a4AnckC0Qi2PznwbQBWo2C5ypIWaIz GyvaKb7tuXPWlalNe3eIQRCw/HK9WX+OsyORWKD119md5QCtaBtJTI/4pysT3x2OLrdX DBKQ== 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 n78-v6si10028631pfi.171.2018.10.29.06.04.06; Mon, 29 Oct 2018 06:04:23 -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 S1726090AbeJ2VwI (ORCPT + 99 others); Mon, 29 Oct 2018 17:52:08 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:34472 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbeJ2VwH (ORCPT ); Mon, 29 Oct 2018 17:52:07 -0400 Received: by mail-qk1-f193.google.com with SMTP id a132so4827299qkg.1; Mon, 29 Oct 2018 06:03:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SS8S9dnRxUWD38Fs9fu7hAdf1KDQ/28YbR5SSVzO0uo=; b=n/ZBaEOueS+k/s3/PEdBpjO1q7EEsvCh27934CtEU8fRRUYDqybjHdeo5GmeHZACt2 brFkw0cAfN+k/BWhs0Lw+cvOWgFOrwGLFQiY2rIl7u+JWlJJXvPoqunzfdtF2Fp1pJ6Y d1o58dKNfs+BAiGpNikDY+9YcYZKJ77BbJJ3EL5rwFUnOGi6Eh/KITxXmGENqLr3eyoy txdCHvAU5JFFxQJ3mOXYbrfG3spizP0QtYBFxzAe3IhB0XX0mKkkWs2EPCV609UcGtjs FT7dgPXj0AGoDoqpdvOKv0TqbJFu3dCEQyomwJyh1NhizMGTvur2Z2WqH5xCiMwFdAAI iPZQ== X-Gm-Message-State: AGRZ1gLI1KJEjCrrKiiTYs4Xt5ef/S+njN9T3FwcYVQ1WQL8BTBkZ9BS wEp/2ED4s1Ygih8ifRaPw9NhlnAzYLlQ2hRq+t4= X-Received: by 2002:ae9:d801:: with SMTP id u1-v6mr12275026qkf.291.1540818211414; Mon, 29 Oct 2018 06:03:31 -0700 (PDT) MIME-Version: 1.0 References: <20170630073448.GA9546@unicorn.suse.cz> <20180831111436.GA23780@dell5510> In-Reply-To: <20180831111436.GA23780@dell5510> From: Arnd Bergmann Date: Mon, 29 Oct 2018 14:03:15 +0100 Message-ID: Subject: Re: RFC: changed error code when binding unix socket twice To: pvorel@suse.cz Cc: mkubecek@suse.cz, David Miller , Networking , Cong Wang , rweikusat@mobileactivedefense.com, Linux Kernel Mailing List , ltp@lists.linux.it, Cyril Hrubis , junchi.chen@intel.com, Dmitry Vyukov , Greg Kroah-Hartman , Naresh Kamboju Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 31, 2018 at 1:17 PM Petr Vorel wrote: > > 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? Naresh noticed that LTP now has a version check to detect linux-4.10+ and expect a different return code from previous versions, but the 0fb44559ffd6 commit that changed the behavior got backported to stable linux-4.4 and 4.9, so now LTP complains about those: https://bugs.linaro.org/show_bug.cgi?id=4042 I don't care much which error code gets returned here, but I think we should either handle this consistently in all kernel versions and check for the one that is deemed the correct one on all versions, or change LTP again to accept either return code. Arnd > > 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);