Received: by 10.223.185.116 with SMTP id b49csp4160546wrg; Mon, 26 Feb 2018 12:17:27 -0800 (PST) X-Google-Smtp-Source: AH8x227F9xBAG6TMgYn9CI5F9ckeYjGaKjnAvkjuu8yAG6pWEWWPGcFJUDHZt1ULnSOWgq110Sar X-Received: by 2002:a17:902:7593:: with SMTP id j19-v6mr11119324pll.408.1519676247836; Mon, 26 Feb 2018 12:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519676247; cv=none; d=google.com; s=arc-20160816; b=z1YaaX1Wn/peoFTa6nqPoxsR9CNWu+QnZrs94S/KujLcLdH4JyzRUTIFSyfj5kGYw2 JdxbucxrSiY8nFPD4tO69J5Gw0CAC1n1vvBFSLyUUDdl6EBBkR0mUczlGcDuSjWIVy1P IuLPXgIGSgPtN8LAXTZdtjVtpTk/nkUwS+N2Bqc98pTnupxC/Ks3Gd+7Pd7ESgIExvDG wfb59zjuDhhp2CDfqmL4NrXRGMvap07AUNA2KZpHYy/txDQCActJxXkGLcfFeVwVnkVu Ry3bphmwH3UP0IjyOMnrCcQJ0SZ3a8G5IkEXE+gMkp1qm+c93gkpdhonUvSXIsKcIuY5 Vu5w== 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=8G9qa0eDUptpjwV9QBWtYjwwgvAqTTe66wVCe8s01OU=; b=EISAbU32rIQwBWcRPtgWgjsJ2q0ZcvjIcZfS3s0O5NyKp18TJXb6mQkHS+EhH/yYB9 mUWB3hs635OSRHx4FUWxPXwswazusPiMLetRbtTIRppZSUwogcfonAwe15XkfOUJGqyk kvXcAv16vz1y7GIM2cfUlEzZBlgfQR+zBqdFrok6AtQ+OzGGmW6Ozwyy4QcTuu/68V4j 0GfscN6PUF8cClBMC88zXLZxcGVLhR9gMePLwzDLC859FkINp8q2csY8M1Qvfc4ZAjXN ZOCljlFnf38xCAUz8fYC+RgWZs7diRARYzecPtTTtdwt65CVJI88w7XI+1Ec9VmndPfG 9+Rg== 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 t12si555367pgo.153.2018.02.26.12.17.12; Mon, 26 Feb 2018 12:17:27 -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 S1751590AbeBZUPy (ORCPT + 99 others); Mon, 26 Feb 2018 15:15:54 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:58294 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750991AbeBZUPu (ORCPT ); Mon, 26 Feb 2018 15:15:50 -0500 Received: from localhost (clnet-b04-243.ikbnet.co.at [83.175.124.243]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2239610C5; Mon, 26 Feb 2018 20:15:48 +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 3.18 01/13] netfilter: drop outermost socket lock in getsockopt() Date: Mon, 26 Feb 2018 21:15:29 +0100 Message-Id: <20180226201527.311780415@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180226201527.242286068@linuxfoundation.org> References: <20180226201527.242286068@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 3.18-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 @@ -1375,10 +1375,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; @@ -1410,9 +1407,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 @@ -1314,10 +1314,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); } @@ -1356,10 +1353,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); }