Received: by 10.223.185.116 with SMTP id b49csp4193552wrg; Mon, 26 Feb 2018 12:57:23 -0800 (PST) X-Google-Smtp-Source: AH8x224raKUHifMa9xp7XaTKFILct01WzvDtjIo0yk9mHIlPK/t//HhFQYRY3DLp/3nZbcAxsW32 X-Received: by 2002:a17:902:12d:: with SMTP id 42-v6mr12051107plb.141.1519678643338; Mon, 26 Feb 2018 12:57:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519678643; cv=none; d=google.com; s=arc-20160816; b=kto9Ru7dzpiHEDrtlpuTD1UgbgGZ3dSr5nkLmwpKseAB00f/CGQyBl7yNdgB2mWwMe OORDCQ0smumsyHOfrHftakt9dUMyWXKrWil3a+PHHUYUThurhDlPZBKxXS425TXGJw5E ucResHGxdy7eVFxRfY70rhTyGLV/bDZfSi6EDMlQN8KSyd62t5vfFvZr7vewuy0pB2y9 cogNtnJ56trQuvcKXHl16KsMlBqtIfj7UnTSFRczVSYWjvpyjK87bl04kCstY9pruxIC dDs8XwOqQYtOyoeoDdR63wOCS5tGjeAThsNt9ezikf58wlVszE9aysTcZ1PR+o/fw4jZ 68Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5XNCKyeT80Stvo9Kv65mkI/jL0TBSA8kJ+Q17jPhSJk=; b=oHQKr1L5SX1vir+gh8fvvyTe713MXZh/A7mY1nL94uzX88KCoBdA0tyVt4gsJ0gJT3 PQ+0YaGE7zd6HFiaRxdDXWpxBdvDwqEk/XONfn3ovILOvr+n5QMQLewDKeL4TI1oEF7Q WCBsALCtc6EQ3olTeHXjiQ1Hhebf7BCTbsHDEZrHrSr4f++Fs3YWli1BPPB94N8xgUs9 ZgbyqjONSSNubG7JHi8mbfRAFMcVw4RT2U4juvQY57voArw1UV8nrW8v87VT2jUB3sNo AytmNLerLDN+BgpQmK+gfOEOg75+6qaiPSK4Vh71vm08zaWE6aMla1KIpbpFFaJC+Q7I ys6Q== 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 a8-v6si7244777ple.435.2018.02.26.12.57.07; Mon, 26 Feb 2018 12:57:23 -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; 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 S1752626AbeBZUXO (ORCPT + 99 others); Mon, 26 Feb 2018 15:23:14 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34706 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752294AbeBZUXL (ORCPT ); Mon, 26 Feb 2018 15:23:11 -0500 Received: from localhost (clnet-b04-243.ikbnet.co.at [83.175.124.243]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8F8ADF11; Mon, 26 Feb 2018 20:23:10 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , syzbot+ddde1c7b7ff7442d7f2d@syzkaller.appspotmail.com, Florian Westphal , Paolo Abeni , Pablo Neira Ayuso , Krzysztof Piotr Oledzki Subject: [PATCH 4.14 01/54] netfilter: drop outermost socket lock in getsockopt() Date: Mon, 26 Feb 2018 21:21:38 +0100 Message-Id: <20180226202144.443053148@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180226202144.375869933@linuxfoundation.org> References: <20180226202144.375869933@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 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 4.14-stable 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 Tested-by: Krzysztof Piotr Oledzki Signed-off-by: Greg Kroah-Hartman --- 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 @@ -1563,10 +1563,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; @@ -1598,9 +1595,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 @@ -1355,10 +1355,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); } @@ -1397,10 +1394,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); }