Skip to contentSkip to conversation

netfilter stable fixes for 3.7

PATCH In review [email protected] 3 participants 19 messages Jan 28, 2013 – Feb 1, 2013 netfilter

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover netfilter stable fixes for 3.7

From: Pablo Neira Ayuso <[email protected]>

This patchset contain netfilter stable fixes for 3.7, original commits (in no particular order) are:

0c36b48 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels e035edd netfilter: nfnetlink_log: fix possible compilation issue due to missing include 665e205 netfilter: xt_recent: fix namespace destroy path
2727de7 netfilter: xt_recent: avoid high order page allocations
5b76c49 netfilter: x_tables: print correct hook names for ARP
4fe198e netfilter: ipset: Fix range bug in hash:ip,port,net
c6f4089 netfilter: ip[6]t_REJECT: fix wrong transport header pointer in TCP reset 32263dd netfilter: xt_hashlimit: fix namespace destroy path
0918184 netfilter: xt_hashlimit: fix race that results in duplicated entries 1310b95 netfilter: ctnetlink: fix leak in error path of ctnetlink_create_expect 97cf00e netfilter: nf_ct_reasm: fix conntrack reassembly expire code 10db906 netfilter: xt_CT: recover NOTRACK target support
757ae31 netfilter: fix missing dependencies for the NOTRACK target 1e47ee8 netfilter: nf_conntrack: fix BUG_ON while removing nf_conntrack with netns

Please, apply. Thanks!

Bob Hockney (1):
netfilter: nfnetlink_log: fix mac address for 6in4 tunnels

Eric Dumazet (1):
netfilter: xt_recent: avoid high order page allocations

Haibo Xi (1):
netfilter: nf_ct_reasm: fix conntrack reassembly expire code

Jan Engelhardt (1):
netfilter: x_tables: print correct hook names for ARP

Jesper Juhl (1):
netfilter: ctnetlink: fix leak in error path of ctnetlink_create_expect

Mukund Jampala (1):
netfilter: ip[6]t_REJECT: fix wrong transport header pointer in TCP reset

Pablo Neira Ayuso (6):
netfilter: nfnetlink_log: fix possible compilation issue due to missing include
netfilter: xt_CT: recover NOTRACK target support
netfilter: fix missing dependencies for the NOTRACK target
netfilter: xt_hashlimit: fix race that results in duplicated entries
netfilter: xt_CT: fix unset return value if conntrack zone are disabled
netfilter: nf_conntrack: fix BUG_ON while removing nf_conntrack with netns

Vitaly E. Lavrov (2):
netfilter: xt_recent: fix namespace destroy path
netfilter: xt_hashlimit: fix namespace destroy path

 include/net/netfilter/nf_conntrack_core.h |    2 ++
 include/net/netns/x_tables.h              |    1 +
 net/ipv4/netfilter/ipt_REJECT.c           |    1 +
 net/ipv6/netfilter/ip6t_REJECT.c          |    1 +
 net/ipv6/netfilter/nf_conntrack_reasm.c   |    5 ++-
 net/netfilter/Kconfig                     |    7 ++++
 net/netfilter/nf_conntrack_core.c         |    9 ++---
 net/netfilter/nf_conntrack_netlink.c      |    2 +-
 net/netfilter/nf_conntrack_standalone.c   |    1 +
 net/netfilter/nfnetlink_log.c             |   16 +++++++--
 net/netfilter/x_tables.c                  |   28 ++++++++++-----
 net/netfilter/xt_CT.c                     |   54 +++++++++++++++++++++++++++--
 net/netfilter/xt_hashlimit.c              |   54 ++++++++++++++++++++++++-----
 net/netfilter/xt_recent.c                 |   43 ++++++++++++++++++-----
 14 files changed, 187 insertions(+), 37 deletions(-)

--
1.7.10.4

author maintainer
#1 lore raw

PATCH 1/14 netfilter: ip[6]t_REJECT: fix wrong transport header pointer in TCP reset

From: Mukund Jampala <[email protected]>

The problem occurs when iptables constructs the tcp reset packet. It doesn't initialize the pointer to the tcp header within the skb. When the skb is passed to the ixgbe driver for transmit, the ixgbe driver attempts to access the tcp header and crashes. Currently, other drivers (such as our 1G e1000e or igb drivers) don't access the tcp header on transmit unless the TSO option is turned on.

<1>BUG: unable to handle kernel NULL pointer dereference at 0000000d <1>IP: [<d081621c>] ixgbe_xmit_frame_ring+0x8cc/0x2260 [ixgbe] <4>*pdpt = 0000000085e5d001 *pde = 0000000000000000
<0>Oops: 0000 [#1] SMP
[...]
<4>Pid: 0, comm: swapper Tainted: P 2.6.35.12 #1 Greencity/Thurley
<4>EIP: 0060:[<d081621c>] EFLAGS: 00010246 CPU: 16
<4>EIP is at ixgbe_xmit_frame_ring+0x8cc/0x2260 [ixgbe]
<4>EAX: c7628820 EBX: 00000007 ECX: 00000000 EDX: 00000000 <4>ESI: 00000008 EDI: c6882180 EBP: dfc6b000 ESP: ced95c48
<4> DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
<0>Process swapper (pid: 0, ti=ced94000 task=ced73bd0 task.ti=ced94000) <0>Stack:
<4> cbec7418 c779e0d8 c77cc888 c77cc8a8 0903010a 00000000 c77c0008 00000002 <4><0> cd4997c0 00000010 dfc6b000 00000000 d0d176c9 c77cc8d8 c6882180 cbec7318 <4><0> 00000004 00000004 cbec7230 cbec7110 00000000 cbec70c0 c779e000 00000002 <0>Call Trace:
<4> [<d0d176c9>] ? 0xd0d176c9
<4> [<d0d18a4d>] ? 0xd0d18a4d
<4> [<411e243e>] ? dev_hard_start_xmit+0x218/0x2d7
<4> [<411f03d7>] ? sch_direct_xmit+0x4b/0x114
<4> [<411f056a>] ? __qdisc_run+0xca/0xe0
<4> [<411e28b0>] ? dev_queue_xmit+0x2d1/0x3d0
<4> [<411e8120>] ? neigh_resolve_output+0x1c5/0x20f
<4> [<411e94a1>] ? neigh_update+0x29c/0x330
<4> [<4121cf29>] ? arp_process+0x49c/0x4cd
<4> [<411f80c9>] ? nf_hook_slow+0x3f/0xac
<4> [<4121ca8d>] ? arp_process+0x0/0x4cd
<4> [<4121ca8d>] ? arp_process+0x0/0x4cd
<4> [<4121c6d5>] ? T.901+0x38/0x3b
<4> [<4121c918>] ? arp_rcv+0xa3/0xb4
<4> [<4121ca8d>] ? arp_process+0x0/0x4cd
<4> [<411e1173>] ? __netif_receive_skb+0x32b/0x346
<4> [<411e19e1>] ? netif_receive_skb+0x5a/0x5f
<4> [<411e1ea9>] ? napi_skb_finish+0x1b/0x30
<4> [<d0816eb4>] ? ixgbe_xmit_frame_ring+0x1564/0x2260 [ixgbe] <4> [<41013468>] ? lapic_next_event+0x13/0x16
<4> [<410429b2>] ? clockevents_program_event+0xd2/0xe4
<4> [<411e1b03>] ? net_rx_action+0x55/0x127
<4> [<4102da1a>] ? __do_softirq+0x77/0xeb
<4> [<4102dab1>] ? do_softirq+0x23/0x27
<4> [<41003a67>] ? do_IRQ+0x7d/0x8e
<4> [<41002a69>] ? common_interrupt+0x29/0x30
<4> [<41007bcf>] ? mwait_idle+0x48/0x4d
<4> [<4100193b>] ? cpu_idle+0x37/0x4c
<0>Code: df 09 d7 0f 94 c2 0f b6 d2 e9 e7 fb ff ff 31 db 31 c0 e9 38 ff ff ff 80 78 06 06 0f 85 3e fb ff ff 8b 7c 24 38 8b 8f b8 00 00 00 <0f> b6 51 0d f6 c2 01 0f 85 27 fb ff ff 80 e2 02 75 0d 8b 6c 24 <0>EIP: [<d081621c>] ixgbe_xmit_frame_ring+0x8cc/0x2260 [ixgbe] SS:ESP

---
 net/ipv4/netfilter/ipt_REJECT.c  |    1 +
 net/ipv6/netfilter/ip6t_REJECT.c |    1 +
 2 files changed, 2 insertions(+)
net/ipv4/netfilter/ipt_REJECT.c +1 -0
index 51f13f8..04b18c1 100644
@@ -81,6 +81,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
 	niph->saddr	= oiph->daddr;
 	niph->daddr	= oiph->saddr;
 
+	skb_reset_transport_header(nskb);
 	tcph = (struct tcphdr *)skb_put(nskb, sizeof(struct tcphdr));
 	memset(tcph, 0, sizeof(*tcph));
 	tcph->source	= oth->dest;
net/ipv6/netfilter/ip6t_REJECT.c +1 -0
index fd4fb34..029623d 100644
@@ -132,6 +132,7 @@ static void send_reset(struct net *net, struct sk_buff *oldskb)
 	ip6h->saddr = oip6h->daddr;
 	ip6h->daddr = oip6h->saddr;
 
+	skb_reset_transport_header(nskb);
 	tcph = (struct tcphdr *)skb_put(nskb, sizeof(struct tcphdr));
 	/* Truncate to length (no data) */
 	tcph->doff = sizeof(struct tcphdr)/4;
Signature · 1 line
1.7.10.4
author maintainer
#2 lore raw

PATCH 2/14 netfilter: nf_ct_reasm: fix conntrack reassembly expire code

In reply to [email protected]

From: Haibo Xi <[email protected]>

Commit b836c99fd6c9 (ipv6: unify conntrack reassembly expire code with standard one) use the standard IPv6 reassembly code(ip6_expire_frag_queue) to handle conntrack reassembly expire.

In ip6_expire_frag_queue, it invoke dev_get_by_index_rcu to get which device received this expired packet.so we must save ifindex when NF_conntrack get this packet.

With this patch applied, I can see ICMP Time Exceeded sent from the receiver when the sender sent out 1/2 fragmented IPv6 packet.

---
 net/ipv6/netfilter/nf_conntrack_reasm.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv6/netfilter/nf_conntrack_reasm.c +4 -1
index 22c8ea9..3dacecc 100644
@@ -311,7 +311,10 @@ found:
 	else
 		fq->q.fragments = skb;
 
-	skb->dev = NULL;
+	if (skb->dev) {
+		fq->iif = skb->dev->ifindex;
+		skb->dev = NULL;
+	}
 	fq->q.stamp = skb->tstamp;
 	fq->q.meat += skb->len;
 	if (payload_len > fq->q.max_size)
Signature · 1 line
1.7.10.4
author maintainer
#3 lore raw

PATCH 3/14 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels

In reply to [email protected]

From: Bob Hockney <[email protected]>

For tunnelled ipv6in4 packets, the LOG target (xt_LOG.c) adjusts the start of the mac field to start at the ethernet header instead of the ipv4 header for the tunnel. This patch conforms what is passed by the NFLOG target through nfnetlink to what the LOG target does. Code borrowed from xt_LOG.c.

---
 net/netfilter/nfnetlink_log.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_log.c +12 -3
index 9f199f2..4e210e0 100644
@@ -384,6 +384,7 @@ __build_packet_message(struct nfulnl_instance *inst,
 	struct nfgenmsg *nfmsg;
 	sk_buff_data_t old_tail = inst->skb->tail;
 	struct sock *sk;
+	const unsigned char *hwhdrp;
 
 	nlh = nlmsg_put(inst->skb, 0, 0,
 			NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET,
@@ -485,9 +486,17 @@ __build_packet_message(struct nfulnl_instance *inst,
 	if (indev && skb_mac_header_was_set(skb)) {
 		if (nla_put_be16(inst->skb, NFULA_HWTYPE, htons(skb->dev->type)) ||
 		    nla_put_be16(inst->skb, NFULA_HWLEN,
-				 htons(skb->dev->hard_header_len)) ||
-		    nla_put(inst->skb, NFULA_HWHEADER, skb->dev->hard_header_len,
-			    skb_mac_header(skb)))
+				 htons(skb->dev->hard_header_len)))
+			goto nla_put_failure;
+
+		hwhdrp = skb_mac_header(skb);
+
+		if (skb->dev->type == ARPHRD_SIT)
+			hwhdrp -= ETH_HLEN;
+
+		if (hwhdrp >= skb->head &&
+		    nla_put(inst->skb, NFULA_HWHEADER,
+			    skb->dev->hard_header_len, hwhdrp))
 			goto nla_put_failure;
 	}
 
Signature · 1 line
1.7.10.4
author maintainer
#4 lore raw

PATCH 4/14 netfilter: nfnetlink_log: fix possible compilation issue due to missing include

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

In (0c36b48 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels) the include file that defines ARPD_SIT was missing. This passed unnoticed during my tests (I did not hit this problem here).

net/netfilter/nfnetlink_log.c: In function '__build_packet_message':
net/netfilter/nfnetlink_log.c:494:25: error: 'ARPHRD_SIT' undeclared (first use in this function) net/netfilter/nfnetlink_log.c:494:25: note: each undeclared identifier is reported only once for +each function it appears in

---
 net/netfilter/nfnetlink_log.c |    1 +
 1 file changed, 1 insertion(+)
net/netfilter/nfnetlink_log.c +1 -0
index 4e210e0..92fd8ec 100644
@@ -13,6 +13,7 @@
  */
 #include <linux/module.h>
 #include <linux/skbuff.h>
+#include <linux/if_arp.h>
 #include <linux/init.h>
 #include <linux/ip.h>
 #include <linux/ipv6.h>
Signature · 1 line
1.7.10.4
author maintainer
#5 lore raw

PATCH 5/14 netfilter: xt_CT: recover NOTRACK target support

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

Florian Westphal reported that the removal of the NOTRACK target (9655050 netfilter: remove xt_NOTRACK) is breaking some existing setups.

That removal was scheduled for removal since long time ago as described in Documentation/feature-removal-schedule.txt

What:  xt_NOTRACK
Files: net/netfilter/xt_NOTRACK.c
When:  April 2011
Why:   Superseded by xt_CT

Still, people may have not notice / may have decided to stick to an old iptables version. I agree with him in that some more conservative approach by spotting some printk to warn users for some time is less agressive.

Current iptables 1.4.16.3 already contains the aliasing support that makes it point to the CT target, so upgrading would fix it. Still, the policy so far has been to avoid pushing our users to upgrade.

As a solution, this patch recovers the NOTRACK target inside the CT target and it now spots a warning.

---
 include/net/netns/x_tables.h |    1 +
 net/netfilter/Kconfig        |    4 ++++
 net/netfilter/xt_CT.c        |   50 +++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 54 insertions(+), 1 deletion(-)
include/net/netns/x_tables.h +1 -0
index 591db7d..c24060e 100644
@@ -8,6 +8,7 @@ struct ebt_table;
 
 struct netns_xt {
 	struct list_head tables[NFPROTO_NUMPROTO];
+	bool notrack_deprecated_warning;
 #if defined(CONFIG_BRIDGE_NF_EBTABLES) || \
     defined(CONFIG_BRIDGE_NF_EBTABLES_MODULE)
 	struct ebt_table *broute_table;
net/netfilter/Kconfig +4 -0
index fefa514..390f96c 100644
@@ -680,6 +680,10 @@ config NETFILTER_XT_TARGET_NFQUEUE
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NETFILTER_XT_TARGET_NOTRACK
+	tristate  '"NOTRACK" target support (DEPRECATED)'
+	select NETFILTER_XT_TARGET_CT
+
 config NETFILTER_XT_TARGET_RATEEST
 	tristate '"RATEEST" target support'
 	depends on NETFILTER_ADVANCED
net/netfilter/xt_CT.c +49 -1

66 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author maintainer
#6 lore raw

PATCH 6/14 netfilter: fix missing dependencies for the NOTRACK target

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

warning: (NETFILTER_XT_TARGET_NOTRACK) selects NETFILTER_XT_TARGET_CT which has unmet direct +dependencies (NET && INET && NETFILTER && NETFILTER_XTABLES && NF_CONNTRACK && (IP_NF_RAW || +IP6_NF_RAW) && NETFILTER_ADVANCED)

---
 net/netfilter/Kconfig |    3 +++
 1 file changed, 3 insertions(+)
net/netfilter/Kconfig +3 -0
index 390f96c..49e96df 100644
@@ -682,6 +682,9 @@ config NETFILTER_XT_TARGET_NFQUEUE
 
 config NETFILTER_XT_TARGET_NOTRACK
 	tristate  '"NOTRACK" target support (DEPRECATED)'
+	depends on NF_CONNTRACK
+	depends on IP_NF_RAW || IP6_NF_RAW
+	depends on NETFILTER_ADVANCED
 	select NETFILTER_XT_TARGET_CT
 
 config NETFILTER_XT_TARGET_RATEEST
Signature · 1 line
1.7.10.4
author maintainer
#7 lore raw

PATCH 7/14 netfilter: xt_recent: fix namespace destroy path

In reply to [email protected]

From: "Vitaly E. Lavrov" <[email protected]>

recent_net_exit() is called before recent_mt_destroy() in the destroy path of network namespaces. Make sure there are no entries in the parent proc entry xt_recent before removing it.

---
 net/netfilter/xt_recent.c |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
net/netfilter/xt_recent.c +16 -4
index 4635c9b..dab053e 100644
@@ -431,7 +431,8 @@ static void recent_mt_destroy(const struct xt_mtdtor_param *par)
 		list_del(&t->list);
 		spin_unlock_bh(&recent_lock);
 #ifdef CONFIG_PROC_FS
-		remove_proc_entry(t->name, recent_net->xt_recent);
+		if (recent_net->xt_recent != NULL)
+			remove_proc_entry(t->name, recent_net->xt_recent);
 #endif
 		recent_table_flush(t);
 		kfree(t);
@@ -615,6 +616,20 @@ static int __net_init recent_proc_net_init(struct net *net)
 
 static void __net_exit recent_proc_net_exit(struct net *net)
 {
+	struct recent_net *recent_net = recent_pernet(net);
+	struct recent_table *t;
+
+	/* recent_net_exit() is called before recent_mt_destroy(). Make sure
+	 * that the parent xt_recent proc entry is is empty before trying to
+	 * remove it.
+	 */
+	spin_lock_bh(&recent_lock);
+	list_for_each_entry(t, &recent_net->tables, list)
+	        remove_proc_entry(t->name, recent_net->xt_recent);
+
+	recent_net->xt_recent = NULL;
+	spin_unlock_bh(&recent_lock);
+
 	proc_net_remove(net, "xt_recent");
 }
 #else
@@ -638,9 +653,6 @@ static int __net_init recent_net_init(struct net *net)
 
 static void __net_exit recent_net_exit(struct net *net)
 {
-	struct recent_net *recent_net = recent_pernet(net);
-
-	BUG_ON(!list_empty(&recent_net->tables));
 	recent_proc_net_exit(net);
 }
 
Signature · 1 line
1.7.10.4
author maintainer
#8 lore raw

PATCH 8/14 netfilter: xt_recent: avoid high order page allocations

In reply to [email protected]

From: Eric Dumazet <[email protected]>

xt_recent can try high order page allocations and this can fail.

iptables: page allocation failure: order:9, mode:0xc0d0

It also wastes about half the allocated space because of kmalloc() power-of-two roundups and struct recent_table layout.

Use vmalloc() instead to save space and be less prone to allocation errors when memory is fragmented.

---
 net/netfilter/xt_recent.c |   23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
net/netfilter/xt_recent.c +18 -5
index dab053e..978efc9 100644
@@ -29,6 +29,7 @@
 #include <linux/skbuff.h>
 #include <linux/inet.h>
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
 
@@ -310,6 +311,14 @@ out:
 	return ret;
 }
 
+static void recent_table_free(void *addr)
+{
+	if (is_vmalloc_addr(addr))
+		vfree(addr);
+	else
+		kfree(addr);
+}
+
 static int recent_mt_check(const struct xt_mtchk_param *par,
 			   const struct xt_recent_mtinfo_v1 *info)
 {
@@ -322,6 +331,7 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
 #endif
 	unsigned int i;
 	int ret = -EINVAL;
+	size_t sz;
 
 	if (unlikely(!hash_rnd_inited)) {
 		get_random_bytes(&hash_rnd, sizeof(hash_rnd));
@@ -360,8 +370,11 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
 		goto out;
 	}
 
-	t = kzalloc(sizeof(*t) + sizeof(t->iphash[0]) * ip_list_hash_size,
-		    GFP_KERNEL);
+	sz = sizeof(*t) + sizeof(t->iphash[0]) * ip_list_hash_size;
+	if (sz <= PAGE_SIZE)
+		t = kzalloc(sz, GFP_KERNEL);
+	else
+		t = vzalloc(sz);
 	if (t == NULL) {
 		ret = -ENOMEM;
 		goto out;
@@ -377,14 +390,14 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
 	uid = make_kuid(&init_user_ns, ip_list_uid);
 	gid = make_kgid(&init_user_ns, ip_list_gid);
 	if (!uid_valid(uid) || !gid_valid(gid)) {
-		kfree(t);
+		recent_table_free(t);
 		ret = -EINVAL;
 		goto out;
 	}
 	pde = proc_create_data(t->name, ip_list_perms, recent_net->xt_recent,
 		  &recent_mt_fops, t);
 	if (pde == NULL) {
-		kfree(t);
+		recent_table_free(t);
 		ret = -ENOMEM;
 		goto out;
 	}
@@ -435,7 +448,7 @@ static void recent_mt_destroy(const struct xt_mtdtor_param *par)
 			remove_proc_entry(t->name, recent_net->xt_recent);
 #endif
 		recent_table_flush(t);
-		kfree(t);
+		recent_table_free(t);
 	}
 	mutex_unlock(&recent_mutex);
 }
Signature · 1 line
1.7.10.4
author maintainer
#9 lore raw

PATCH 9/14 netfilter: xt_hashlimit: fix namespace destroy path

In reply to [email protected]

From: "Vitaly E. Lavrov" <[email protected]>

recent_net_exit() is called before recent_mt_destroy() in the destroy path of network namespaces. Make sure there are no entries in the parent proc entry xt_recent before removing it.

---
 net/netfilter/xt_hashlimit.c |   29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
net/netfilter/xt_hashlimit.c +25 -4
index 26a668a..30ad0b62 100644
@@ -318,7 +318,10 @@ static void htable_destroy(struct xt_hashlimit_htable *hinfo)
 		parent = hashlimit_net->ipt_hashlimit;
 	else
 		parent = hashlimit_net->ip6t_hashlimit;
-	remove_proc_entry(hinfo->pde->name, parent);
+
+	if(parent != NULL)
+		remove_proc_entry(hinfo->pde->name, parent);
+
 	htable_selective_cleanup(hinfo, select_all);
 	vfree(hinfo);
 }
@@ -856,6 +859,27 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
 
 static void __net_exit hashlimit_proc_net_exit(struct net *net)
 {
+	struct xt_hashlimit_htable *hinfo;
+	struct hlist_node *pos;
+	struct proc_dir_entry *pde;
+	struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
+
+	/* recent_net_exit() is called before recent_mt_destroy(). Make sure
+	 * that the parent xt_recent proc entry is is empty before trying to
+	 * remove it.
+	 */
+	mutex_lock(&hashlimit_mutex);
+	pde = hashlimit_net->ipt_hashlimit;
+	if (pde == NULL)
+		pde = hashlimit_net->ip6t_hashlimit;
+
+	hlist_for_each_entry(hinfo, pos, &hashlimit_net->htables, node)
+		remove_proc_entry(hinfo->pde->name, pde);
+
+	hashlimit_net->ipt_hashlimit = NULL;
+	hashlimit_net->ip6t_hashlimit = NULL;
+	mutex_unlock(&hashlimit_mutex);
+
 	proc_net_remove(net, "ipt_hashlimit");
 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
 	proc_net_remove(net, "ip6t_hashlimit");
@@ -872,9 +896,6 @@ static int __net_init hashlimit_net_init(struct net *net)
 
 static void __net_exit hashlimit_net_exit(struct net *net)
 {
-	struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
-
-	BUG_ON(!hlist_empty(&hashlimit_net->htables));
 	hashlimit_proc_net_exit(net);
 }
 
Signature · 1 line
1.7.10.4
author maintainer
#10 lore raw

PATCH 10/14 netfilter: xt_hashlimit: fix race that results in duplicated entries

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

Two packets may race to create the same entry in the hashtable, double check if this packet lost race. This double checking only happens in the path of the packet that creates the hashtable for first time.

Note that, with this patch, no packet drops occur if the race happens.

---
 net/netfilter/xt_hashlimit.c |   25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)
net/netfilter/xt_hashlimit.c +21 -4
index 30ad0b62..a9d7af9 100644
@@ -157,11 +157,22 @@ dsthash_find(const struct xt_hashlimit_htable *ht,
 /* allocate dsthash_ent, initialize dst, put in htable and lock it */
 static struct dsthash_ent *
 dsthash_alloc_init(struct xt_hashlimit_htable *ht,
-		   const struct dsthash_dst *dst)
+		   const struct dsthash_dst *dst, bool *race)
 {
 	struct dsthash_ent *ent;
 
 	spin_lock(&ht->lock);
+
+	/* Two or more packets may race to create the same entry in the
+	 * hashtable, double check if this packet lost race.
+	 */
+	ent = dsthash_find(ht, dst);
+	if (ent != NULL) {
+		spin_unlock(&ht->lock);
+		*race = true;
+		return ent;
+	}
+
 	/* initialize hash with random val at the time we allocate
 	 * the first hashtable entry */
 	if (unlikely(!ht->rnd_initialized)) {
@@ -588,6 +599,7 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	unsigned long now = jiffies;
 	struct dsthash_ent *dh;
 	struct dsthash_dst dst;
+	bool race = false;
 	u32 cost;
 
 	if (hashlimit_init_dst(hinfo, &dst, skb, par->thoff) < 0)
@@ -596,13 +608,18 @@ hashlimit_mt(const struct sk_buff *skb, struct xt_action_param *par)
 	rcu_read_lock_bh();
 	dh = dsthash_find(hinfo, &dst);
 	if (dh == NULL) {
-		dh = dsthash_alloc_init(hinfo, &dst);
+		dh = dsthash_alloc_init(hinfo, &dst, &race);
 		if (dh == NULL) {
 			rcu_read_unlock_bh();
 			goto hotdrop;
+		} else if (race) {
+			/* Already got an entry, update expiration timeout */
+			dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire);
+			rateinfo_recalc(dh, now, hinfo->cfg.mode);
+		} else {
+			dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire);
+			rateinfo_init(dh, hinfo);
 		}
-		dh->expires = jiffies + msecs_to_jiffies(hinfo->cfg.expire);
-		rateinfo_init(dh, hinfo);
 	} else {
 		/* update expiration timeout */
 		dh->expires = now + msecs_to_jiffies(hinfo->cfg.expire);
Signature · 1 line
1.7.10.4
author maintainer
#11 lore raw

PATCH 11/14 netfilter: xt_CT: fix unset return value if conntrack zone are disabled

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

net/netfilter/xt_CT.c: In function ‘xt_ct_tg_check_v1’:
net/netfilter/xt_CT.c:250:6: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized] net/netfilter/xt_CT.c: In function ‘xt_ct_tg_check_v0’:
net/netfilter/xt_CT.c:112:6: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]

---
 net/netfilter/xt_CT.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/xt_CT.c +2 -2
index aeeaf5c..8461605 100644
@@ -109,7 +109,7 @@ static int xt_ct_tg_check_v0(const struct xt_tgchk_param *par)
 	struct xt_ct_target_info *info = par->targinfo;
 	struct nf_conntrack_tuple t;
 	struct nf_conn *ct;
-	int ret;
+	int ret = -EOPNOTSUPP;
 
 	if (info->flags & ~XT_CT_NOTRACK)
 		return -EINVAL;
@@ -243,7 +243,7 @@ static int xt_ct_tg_check_v1(const struct xt_tgchk_param *par)
 	struct xt_ct_target_info_v1 *info = par->targinfo;
 	struct nf_conntrack_tuple t;
 	struct nf_conn *ct;
-	int ret;
+	int ret = -EOPNOTSUPP;
 
 	if (info->flags & ~XT_CT_NOTRACK)
 		return -EINVAL;
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#12 lore raw

PATCH 12/14 netfilter: nf_conntrack: fix BUG_ON while removing nf_conntrack with netns

In reply to [email protected]

From: Pablo Neira Ayuso <[email protected]>

canqun zhang reported that we're hitting BUG_ON in the nf_conntrack_destroy path when calling kfree_skb while rmmod'ing the nf_conntrack module.

Currently, the nf_ct_destroy hook is being set to NULL in the destroy path of conntrack.init_net. However, this is a problem since init_net may be destroyed before any other existing netns (we cannot assume any specific ordering while releasing existing netns according to what I read in recent emails).

Thanks to Gao feng for initial patch to address this issue.

---
 include/net/netfilter/nf_conntrack_core.h |    2 ++
 net/netfilter/nf_conntrack_core.c         |    9 +++++----
 net/netfilter/nf_conntrack_standalone.c   |    1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
include/net/netfilter/nf_conntrack_core.h +2 -0
index d8f5b9f..e98aeb3 100644
@@ -31,6 +31,8 @@ extern void nf_conntrack_cleanup(struct net *net);
 extern int nf_conntrack_proto_init(struct net *net);
 extern void nf_conntrack_proto_fini(struct net *net);
 
+extern void nf_conntrack_cleanup_end(void);
+
 extern bool
 nf_ct_get_tuple(const struct sk_buff *skb,
 		unsigned int nhoff,
net/netfilter/nf_conntrack_core.c +5 -4
index 0f241be..ec02168 100644
@@ -1383,11 +1383,12 @@ void nf_conntrack_cleanup(struct net *net)
 	synchronize_net();
 	nf_conntrack_proto_fini(net);
 	nf_conntrack_cleanup_net(net);
+}
 
-	if (net_eq(net, &init_net)) {
-		RCU_INIT_POINTER(nf_ct_destroy, NULL);
-		nf_conntrack_cleanup_init_net();
-	}
+void nf_conntrack_cleanup_end(void)
+{
+	RCU_INIT_POINTER(nf_ct_destroy, NULL);
+	nf_conntrack_cleanup_init_net();
 }
 
 void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
net/netfilter/nf_conntrack_standalone.c +1 -0
index 9b39432..df8aa3a 100644
@@ -571,6 +571,7 @@ static int __init nf_conntrack_standalone_init(void)
 static void __exit nf_conntrack_standalone_fini(void)
 {
 	unregister_pernet_subsys(&nf_conntrack_net_ops);
+	nf_conntrack_cleanup_end();
 }
 
 module_init(nf_conntrack_standalone_init);
Signature · 1 line
1.7.10.4
author maintainer
#13 lore raw

PATCH 13/14 netfilter: x_tables: print correct hook names for ARP

In reply to [email protected]

From: Jan Engelhardt <[email protected]>

arptables 0.0.4 (released on 10th Jan 2013) supports calling the CLASSIFY target, but on adding a rule to the wrong chain, the diagnostic is as follows:

	# arptables -A INPUT -j CLASSIFY --set-class 0:0
	arptables: Invalid argument
	# dmesg | tail -n1
	x_tables: arp_tables: CLASSIFY target: used from hooks
	PREROUTING, but only usable from INPUT/FORWARD

This is incorrect, since xt_CLASSIFY.c does specify (1 << NF_ARP_OUT) | (1 << NF_ARP_FORWARD).

This patch corrects the x_tables diagnostic message to print the proper hook names for the NFPROTO_ARP case.

Affects all kernels down to and including v2.6.31.

---
 net/netfilter/x_tables.c |   28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
net/netfilter/x_tables.c +20 -8
index 8d987c3..7b3a9e5 100644
@@ -345,19 +345,27 @@ int xt_find_revision(u8 af, const char *name, u8 revision, int target,
 }
 EXPORT_SYMBOL_GPL(xt_find_revision);
 
-static char *textify_hooks(char *buf, size_t size, unsigned int mask)
+static char *
+textify_hooks(char *buf, size_t size, unsigned int mask, uint8_t nfproto)
 {
-	static const char *const names[] = {
+	static const char *const inetbr_names[] = {
 		"PREROUTING", "INPUT", "FORWARD",
 		"OUTPUT", "POSTROUTING", "BROUTING",
 	};
-	unsigned int i;
+	static const char *const arp_names[] = {
+		"INPUT", "FORWARD", "OUTPUT",
+	};
+	const char *const *names;
+	unsigned int i, max;
 	char *p = buf;
 	bool np = false;
 	int res;
 
+	names = (nfproto == NFPROTO_ARP) ? arp_names : inetbr_names;
+	max   = (nfproto == NFPROTO_ARP) ? ARRAY_SIZE(arp_names) :
+	                                   ARRAY_SIZE(inetbr_names);
 	*p = '\0';
-	for (i = 0; i < ARRAY_SIZE(names); ++i) {
+	for (i = 0; i < max; ++i) {
 		if (!(mask & (1 << i)))
 			continue;
 		res = snprintf(p, size, "%s%s", np ? "/" : "", names[i]);
@@ -402,8 +410,10 @@ int xt_check_match(struct xt_mtchk_param *par,
 		pr_err("%s_tables: %s match: used from hooks %s, but only "
 		       "valid from %s\n",
 		       xt_prefix[par->family], par->match->name,
-		       textify_hooks(used, sizeof(used), par->hook_mask),
-		       textify_hooks(allow, sizeof(allow), par->match->hooks));
+		       textify_hooks(used, sizeof(used), par->hook_mask,
+		                     par->family),
+		       textify_hooks(allow, sizeof(allow), par->match->hooks,
+		                     par->family));
 		return -EINVAL;
 	}
 	if (par->match->proto && (par->match->proto != proto || inv_proto)) {
@@ -575,8 +585,10 @@ int xt_check_target(struct xt_tgchk_param *par,
 		pr_err("%s_tables: %s target: used from hooks %s, but only "
 		       "usable from %s\n",
 		       xt_prefix[par->family], par->target->name,
-		       textify_hooks(used, sizeof(used), par->hook_mask),
-		       textify_hooks(allow, sizeof(allow), par->target->hooks));
+		       textify_hooks(used, sizeof(used), par->hook_mask,
+		                     par->family),
+		       textify_hooks(allow, sizeof(allow), par->target->hooks,
+		                     par->family));
 		return -EINVAL;
 	}
 	if (par->target->proto && (par->target->proto != proto || inv_proto)) {
Signature · 1 line
1.7.10.4
author maintainer
#14 lore raw

PATCH 14/14 netfilter: ctnetlink: fix leak in error path of ctnetlink_create_expect

In reply to [email protected]

From: Jesper Juhl <[email protected]>

This patch fixes a leak in one of the error paths of ctnetlink_create_expect if no helper and no timeout is specified.

---
 net/netfilter/nf_conntrack_netlink.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +1 -1
index 7bbfb3d..ef9e86e 100644
@@ -2514,7 +2514,7 @@ ctnetlink_create_expect(struct net *net, u16 zone,
 	if (!help) {
 		if (!cda[CTA_EXPECT_TIMEOUT]) {
 			err = -EINVAL;
-			goto out;
+			goto err_out;
 		}
 		exp->timeout.expires =
 		  jiffies + ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) * HZ;
Signature · 1 line
1.7.10.4
#15 lore raw
In reply to [email protected]

From: [email protected]
Date: Mon, 28 Jan 2013 20:31:19 +0100

Quoted 20 lines

From: Pablo Neira Ayuso <[email protected]>

This patchset contain netfilter stable fixes for 3.7, original commits (in no particular order) are:

0c36b48 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels e035edd netfilter: nfnetlink_log: fix possible compilation issue due to missing include 665e205 netfilter: xt_recent: fix namespace destroy path
2727de7 netfilter: xt_recent: avoid high order page allocations
5b76c49 netfilter: x_tables: print correct hook names for ARP
4fe198e netfilter: ipset: Fix range bug in hash:ip,port,net
c6f4089 netfilter: ip[6]t_REJECT: fix wrong transport header pointer in TCP reset 32263dd netfilter: xt_hashlimit: fix namespace destroy path
0918184 netfilter: xt_hashlimit: fix race that results in duplicated entries 1310b95 netfilter: ctnetlink: fix leak in error path of ctnetlink_create_expect 97cf00e netfilter: nf_ct_reasm: fix conntrack reassembly expire code 10db906 netfilter: xt_CT: recover NOTRACK target support
757ae31 netfilter: fix missing dependencies for the NOTRACK target 1e47ee8 netfilter: nf_conntrack: fix BUG_ON while removing nf_conntrack with netns

Quoted 1 line

Please, apply. Thanks!

These all look fine to me for -stable.

#16 lore raw
In reply to [email protected]
Quoted 11 lines · On Mon, Jan 28, 2013 at 08:31:19PM +0100, [email protected] wrote:

From: Pablo Neira Ayuso <[email protected]>

This patchset contain netfilter stable fixes for 3.7, original commits (in no particular order) are:

0c36b48 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels e035edd netfilter: nfnetlink_log: fix possible compilation issue due to missing include 665e205 netfilter: xt_recent: fix namespace destroy path
2727de7 netfilter: xt_recent: avoid high order page allocations
5b76c49 netfilter: x_tables: print correct hook names for ARP
4fe198e netfilter: ipset: Fix range bug in hash:ip,port,net

This patch didn't apply as a straight 'git cherrypick', so I didn't take it. You also didn't send it, so something is odd here.

Quoted 10 lines

c6f4089 netfilter: ip[6]t_REJECT: fix wrong transport header pointer in TCP reset 32263dd netfilter: xt_hashlimit: fix namespace destroy path
0918184 netfilter: xt_hashlimit: fix race that results in duplicated entries 1310b95 netfilter: ctnetlink: fix leak in error path of ctnetlink_create_expect 97cf00e netfilter: nf_ct_reasm: fix conntrack reassembly expire code 10db906 netfilter: xt_CT: recover NOTRACK target support
757ae31 netfilter: fix missing dependencies for the NOTRACK target 1e47ee8 netfilter: nf_conntrack: fix BUG_ON while removing nf_conntrack with netns

Please, apply. Thanks!

In the future, please put the git commit ids in the patches you send, I had to match them up by hand and put them into the patch.

I've only applied 13 patches, so I know I've messed something up, can you take a look at what I've applied and let me know what I missed?

thanks,

greg k-h

author maintainer
#17 lore raw

Hi Greg,

Quoted 13 lines · Greg KH
Quoted 11 lines · On Mon, Jan 28, 2013 at 08:31:19PM +0100, [email protected] wrote:

From: Pablo Neira Ayuso <[email protected]>

This patchset contain netfilter stable fixes for 3.7, original commits (in no particular order) are:

0c36b48 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels e035edd netfilter: nfnetlink_log: fix possible compilation issue due to missing include 665e205 netfilter: xt_recent: fix namespace destroy path
2727de7 netfilter: xt_recent: avoid high order page allocations
5b76c49 netfilter: x_tables: print correct hook names for ARP
4fe198e netfilter: ipset: Fix range bug in hash:ip,port,net

Quoted 2 lines

This patch didn't apply as a straight 'git cherrypick', so I didn't take it. You also didn't send it, so something is odd here.

My fault, sorry, that slipped through the list but it should be this instead:

6bbc7f3 netfilter: xt_CT: fix unset return value if conntrack zone are disabled

http://patchwork.ozlabs.org/patch/216343/

I send it to you as patch 11/14.

I can resend it if that makes things easier.

Quoted 9 lines
Quoted 9 lines

c6f4089 netfilter: ip[6]t_REJECT: fix wrong transport header pointer in TCP reset 32263dd netfilter: xt_hashlimit: fix namespace destroy path
0918184 netfilter: xt_hashlimit: fix race that results in duplicated entries 1310b95 netfilter: ctnetlink: fix leak in error path of ctnetlink_create_expect 97cf00e netfilter: nf_ct_reasm: fix conntrack reassembly expire code 10db906 netfilter: xt_CT: recover NOTRACK target support
757ae31 netfilter: fix missing dependencies for the NOTRACK target 1e47ee8 netfilter: nf_conntrack: fix BUG_ON while removing nf_conntrack with netns

Quoted 4 lines
Quoted 1 line

Please, apply. Thanks!

In the future, please put the git commit ids in the patches you send, I had to match them up by hand and put them into the patch.

Will do that in the future, thanks!

#18 lore raw
Quoted 16 lines · Pablo Neira Ayuso

Hi Greg,

Quoted 13 lines · Greg KH
Quoted 11 lines · On Mon, Jan 28, 2013 at 08:31:19PM +0100, [email protected] wrote:

From: Pablo Neira Ayuso <[email protected]>

This patchset contain netfilter stable fixes for 3.7, original commits (in no particular order) are:

0c36b48 netfilter: nfnetlink_log: fix mac address for 6in4 tunnels e035edd netfilter: nfnetlink_log: fix possible compilation issue due to missing include 665e205 netfilter: xt_recent: fix namespace destroy path
2727de7 netfilter: xt_recent: avoid high order page allocations
5b76c49 netfilter: x_tables: print correct hook names for ARP
4fe198e netfilter: ipset: Fix range bug in hash:ip,port,net

Quoted 7 lines
Quoted 2 lines

This patch didn't apply as a straight 'git cherrypick', so I didn't take it. You also didn't send it, so something is odd here.

My fault, sorry, that slipped through the list but it should be this instead:

6bbc7f3 netfilter: xt_CT: fix unset return value if conntrack zone are disabled

That commit id doesn't match up with any git commit id that I can find in Linus's tree. Are you sure you git it right?

Quoted 5 lines

http://patchwork.ozlabs.org/patch/216343/

I send it to you as patch 11/14.

I can resend it if that makes things easier.

Please do, along with the correct git commit id for the patch.

thanks,

greg k-h