Skip to contentSkip to conversation

fix conntrack event cache deadlock

NETFILTER Applied Harald Welte 2 participants 3 messages Sep 22, 2005 – Sep 23, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Dave, please apply the following fix.

(Bug #2 exists even in pre-2.6.14 kernels, but I don't think it's such a serious problem, so I won't provide a fix for -stable.)

[NETFILTER] Fix conntrack event cache deadlock/oops

This patch fixes a number of bugs. It cannot be reasonably split up in multiple fixes, since all bugs interact with each other and affect the same function:

Bug #1:
The event cache code cannot be called while a lock is held. Therefore, the call to ip_conntrack_event_cache() within ip_ct_refresh_acct() needs to be moved outside of the locked section. This fixes a number of 2.6.14-rcX oops and deadlock reports.

Bug #2:
We used to call ct_add_counters() for unconfirmed connections without holding a lock. Since the add operations are not atomic, we could race with another CPU.

Bug #3:
ip_ct_refresh_acct() lost REFRESH events in some cases where refresh (and the corresponding event) are desired, but no accounting shall be performed. Both, evenst and accounting implicitly depended on the skb
parameter bein non-null. We now re-introduce a non-accounting
"ip_ct_refresh()" variant to explicitly state the desired behaviour.

---
commit 0410f33b62b892379270539b189577126ea56ffe
tree 2031dcce6de02d10246d9fdc390e11e8f29a6c7b
parent fa304068f77ddce6ff01d48f1033d176a6e0ab5f
author Harald Welte <[email protected]> Do, 22 Sep 2005 16:30:22 +0200 committer Harald Welte <[email protected]> Do, 22 Sep 2005 16:30:22 +0200

 include/linux/netfilter_ipv4/ip_conntrack.h   |   25 +++++++++++--
 net/ipv4/netfilter/ip_conntrack_amanda.c      |    2 +
 net/ipv4/netfilter/ip_conntrack_core.c        |   49 +++++++++++++------------
 net/ipv4/netfilter/ip_conntrack_helper_pptp.c |    1 -
 net/ipv4/netfilter/ip_conntrack_netbios_ns.c  |    2 +
 net/ipv4/netfilter/ip_conntrack_standalone.c  |    2 +
 6 files changed, 49 insertions(+), 32 deletions(-)
include/linux/netfilter_ipv4/ip_conntrack.h +21 -4
@@ -332,11 +332,28 @@ extern void need_ip_conntrack(void);
 extern int invert_tuplepr(struct ip_conntrack_tuple *inverse,
 			  const struct ip_conntrack_tuple *orig);
 
+extern void __ip_ct_refresh_acct(struct ip_conntrack *ct,
+			         enum ip_conntrack_info ctinfo,
+			         const struct sk_buff *skb,
+			         unsigned long extra_jiffies,
+				 int do_acct);
+
+/* Refresh conntrack for this many jiffies and do accounting */
+static inline void ip_ct_refresh_acct(struct ip_conntrack *ct, 
+				      enum ip_conntrack_info ctinfo,
+				      const struct sk_buff *skb,
+				      unsigned long extra_jiffies)
+{
+	__ip_ct_refresh_acct(ct, ctinfo, skb, extra_jiffies, 1);
+}
+
 /* Refresh conntrack for this many jiffies */
-extern void ip_ct_refresh_acct(struct ip_conntrack *ct,
-			       enum ip_conntrack_info ctinfo,
-			       const struct sk_buff *skb,
-			       unsigned long extra_jiffies);
+static inline void ip_ct_refresh(struct ip_conntrack *ct,
+				 const struct sk_buff *skb,
+				 unsigned long extra_jiffies)
+{
+	__ip_ct_refresh_acct(ct, 0, skb, extra_jiffies, 0);
+}
 
 /* These are for NAT.  Icky. */
 /* Update TCP window tracking data when NAT mangles the packet */
net/ipv4/netfilter/ip_conntrack_amanda.c +1 -1
@@ -65,7 +65,7 @@ static int help(struct sk_buff **pskb,
 
 	/* increase the UDP timeout of the master connection as replies from
 	 * Amanda clients to the server can be quite delayed */
-	ip_ct_refresh_acct(ct, ctinfo, NULL, master_timeout * HZ);
+	ip_ct_refresh(ct, *pskb, master_timeout * HZ);
 
 	/* No data? */
 	dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr);
net/ipv4/netfilter/ip_conntrack_core.c +25 -24

70 lines not on this page · raw message

net/ipv4/netfilter/ip_conntrack_helper_pptp.c +0 -1
@@ -172,7 +172,6 @@ static int destroy_sibling_or_exp(const 
 		DEBUGP("setting timeout of conntrack %p to 0\n", sibling);
 		sibling->proto.gre.timeout = 0;
 		sibling->proto.gre.stream_timeout = 0;
-		/* refresh_acct will not modify counters if skb == NULL */
 		if (del_timer(&sibling->timeout))
 			sibling->timeout.function((unsigned long)sibling);
 		ip_conntrack_put(sibling);
net/ipv4/netfilter/ip_conntrack_netbios_ns.c +1 -1
@@ -91,7 +91,7 @@ static int help(struct sk_buff **pskb,
 	ip_conntrack_expect_related(exp);
 	ip_conntrack_expect_put(exp);
 
-	ip_ct_refresh_acct(ct, ctinfo, NULL, timeout * HZ);
+	ip_ct_refresh(ct, *pskb, timeout * HZ);
 out:
 	return NF_ACCEPT;
 }
net/ipv4/netfilter/ip_conntrack_standalone.c +1 -1
@@ -989,7 +989,7 @@ EXPORT_SYMBOL(need_ip_conntrack);
 EXPORT_SYMBOL(ip_conntrack_helper_register);
 EXPORT_SYMBOL(ip_conntrack_helper_unregister);
 EXPORT_SYMBOL(ip_ct_iterate_cleanup);
-EXPORT_SYMBOL(ip_ct_refresh_acct);
+EXPORT_SYMBOL(__ip_ct_refresh_acct);
 
 EXPORT_SYMBOL(ip_conntrack_expect_alloc);
 EXPORT_SYMBOL(ip_conntrack_expect_put);
Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
maintainer Applied
#1 lore raw

From: Harald Welte <[email protected]>
Date: Thu, 22 Sep 2005 16:35:15 +0200

Quoted 1 line

[NETFILTER] Fix conntrack event cache deadlock/oops

Applied. I hope that doing the event cache call outside the lock is safe? It was not depending upon that protection in any way was it?

Thanks Harald.

#2 lore raw
Quoted 8 lines · David S. Miller

From: Harald Welte <[email protected]>
Date: Thu, 22 Sep 2005 16:35:15 +0200

Quoted 1 line

[NETFILTER] Fix conntrack event cache deadlock/oops

Applied. I hope that doing the event cache call outside the lock is safe? It was not depending upon that protection in any way was it?

no, not at all. It was a mistake to call it within the locked section. The call was erroneously placed there, because it fitted there without reorganizing the code flow.

Signature · 5 lines
- Harald Welte <[email protected]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie