From patchwork Thu Mar 8 01:01:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 145390 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id ABCC0B6EE8 for ; Thu, 8 Mar 2012 12:02:04 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752045Ab2CHBBt (ORCPT ); Wed, 7 Mar 2012 20:01:49 -0500 Received: from mail.us.es ([193.147.175.20]:56125 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751260Ab2CHBBh (ORCPT ); Wed, 7 Mar 2012 20:01:37 -0500 Received: (qmail 6134 invoked from network); 8 Mar 2012 02:01:35 +0100 Received: from unknown (HELO us.es) (192.168.2.12) by us.es with SMTP; 8 Mar 2012 02:01:35 +0100 Received: (qmail 21332 invoked by uid 507); 8 Mar 2012 01:01:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on antivirus2 X-Spam-Level: X-Spam-Status: No, score=-98.4 required=7.5 tests=BAYES_50,KHOP_DYNAMIC, RCVD_IN_PBL, RDNS_DYNAMIC, T_FRT_CONTACT, USER_IN_WHITELIST autolearn=disabled version=3.3.1 Received: from 127.0.0.1 by antivirus2 (envelope-from , uid 501) with qmail-scanner-2.08 (clamdscan: 0.97.3/14610. Clear:RC:1(127.0.0.1):. Processed in 0.025404 secs); 08 Mar 2012 01:01:34 -0000 Received: from unknown (HELO antivirus2) (127.0.0.1) by us.es with SMTP; 8 Mar 2012 01:01:34 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus2 (F-Secure/fsigk_smtp/407/antivirus2); Thu, 08 Mar 2012 02:01:34 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/407/antivirus2) Received: (qmail 12381 invoked from network); 8 Mar 2012 02:01:34 +0100 Received: from 91-64-60-56-dynip.superkabel.de (HELO localhost.localdomain) (pneira@us.es@91.64.60.56) by us.es with SMTP; 8 Mar 2012 02:01:34 +0100 From: pablo@netfilter.org To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH 15/23] netfilter: ctnetlink: fix lockep splats Date: Thu, 8 Mar 2012 02:01:04 +0100 Message-Id: <1331168472-5820-16-git-send-email-pablo@netfilter.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1331168472-5820-1-git-send-email-pablo@netfilter.org> References: <1331168472-5820-1-git-send-email-pablo@netfilter.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Hans Schillstrom net/netfilter/nf_conntrack_proto.c:70 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 1, debug_locks = 0 3 locks held by conntrack/3235: nfnl_lock+0x17/0x20 netlink_dump+0x32/0x240 ctnetlink_dump_table+0x3e/0x170 [nf_conntrack_netlink] stack backtrace: Pid: 3235, comm: conntrack Tainted: G W 3.2.0+ #511 Call Trace: [] lockdep_rcu_suspicious+0xe5/0x100 [] __nf_ct_l4proto_find+0x81/0xb0 [nf_conntrack] [] ctnetlink_fill_info+0x215/0x5f0 [nf_conntrack_netlink] [] ctnetlink_dump_table+0xd1/0x170 [nf_conntrack_netlink] [] netlink_dump+0x7f/0x240 [] ? trace_hardirqs_on+0xd/0x10 [] netlink_dump_start+0xdf/0x190 [] ? ctnetlink_change_nat_seq_adj+0x160/0x160 [nf_conntrack_netlink] [] ? ctnetlink_get_conntrack+0x2a0/0x2a0 [nf_conntrack_netlink] [] ctnetlink_get_conntrack+0x89/0x2a0 [nf_conntrack_netlink] [] nfnetlink_rcv_msg+0x467/0x5f0 [] ? nfnetlink_rcv_msg+0x49c/0x5f0 [] ? nfnetlink_rcv_msg+0x342/0x5f0 [] ? get_parent_ip+0x11/0x50 [] ? nfnetlink_subsys_register+0x60/0x60 [] netlink_rcv_skb+0xa9/0xd0 [] nfnetlink_rcv+0x15/0x20 [] netlink_unicast+0x1ae/0x1f0 [] netlink_sendmsg+0x2c6/0x320 [] sock_sendmsg+0x117/0x130 [] ? might_fault+0x53/0xb0 [] ? might_fault+0x9c/0xb0 [] ? might_fault+0x53/0xb0 [] ? move_addr_to_kernel+0x71/0x80 [] sys_sendto+0xfe/0x130 [] ? sys_bind+0xb4/0xd0 [] ? retint_swapgs+0xe/0x13 [] system_call_fastpath+0x16/0x1b Reported-by: Hans Schillstrom Signed-off-by: Eric Dumazet Signed-off-by: Hans Schillstrom --- net/netfilter/nf_conntrack_netlink.c | 40 ++++++++++++++++++++------------- 1 files changed, 24 insertions(+), 16 deletions(-) diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c index b8827e8..c1ea64c 100644 --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -110,15 +110,16 @@ ctnetlink_dump_tuples(struct sk_buff *skb, struct nf_conntrack_l3proto *l3proto; struct nf_conntrack_l4proto *l4proto; + rcu_read_lock(); l3proto = __nf_ct_l3proto_find(tuple->src.l3num); ret = ctnetlink_dump_tuples_ip(skb, tuple, l3proto); - if (unlikely(ret < 0)) - return ret; - - l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum); - ret = ctnetlink_dump_tuples_proto(skb, tuple, l4proto); - + if (ret >= 0) { + l4proto = __nf_ct_l4proto_find(tuple->src.l3num, + tuple->dst.protonum); + ret = ctnetlink_dump_tuples_proto(skb, tuple, l4proto); + } + rcu_read_unlock(); return ret; } @@ -712,9 +713,11 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb) struct hlist_nulls_node *n; struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh); u_int8_t l3proto = nfmsg->nfgen_family; + int res; #ifdef CONFIG_NF_CONNTRACK_MARK const struct ctnetlink_dump_filter *filter = cb->data; #endif + spin_lock_bh(&nf_conntrack_lock); last = (struct nf_conn *)cb->args[1]; for (; cb->args[0] < net->ct.htable_size; cb->args[0]++) { @@ -740,11 +743,14 @@ restart: continue; } #endif - if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, - cb->nlh->nlmsg_seq, - NFNL_MSG_TYPE( - cb->nlh->nlmsg_type), - ct) < 0) { + rcu_read_lock(); + res = + ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid, + cb->nlh->nlmsg_seq, + NFNL_MSG_TYPE(cb->nlh->nlmsg_type), + ct); + rcu_read_unlock(); + if (res < 0) { nf_conntrack_get(&ct->ct_general); cb->args[1] = (unsigned long)ct; goto out; @@ -1649,14 +1655,16 @@ ctnetlink_exp_dump_mask(struct sk_buff *skb, if (!nest_parms) goto nla_put_failure; + rcu_read_lock(); l3proto = __nf_ct_l3proto_find(tuple->src.l3num); ret = ctnetlink_dump_tuples_ip(skb, &m, l3proto); - - if (unlikely(ret < 0)) - goto nla_put_failure; - - l4proto = __nf_ct_l4proto_find(tuple->src.l3num, tuple->dst.protonum); + if (ret >= 0) { + l4proto = __nf_ct_l4proto_find(tuple->src.l3num, + tuple->dst.protonum); ret = ctnetlink_dump_tuples_proto(skb, &m, l4proto); + } + rcu_read_unlock(); + if (unlikely(ret < 0)) goto nla_put_failure;