Skip to contentSkip to conversation

netfilter fixes for 2.6.37

PATCH In review [email protected] 2 participants 5 messages Jan 11, 2011

Subsystems (4)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover netfilter fixes for 2.6.37

From: Pablo Neira Ayuso <[email protected]>

Hi David,

The following patchset contains Netfilter bugfixes for 2.6.37.

You can pull them from:

git://1984.lsi.us.es/net-2.6 master

Please, apply!

Eric Dumazet (1):
netfilter: x_tables: dont block BH while reading counters

Florian Westphal (1):
netfilter: ebtables: make broute table work again

Stephen Hemminger (1):
netfilter: fix race in conntrack between dump_table and destroy

 include/linux/if_bridge.h            |    2 +-
 include/linux/netfilter/x_tables.h   |   10 ++++----
 net/ipv4/netfilter/arp_tables.c      |   45 ++++++++++-----------------------
 net/ipv4/netfilter/ip_tables.c       |   45 ++++++++++-----------------------
 net/ipv6/netfilter/ip6_tables.c      |   45 ++++++++++-----------------------
 net/netfilter/nf_conntrack_netlink.c |   14 ++++-------
 net/netfilter/x_tables.c             |    3 +-
 7 files changed, 55 insertions(+), 109 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 netfilter: x_tables: dont block BH while reading counters

From: Eric Dumazet <[email protected]>

Using "iptables -L" with a lot of rules have a too big BH latency. Jesper mentioned ~6 ms and worried of frame drops.

Switch to a per_cpu seqlock scheme, so that taking a snapshot of counters doesnt need to block BH (for this cpu, but also other cpus).

This adds two increments on seqlock sequence per ipt_do_table() call, its a reasonable cost for allowing "iptables -L" not block BH processing.

---
 include/linux/netfilter/x_tables.h |   10 ++++----
 net/ipv4/netfilter/arp_tables.c    |   45 +++++++++++------------------------
 net/ipv4/netfilter/ip_tables.c     |   45 +++++++++++------------------------
 net/ipv6/netfilter/ip6_tables.c    |   45 +++++++++++------------------------
 net/netfilter/x_tables.c           |    3 +-
 5 files changed, 49 insertions(+), 99 deletions(-)
include/linux/netfilter/x_tables.h +5 -5
index 742bec0..6712e71 100644
@@ -472,7 +472,7 @@ extern void xt_free_table_info(struct xt_table_info *info);
  *  necessary for reading the counters.
  */
 struct xt_info_lock {
-	spinlock_t lock;
+	seqlock_t lock;
 	unsigned char readers;
 };
 DECLARE_PER_CPU(struct xt_info_lock, xt_info_locks);
@@ -497,7 +497,7 @@ static inline void xt_info_rdlock_bh(void)
 	local_bh_disable();
 	lock = &__get_cpu_var(xt_info_locks);
 	if (likely(!lock->readers++))
-		spin_lock(&lock->lock);
+		write_seqlock(&lock->lock);
 }
 
 static inline void xt_info_rdunlock_bh(void)
@@ -505,7 +505,7 @@ static inline void xt_info_rdunlock_bh(void)
 	struct xt_info_lock *lock = &__get_cpu_var(xt_info_locks);
 
 	if (likely(!--lock->readers))
-		spin_unlock(&lock->lock);
+		write_sequnlock(&lock->lock);
 	local_bh_enable();
 }
 
@@ -516,12 +516,12 @@ static inline void xt_info_rdunlock_bh(void)
  */
 static inline void xt_info_wrlock(unsigned int cpu)
 {
-	spin_lock(&per_cpu(xt_info_locks, cpu).lock);
+	write_seqlock(&per_cpu(xt_info_locks, cpu).lock);
 }
 
 static inline void xt_info_wrunlock(unsigned int cpu)
 {
-	spin_unlock(&per_cpu(xt_info_locks, cpu).lock);
+	write_sequnlock(&per_cpu(xt_info_locks, cpu).lock);
 }
 
 /*
net/ipv4/netfilter/arp_tables.c +14 -31

70 lines not on this page · raw message

net/ipv4/netfilter/ip_tables.c +14 -31

70 lines not on this page · raw message

net/ipv6/netfilter/ip6_tables.c +14 -31

70 lines not on this page · raw message

net/netfilter/x_tables.c +2 -1
index 8046350..c942376 100644
@@ -1325,7 +1325,8 @@ static int __init xt_init(void)
 
 	for_each_possible_cpu(i) {
 		struct xt_info_lock *lock = &per_cpu(xt_info_locks, i);
-		spin_lock_init(&lock->lock);
+
+		seqlock_init(&lock->lock);
 		lock->readers = 0;
 	}
 
Signature · 1 line
1.7.2.3
author maintainer
#2 lore raw

PATCH 2/3 netfilter: fix race in conntrack between dump_table and destroy

In reply to [email protected]

From: Stephen Hemminger <[email protected]>

The netlink interface to dump the connection tracking table has a race when entries are deleted at the same time. A customer reported a crash and the backtrace showed thatctnetlink_dump_table was running while a conntrack entry was being destroyed.
(see https://bugzilla.vyatta.com/show_bug.cgi?id=6402).

According to RCU documentation, when using hlist_nulls the reader must handle the case of seeing a deleted entry and not proceed further down the linked list. The old code would continue which caused the scan to walk into the free list.

This patch uses locking (rather than RCU) for this operation which is guaranteed safe, and no longer requires getting reference while doing dump operation.

---
 net/netfilter/nf_conntrack_netlink.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
net/netfilter/nf_conntrack_netlink.c +5 -9
index 7461402..5cb8d30 100644
@@ -645,25 +645,23 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 	struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
 	u_int8_t l3proto = nfmsg->nfgen_family;
 
-	rcu_read_lock();
+	spin_lock_bh(&nf_conntrack_lock);
 	last = (struct nf_conn *)cb->args[1];
 	for (; cb->args[0] < net->ct.htable_size; cb->args[0]++) {
 restart:
-		hlist_nulls_for_each_entry_rcu(h, n, &net->ct.hash[cb->args[0]],
+		hlist_nulls_for_each_entry(h, n, &net->ct.hash[cb->args[0]],
 					 hnnode) {
 			if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
 				continue;
 			ct = nf_ct_tuplehash_to_ctrack(h);
-			if (!atomic_inc_not_zero(&ct->ct_general.use))
-				continue;
 			/* Dump entries of a given L3 protocol number.
 			 * If it is not specified, ie. l3proto == 0,
 			 * then dump everything. */
 			if (l3proto && nf_ct_l3num(ct) != l3proto)
-				goto releasect;
+				continue;
 			if (cb->args[1]) {
 				if (ct != last)
-					goto releasect;
+					continue;
 				cb->args[1] = 0;
 			}
 			if (ctnetlink_fill_info(skb, NETLINK_CB(cb->skb).pid,
@@ -681,8 +679,6 @@ restart:
 				if (acct)
 					memset(acct, 0, sizeof(struct nf_conn_counter[IP_CT_DIR_MAX]));
 			}
-releasect:
-		nf_ct_put(ct);
 		}
 		if (cb->args[1]) {
 			cb->args[1] = 0;
@@ -690,7 +686,7 @@ releasect:
 		}
 	}
 out:
-	rcu_read_unlock();
+	spin_unlock_bh(&nf_conntrack_lock);
 	if (last)
 		nf_ct_put(last);
 
Signature · 1 line
1.7.2.3
author maintainer
#3 lore raw

PATCH 3/3 netfilter: ebtables: make broute table work again

In reply to [email protected]

From: Florian Westphal <[email protected]>

broute table init hook sets up the "br_should_route_hook" pointer, which then gets called from br_input.

commit a386f99025f13b32502fe5dedf223c20d7283826 (bridge: add proper RCU annotation to should_route_hook) introduced a typedef, and then changed this to:

br_should_route_hook_t *rhook;
[..]
rhook = rcu_dereference(br_should_route_hook);
if (*rhook(skb))

problem is that "br_should_route_hook" contains the address of the function, so calling *rhook() results in kernel panic.

---
 include/linux/if_bridge.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/if_bridge.h +1 -1
index f7e73c3..dd3f201 100644
@@ -103,7 +103,7 @@ struct __fdb_entry {
 
 extern void brioctl_set(int (*ioctl_hook)(struct net *, unsigned int, void __user *));
 
-typedef int (*br_should_route_hook_t)(struct sk_buff *skb);
+typedef int br_should_route_hook_t(struct sk_buff *skb);
 extern br_should_route_hook_t __rcu *br_should_route_hook;
 
 #endif
Signature · 1 line
1.7.2.3