Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2517749imu; Thu, 29 Nov 2018 06:18:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/VcBRte+r+ZMpkE5LVf4uYVRiN8KSoaw9BQ5/FDNvMcZ9eQ8syHnthQiFNs15UfIEbPGkLj X-Received: by 2002:a63:594d:: with SMTP id j13mr1405099pgm.210.1543501109557; Thu, 29 Nov 2018 06:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543501109; cv=none; d=google.com; s=arc-20160816; b=A+wvQ0U3qL7hS5yS05rRgNygwsVPrIVrC0ZPRQY4n22MCzqjeIjHM0YA5qjai1H85x WX4nmEECJMOI8lnkJFNF4DcCPlPw2SIZhGBliommcpDDN74va9k+xVRJmtha6PXE0aWB RTScKvDpD7vL2qpqTl4ZQ3DhCA7h5K+7xgko9gwg9Oe7SbGcZ2PBlHl+a8s4XelvQjSX vehxOOSw/8SLoppwCp/LRFw9qWJG8gMuvymMQwTYnizfGsUJtBFwXzNDUc3E96U0LUfX IhJl/32eKBJA+9sxNEGmFAPW+RwFBVhb1PmAI+aYSqbjGwmaWgd9m0KlOqynY8A9uv1B BLFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1DsVvKqfOXnMVKa20g8S4D6FSvfmhli/8iYbftAAnMo=; b=De8427ACim4lvyOEFXKkC4NXtLSt7eBcmYhMDtqaWcGRDst6idAtip/mMquh9VvLG1 8P2wrBYDVrhEk/1hBDPeJ+BFE3ZfuuQ+Bc8XCr4yyroz9mah0qMi5rE0p0d9cclKyjMm RnLNqnAlYBSIyBq4RBq+FyUpoqG+HtJg2Uwc2gPAMy6xhFQH/kBjukzdmq66pw0vRRbY xtifIGw1zvE5gf1ZbrBms4Kn10QhI7HevH6/MDMkfDIPHJq3CWzGnHikGT0Pe0x9ig4r gcyiavVS1cMEQXTTgE6eG6vZffqMqaYvxs7EW9dWLreDzr/u/kzhf2sT/GYhygPAyGHC slOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="V/rMp+nt"; 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 s27si1969173pgm.501.2018.11.29.06.18.14; Thu, 29 Nov 2018 06:18:29 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="V/rMp+nt"; 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 S1730041AbeK3BWB (ORCPT + 99 others); Thu, 29 Nov 2018 20:22:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:43562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728865AbeK3BWB (ORCPT ); Thu, 29 Nov 2018 20:22:01 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7760D21104; Thu, 29 Nov 2018 14:16:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543500990; bh=i0SaZa/jQKc7kNXfRbDyk3FMOraS5fUUikqhqDo5sCk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/rMp+nt98KFFB/ttoj7RHvL2ayfA6of2HSEpjxK5SzIsAxxGFd5CjL128Cur2Aum rGgRkz7eD5owPYOOLWWDwHNLGJfDKxgMXqy9teqeR1lUIpJKGykO6yxv9QvUvevdI9 Oc3ukrA6QH7LkjMGnqUYzWFzB9c8Zu/V9bIeenfw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , Rainer Weikusat , Al Viro , Cong Wang , "David S. Miller" , Petr Vorel Subject: [PATCH 3.18 82/83] af_unix: move unix_mknod() out of bindlock Date: Thu, 29 Nov 2018 15:12:40 +0100 Message-Id: <20181129140142.732788522@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140138.002176596@linuxfoundation.org> References: <20181129140138.002176596@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: WANG Cong commit 0fb44559ffd67de8517098b81f675fa0210f13f0 upstream. Dmitry reported a deadlock scenario: unix_bind() path: u->bindlock ==> sb_writer do_splice() path: sb_writer ==> pipe->mutex ==> u->bindlock In the unix_bind() code path, unix_mknod() does not have to be done with u->bindlock held, since it is a pure fs operation, so we can just move unix_mknod() out. Reported-by: Dmitry Vyukov Tested-by: Dmitry Vyukov Cc: Rainer Weikusat Cc: Al Viro Signed-off-by: Cong Wang Signed-off-by: David S. Miller Cc: Petr Vorel Signed-off-by: Greg Kroah-Hartman --- net/unix/af_unix.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -980,6 +980,7 @@ static int unix_bind(struct socket *sock unsigned int hash; struct unix_address *addr; struct hlist_head *list; + struct path path = { NULL, NULL }; err = -EINVAL; if (sunaddr->sun_family != AF_UNIX) @@ -995,9 +996,20 @@ static int unix_bind(struct socket *sock goto out; addr_len = err; + 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; + } + } + err = mutex_lock_interruptible(&u->readlock); if (err) - goto out; + goto out_put; err = -EINVAL; if (u->addr) @@ -1014,16 +1026,6 @@ static int unix_bind(struct socket *sock atomic_set(&addr->refcnt, 1); if (sun_path[0]) { - struct path path; - 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; - unix_release_addr(addr); - goto out_up; - } addr->hash = UNIX_HASH_SIZE; hash = d_backing_inode(path.dentry)->i_ino & (UNIX_HASH_SIZE-1); spin_lock(&unix_table_lock); @@ -1050,6 +1052,9 @@ out_unlock: spin_unlock(&unix_table_lock); out_up: mutex_unlock(&u->readlock); +out_put: + if (err) + path_put(&path); out: return err; }