Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2232463imm; Thu, 7 Jun 2018 07:26:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK7kJVCRRIvZAvD3O117Bq1n8nqWUj/IThpnFXo8utL0vzKPB6rpbIjq5Ex73Ntrw/rU3sp X-Received: by 2002:a17:902:8a81:: with SMTP id p1-v6mr2334855plo.33.1528381616375; Thu, 07 Jun 2018 07:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528381616; cv=none; d=google.com; s=arc-20160816; b=ev3lSvpFkZ1ZKEY3E52yYCWFyPGBO33aEG7qIsBZNN1RawawRqw+91TPZhEoRudvwi j6R+sFz2AfHnmJAa/sHCuLuvHf0rqRo1kobBavdIiMEuALWkY/fr4W7tm3/q3rhlpACo BeQCnRwSac1cktaU0ECBEZOEzhHt6mZUEd8ZK/v8kY7B9jxIKM5nyzTlJvtf9krhcndh p+rLsXjoDHd7kb8Px6Abm1e9W4ScePKa2tN19Wa9CpH1/sS+DBNYymoHJeu4nyX1vCDx bjqqxS8NLe7wsNvIrZ8cNdtQ4dPcn5bKXM0yJN8Fpd1FGjDb8bkjvHKNlHw4L8BZ5DFX BooQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=vBg+bGzGGblfDIe3AzGLH7kqXrvSFJttUbRo1d0S4EM=; b=IruS8yU8QGk53LRQu19FKKL09PJFa2GlsMbS6OmRDO5W1vKdWIJlClRb4tGCq6hleM UrReCXX3/peyWmvkyVqkkEfjjjCAObxVvDITzyVK70pywVA3p/ckMy1CgisDVGOt5n4M xEFxABVXQyrdy/MyVm2veTyzXU8I/Akw5uvlEcjDm8uAWXpsyscbptdRSx9plTws4Ikw u2Fwaw5PfF6MLiTvC4tUp21GnSYA5oN3u7tL9cnZJwOGOh+UKroi3llCrseLGNwbozSQ ieMkwu/ILKQG+y/Zmq/wXQVyoUYa/XWtVIRVxHXMl4FIjVH+SF2syFA8bigiLUA9Sihz MWaQ== 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 p3-v6si31282257plr.131.2018.06.07.07.26.42; Thu, 07 Jun 2018 07:26:56 -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 S933109AbeFGOVw (ORCPT + 99 others); Thu, 7 Jun 2018 10:21:52 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:39449 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933079AbeFGOJK (ORCPT ); Thu, 7 Jun 2018 10:09:10 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbA-0005Zk-VN; Thu, 07 Jun 2018 15:09:09 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb7-00033N-Ej; Thu, 07 Jun 2018 15:09:05 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Pablo Neira Ayuso" , syzbot+ddde1c7b7ff7442d7f2d@syzkaller.appspotmail.com, "Florian Westphal" , "Paolo Abeni" , "Xin Long" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 234/410] netfilter: drop outermost socket lock in getsockopt() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Abeni commit 01ea306f2ac2baff98d472da719193e738759d93 upstream. The Syzbot reported a possible deadlock in the netfilter area caused by rtnl lock, xt lock and socket lock being acquired with a different order on different code paths, leading to the following backtrace: Reviewed-by: Xin Long ====================================================== WARNING: possible circular locking dependency detected 4.15.0+ #301 Not tainted ------------------------------------------------------ syzkaller233489/4179 is trying to acquire lock: (rtnl_mutex){+.+.}, at: [<0000000048e996fd>] rtnl_lock+0x17/0x20 net/core/rtnetlink.c:74 but task is already holding lock: (&xt[i].mutex){+.+.}, at: [<00000000328553a2>] xt_find_table_lock+0x3e/0x3e0 net/netfilter/x_tables.c:1041 which lock already depends on the new lock. === Since commit 3f34cfae1230 ("netfilter: on sockopt() acquire sock lock only in the required scope"), we already acquire the socket lock in the innermost scope, where needed. In such commit I forgot to remove the outer-most socket lock from the getsockopt() path, this commit addresses the issues dropping it now. v1 -> v2: fix bad subj, added relavant 'fixes' tag Fixes: 22265a5c3c10 ("netfilter: xt_TEE: resolve oif using netdevice notifiers") Fixes: 202f59afd441 ("netfilter: ipt_CLUSTERIP: do not hold dev") Fixes: 3f34cfae1230 ("netfilter: on sockopt() acquire sock lock only in the required scope") Reported-by: syzbot+ddde1c7b7ff7442d7f2d@syzkaller.appspotmail.com Suggested-by: Florian Westphal Signed-off-by: Paolo Abeni Signed-off-by: Pablo Neira Ayuso Signed-off-by: Ben Hutchings --- net/ipv4/ip_sockglue.c | 7 +------ net/ipv6/ipv6_sockglue.c | 10 ++-------- 2 files changed, 3 insertions(+), 14 deletions(-) --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -1391,10 +1391,7 @@ int ip_getsockopt(struct sock *sk, int l if (get_user(len, optlen)) return -EFAULT; - lock_sock(sk); - err = nf_getsockopt(sk, PF_INET, optname, optval, - &len); - release_sock(sk); + err = nf_getsockopt(sk, PF_INET, optname, optval, &len); if (err >= 0) err = put_user(len, optlen); return err; @@ -1426,9 +1423,7 @@ int compat_ip_getsockopt(struct sock *sk if (get_user(len, optlen)) return -EFAULT; - lock_sock(sk); err = compat_nf_getsockopt(sk, PF_INET, optname, optval, &len); - release_sock(sk); if (err >= 0) err = put_user(len, optlen); return err; --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -1309,10 +1309,7 @@ int ipv6_getsockopt(struct sock *sk, int if (get_user(len, optlen)) return -EFAULT; - lock_sock(sk); - err = nf_getsockopt(sk, PF_INET6, optname, optval, - &len); - release_sock(sk); + err = nf_getsockopt(sk, PF_INET6, optname, optval, &len); if (err >= 0) err = put_user(len, optlen); } @@ -1352,10 +1349,7 @@ int compat_ipv6_getsockopt(struct sock * if (get_user(len, optlen)) return -EFAULT; - lock_sock(sk); - err = compat_nf_getsockopt(sk, PF_INET6, - optname, optval, &len); - release_sock(sk); + err = compat_nf_getsockopt(sk, PF_INET6, optname, optval, &len); if (err >= 0) err = put_user(len, optlen); }