netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] netfilter: netfilter fixes for -rc1
@ 2011-06-16 19:41 kaber
  2011-06-16 19:41 ` [PATCH 1/6] IPVS netns exit causes crash in conntrack kaber
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: kaber @ 2011-06-16 19:41 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

Hi Dave,

the following patches fix a couple of netfilter bugs:

- an IPVS/netns shutdown related crash in conntrack, from Hans

- avoidance of double sequence number adjustment on loopback with
  NAT to fix data corruption issues, from Julian

- a fix for the protocol check in the ECN match: in addition to the
  protocol it needs to check for inversion, from myself

- a fix for missing inversion in the ECN IP header matching, from
  myself

- a compile for for ip_tables with debugging enabled, from
  Sebastian Andrzej Siewior

Please apply or pull from:

git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-2.6.git master

Thanks!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/6] IPVS netns exit causes crash in conntrack
  2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
@ 2011-06-16 19:41 ` kaber
  2011-06-16 19:41 ` [PATCH 2/6] netfilter: ip_tables: fix compile with debug kaber
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: kaber @ 2011-06-16 19:41 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Hans Schillstrom <hans.schillstrom@ericsson.com>

Quote from Patric Mc Hardy
"This looks like nfnetlink.c excited and destroyed the nfnl socket, but
ip_vs was still holding a reference to a conntrack. When the conntrack
got destroyed it created a ctnetlink event, causing an oops in
netlink_has_listeners when trying to use the destroyed nfnetlink
socket."

If nf_conntrack_netlink is loaded before ip_vs this is not a problem.

This patch simply avoids calling ip_vs_conn_drop_conntrack()
when netns is dying as suggested by Julian.

Signed-off-by: Hans Schillstrom <hans.schillstrom@ericsson.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
---
 net/netfilter/ipvs/ip_vs_conn.c |   10 +++++++++-
 net/netfilter/ipvs/ip_vs_core.c |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index bf28ac2..782db27 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -776,8 +776,16 @@ static void ip_vs_conn_expire(unsigned long data)
 		if (cp->control)
 			ip_vs_control_del(cp);
 
-		if (cp->flags & IP_VS_CONN_F_NFCT)
+		if (cp->flags & IP_VS_CONN_F_NFCT) {
 			ip_vs_conn_drop_conntrack(cp);
+			/* Do not access conntracks during subsys cleanup
+			 * because nf_conntrack_find_get can not be used after
+			 * conntrack cleanup for the net.
+			 */
+			smp_rmb();
+			if (ipvs->enable)
+				ip_vs_conn_drop_conntrack(cp);
+		}
 
 		ip_vs_pe_put(cp->pe);
 		kfree(cp->pe_data);
diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 55af224..24c28d2 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -1945,6 +1945,7 @@ static void __net_exit __ip_vs_dev_cleanup(struct net *net)
 {
 	EnterFunction(2);
 	net_ipvs(net)->enable = 0;	/* Disable packet reception */
+	smp_wmb();
 	__ip_vs_sync_cleanup(net);
 	LeaveFunction(2);
 }
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/6] netfilter: ip_tables: fix compile with debug
  2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
  2011-06-16 19:41 ` [PATCH 1/6] IPVS netns exit causes crash in conntrack kaber
@ 2011-06-16 19:41 ` kaber
  2011-06-16 19:41 ` [PATCH 3/6] netfilter: ipt_ecn: fix protocol check in ecn_mt_check() kaber
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: kaber @ 2011-06-16 19:41 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>

Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/ip_tables.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index 7647438..24e556e 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -566,7 +566,7 @@ check_entry(const struct ipt_entry *e, const char *name)
 	const struct xt_entry_target *t;
 
 	if (!ip_checkentry(&e->ip)) {
-		duprintf("ip check failed %p %s.\n", e, par->match->name);
+		duprintf("ip check failed %p %s.\n", e, name);
 		return -EINVAL;
 	}
 
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/6] netfilter: ipt_ecn: fix protocol check in ecn_mt_check()
  2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
  2011-06-16 19:41 ` [PATCH 1/6] IPVS netns exit causes crash in conntrack kaber
  2011-06-16 19:41 ` [PATCH 2/6] netfilter: ip_tables: fix compile with debug kaber
@ 2011-06-16 19:41 ` kaber
  2011-06-16 19:41 ` [PATCH 4/6] netfilter: ipt_ecn: fix inversion for IP header ECN match kaber
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: kaber @ 2011-06-16 19:41 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Patrick McHardy <kaber@trash.net>

Check for protocol inversion in ecn_mt_check() and remove the
unnecessary runtime check for IPPROTO_TCP in ecn_mt().

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/ipt_ecn.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/netfilter/ipt_ecn.c b/net/ipv4/netfilter/ipt_ecn.c
index af6e9c7..aaa85be 100644
--- a/net/ipv4/netfilter/ipt_ecn.c
+++ b/net/ipv4/netfilter/ipt_ecn.c
@@ -76,8 +76,6 @@ static bool ecn_mt(const struct sk_buff *skb, struct xt_action_param *par)
 			return false;
 
 	if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) {
-		if (ip_hdr(skb)->protocol != IPPROTO_TCP)
-			return false;
 		if (!match_tcp(skb, info, &par->hotdrop))
 			return false;
 	}
@@ -97,7 +95,7 @@ static int ecn_mt_check(const struct xt_mtchk_param *par)
 		return -EINVAL;
 
 	if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR) &&
-	    ip->proto != IPPROTO_TCP) {
+	    (ip->proto != IPPROTO_TCP || ip->invflags & IPT_INV_PROTO)) {
 		pr_info("cannot match TCP bits in rule for non-tcp packets\n");
 		return -EINVAL;
 	}
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/6] netfilter: ipt_ecn: fix inversion for IP header ECN match
  2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
                   ` (2 preceding siblings ...)
  2011-06-16 19:41 ` [PATCH 3/6] netfilter: ipt_ecn: fix protocol check in ecn_mt_check() kaber
@ 2011-06-16 19:41 ` kaber
  2011-06-16 19:41 ` [PATCH 5/6] netfilter: fix looped (broad|multi)cast's MAC handling kaber
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: kaber @ 2011-06-16 19:41 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Patrick McHardy <kaber@trash.net>

Userspace allows to specify inversion for IP header ECN matches, the
kernel silently accepts it, but doesn't invert the match result.

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/ipt_ecn.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/net/ipv4/netfilter/ipt_ecn.c b/net/ipv4/netfilter/ipt_ecn.c
index aaa85be..2b57e52 100644
--- a/net/ipv4/netfilter/ipt_ecn.c
+++ b/net/ipv4/netfilter/ipt_ecn.c
@@ -25,7 +25,8 @@ MODULE_LICENSE("GPL");
 static inline bool match_ip(const struct sk_buff *skb,
 			    const struct ipt_ecn_info *einfo)
 {
-	return (ip_hdr(skb)->tos & IPT_ECN_IP_MASK) == einfo->ip_ect;
+	return ((ip_hdr(skb)->tos & IPT_ECN_IP_MASK) == einfo->ip_ect) ^
+	       !!(einfo->invert & IPT_ECN_OP_MATCH_IP);
 }
 
 static inline bool match_tcp(const struct sk_buff *skb,
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/6] netfilter: fix looped (broad|multi)cast's MAC handling
  2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
                   ` (3 preceding siblings ...)
  2011-06-16 19:41 ` [PATCH 4/6] netfilter: ipt_ecn: fix inversion for IP header ECN match kaber
@ 2011-06-16 19:41 ` kaber
  2011-06-16 19:41 ` [PATCH 6/6] netfilter: nf_nat: avoid double seq_adjust for loopback kaber
  2011-06-17  1:43 ` [PATCH 0/8] netfilter: netfilter fixes for -rc1 David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: kaber @ 2011-06-16 19:41 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Nicolas Cavallari <cavallar@lri.fr>

By default, when broadcast or multicast packet are sent from a local
application, they are sent to the interface then looped by the kernel
to other local applications, going throught netfilter hooks in the
process.

These looped packet have their MAC header removed from the skb by the
kernel looping code. This confuse various netfilter's netlink queue,
netlink log and the legacy ip_queue, because they try to extract a
hardware address from these packets, but extracts a part of the IP
header instead.

This patch prevent NFQUEUE, NFLOG and ip_QUEUE to include a MAC header
if there is none in the packet.

Signed-off-by: Nicolas Cavallari <cavallar@lri.fr>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/ipv4/netfilter/ip_queue.c   |    3 ++-
 net/ipv6/netfilter/ip6_queue.c  |    3 ++-
 net/netfilter/nfnetlink_log.c   |    3 ++-
 net/netfilter/nfnetlink_queue.c |    3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
index f7f9bd7..5c9b9d9 100644
--- a/net/ipv4/netfilter/ip_queue.c
+++ b/net/ipv4/netfilter/ip_queue.c
@@ -203,7 +203,8 @@ ipq_build_packet_message(struct nf_queue_entry *entry, int *errp)
 	else
 		pmsg->outdev_name[0] = '\0';
 
-	if (entry->indev && entry->skb->dev) {
+	if (entry->indev && entry->skb->dev &&
+	    entry->skb->mac_header != entry->skb->network_header) {
 		pmsg->hw_type = entry->skb->dev->type;
 		pmsg->hw_addrlen = dev_parse_header(entry->skb,
 						    pmsg->hw_addr);
diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
index 065fe40..2493948 100644
--- a/net/ipv6/netfilter/ip6_queue.c
+++ b/net/ipv6/netfilter/ip6_queue.c
@@ -204,7 +204,8 @@ ipq_build_packet_message(struct nf_queue_entry *entry, int *errp)
 	else
 		pmsg->outdev_name[0] = '\0';
 
-	if (entry->indev && entry->skb->dev) {
+	if (entry->indev && entry->skb->dev &&
+	    entry->skb->mac_header != entry->skb->network_header) {
 		pmsg->hw_type = entry->skb->dev->type;
 		pmsg->hw_addrlen = dev_parse_header(entry->skb, pmsg->hw_addr);
 	}
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index e0ee010..2e7ccbb 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -456,7 +456,8 @@ __build_packet_message(struct nfulnl_instance *inst,
 	if (skb->mark)
 		NLA_PUT_BE32(inst->skb, NFULA_MARK, htonl(skb->mark));
 
-	if (indev && skb->dev) {
+	if (indev && skb->dev &&
+	    skb->mac_header != skb->network_header) {
 		struct nfulnl_msg_packet_hw phw;
 		int len = dev_parse_header(skb, phw.hw_addr);
 		if (len > 0) {
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index b83123f..fdd2faf 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -335,7 +335,8 @@ nfqnl_build_packet_message(struct nfqnl_instance *queue,
 	if (entskb->mark)
 		NLA_PUT_BE32(skb, NFQA_MARK, htonl(entskb->mark));
 
-	if (indev && entskb->dev) {
+	if (indev && entskb->dev &&
+	    entskb->mac_header != entskb->network_header) {
 		struct nfqnl_msg_packet_hw phw;
 		int len = dev_parse_header(entskb, phw.hw_addr);
 		if (len) {
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/6] netfilter: nf_nat: avoid double seq_adjust for loopback
  2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
                   ` (4 preceding siblings ...)
  2011-06-16 19:41 ` [PATCH 5/6] netfilter: fix looped (broad|multi)cast's MAC handling kaber
@ 2011-06-16 19:41 ` kaber
  2011-06-17  1:43 ` [PATCH 0/8] netfilter: netfilter fixes for -rc1 David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: kaber @ 2011-06-16 19:41 UTC (permalink / raw)
  To: davem; +Cc: netfilter-devel, netdev

From: Julian Anastasov <ja@ssi.bg>

	Avoid double seq adjustment for loopback traffic
because it causes silent repetition of TCP data. One
example is passive FTP with DNAT rule and difference in the
length of IP addresses.

	This patch adds check if packet is sent and
received via loopback device. As the same conntrack is
used both for outgoing and incoming direction, we restrict
seq adjustment to happen only in POSTROUTING.

Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 include/net/netfilter/nf_conntrack.h           |    6 ++++++
 net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c |    4 +++-
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index c7c42e7..5d4f8e5 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -307,6 +307,12 @@ static inline int nf_ct_is_untracked(const struct nf_conn *ct)
 	return test_bit(IPS_UNTRACKED_BIT, &ct->status);
 }
 
+/* Packet is received from loopback */
+static inline bool nf_is_loopback_packet(const struct sk_buff *skb)
+{
+	return skb->dev && skb->skb_iif && skb->dev->flags & IFF_LOOPBACK;
+}
+
 extern int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp);
 extern unsigned int nf_conntrack_htable_size;
 extern unsigned int nf_conntrack_max;
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index db10075..de9da21 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -121,7 +121,9 @@ static unsigned int ipv4_confirm(unsigned int hooknum,
 		return ret;
 	}
 
-	if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status)) {
+	/* adjust seqs for loopback traffic only in outgoing direction */
+	if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
+	    !nf_is_loopback_packet(skb)) {
 		typeof(nf_nat_seq_adjust_hook) seq_adjust;
 
 		seq_adjust = rcu_dereference(nf_nat_seq_adjust_hook);
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/8] netfilter: netfilter fixes for -rc1
  2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
                   ` (5 preceding siblings ...)
  2011-06-16 19:41 ` [PATCH 6/6] netfilter: nf_nat: avoid double seq_adjust for loopback kaber
@ 2011-06-17  1:43 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2011-06-17  1:43 UTC (permalink / raw)
  To: kaber; +Cc: netfilter-devel, netdev

From: kaber@trash.net
Date: Thu, 16 Jun 2011 21:41:35 +0200

> Please apply or pull from:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-2.6.git master

Pulled, thanks Patrick.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-06-17  1:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-16 19:41 [PATCH 0/8] netfilter: netfilter fixes for -rc1 kaber
2011-06-16 19:41 ` [PATCH 1/6] IPVS netns exit causes crash in conntrack kaber
2011-06-16 19:41 ` [PATCH 2/6] netfilter: ip_tables: fix compile with debug kaber
2011-06-16 19:41 ` [PATCH 3/6] netfilter: ipt_ecn: fix protocol check in ecn_mt_check() kaber
2011-06-16 19:41 ` [PATCH 4/6] netfilter: ipt_ecn: fix inversion for IP header ECN match kaber
2011-06-16 19:41 ` [PATCH 5/6] netfilter: fix looped (broad|multi)cast's MAC handling kaber
2011-06-16 19:41 ` [PATCH 6/6] netfilter: nf_nat: avoid double seq_adjust for loopback kaber
2011-06-17  1:43 ` [PATCH 0/8] netfilter: netfilter fixes for -rc1 David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).