Skip to contentSkip to conversation

netfilter updates for net-next

PATCH In review Pablo Neira Ayuso 2 participants 6 messages Sep 4, 2013

Subsystems (3)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

cover netfilter updates for net-next

Hi David,

The following batch contains:

* Three fixes for the new synproxy target available in your net-next tree, from Jesper D. Brouer and Patrick McHardy.

* One fix for TCPMSS to correctly handling the fragmentation case, from Phil Oester. I'll pass this one to -stable.

You can pull this changes from:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master

Thanks!

----------------------------------------------------------------

The following changes since commit 5a17a390de7bdbcfff9b8f344273a886ca4cf8bf:

net: make snmp_mib_free static inline (2013-09-02 21:00:50 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master

for you to fetch changes up to 1205e1fa615805c9efa97303b552cf445965752a:

netfilter: xt_TCPMSS: correct return value in tcpmss_mangle_packet (2013-09-04 14:20:03 +0200)

----------------------------------------------------------------
Jesper Dangaard Brouer (2):
netfilter: more strict TCP flag matching in SYNPROXY
netfilter: SYNPROXY: let unrelated packets continue

Patrick McHardy (1):
netfilter: synproxy_core: fix warning in __nf_ct_ext_add_length()

Phil Oester (1):
netfilter: xt_TCPMSS: correct return value in tcpmss_mangle_packet

 net/ipv4/netfilter/ipt_SYNPROXY.c  |   10 +++++++---
 net/ipv6/netfilter/ip6t_SYNPROXY.c |   10 +++++++---
 net/netfilter/nf_synproxy_core.c   |    4 ++--
 net/netfilter/xt_TCPMSS.c          |    2 +-
 4 files changed, 17 insertions(+), 9 deletions(-)
author maintainer
#1 lore raw

PATCH 1/4 netfilter: more strict TCP flag matching in SYNPROXY

From: Jesper Dangaard Brouer <[email protected]>

Its seems Patrick missed to incoorporate some of my requested changes during review v2 of SYNPROXY netfilter module.

Which were, to avoid SYN+ACK packets to enter the path, meant for the ACK packet from the client (from the 3WHS).

Further there were a bug in ip6t_SYNPROXY.c, for matching SYN packets that didn't exclude the ACK flag.

Go a step further with SYN packet/flag matching by excluding flags ACK+FIN+RST, in both IPv4 and IPv6 modules.

The intented usage of SYNPROXY is as follows:
(gracefully describing usage in commit)

iptables -t raw -A PREROUTING -i eth0 -p tcp --dport 80 --syn -j NOTRACK

 iptables -A INPUT -i eth0 -p tcp --dport 80 -m state UNTRACKED,INVALID \
         -j SYNPROXY --sack-perm --timestamp --mss 1480 --wscale 7 --ecn

echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose

This does filter SYN flags early, for packets in the UNTRACKED state, but packets in the INVALID state with other TCP flags could still reach the module, thus this stricter flag matching is still needed.

---
 net/ipv4/netfilter/ipt_SYNPROXY.c  |    4 ++--
 net/ipv6/netfilter/ip6t_SYNPROXY.c |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
net/ipv4/netfilter/ipt_SYNPROXY.c +2 -2
index 94371db..90e489e 100644
@@ -269,7 +269,7 @@ synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 
 	synproxy_parse_options(skb, par->thoff, th, &opts);
 
-	if (th->syn && !th->ack) {
+	if (th->syn && !(th->ack || th->fin || th->rst)) {
 		/* Initial SYN from client */
 		this_cpu_inc(snet->stats->syn_received);
 
@@ -285,7 +285,7 @@ synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 					  XT_SYNPROXY_OPT_ECN);
 
 		synproxy_send_client_synack(skb, th, &opts);
-	} else if (th->ack && !(th->fin || th->rst))
+	} else if (th->ack && !(th->fin || th->rst || th->syn))
 		/* ACK from client */
 		synproxy_recv_client_ack(snet, skb, th, &opts, ntohl(th->seq));
 
net/ipv6/netfilter/ip6t_SYNPROXY.c +2 -2
index 4270a9b..a5af0bf 100644
@@ -284,7 +284,7 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 
 	synproxy_parse_options(skb, par->thoff, th, &opts);
 
-	if (th->syn) {
+	if (th->syn && !(th->ack || th->fin || th->rst)) {
 		/* Initial SYN from client */
 		this_cpu_inc(snet->stats->syn_received);
 
@@ -300,7 +300,7 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 					  XT_SYNPROXY_OPT_ECN);
 
 		synproxy_send_client_synack(skb, th, &opts);
-	} else if (th->ack && !(th->fin || th->rst))
+	} else if (th->ack && !(th->fin || th->rst || th->syn))
 		/* ACK from client */
 		synproxy_recv_client_ack(snet, skb, th, &opts, ntohl(th->seq));
 
Signature · 1 line
1.7.10.4
author maintainer
#2 lore raw

PATCH 2/4 netfilter: synproxy_core: fix warning in __nf_ct_ext_add_length()

In reply to Pablo Neira Ayuso

From: Patrick McHardy <[email protected]>

With CONFIG_NETFILTER_DEBUG we get the following warning during SYNPROXY init:

[   80.558906] WARNING: CPU: 1 PID: 4833 at net/netfilter/nf_conntrack_extend.c:80 __nf_ct_ext_add_length+0x217/0x220 [nf_conntrack]()

The reason is that the conntrack template is set to confirmed before adding the extension and it is invalid to add extensions to already confirmed conntracks. Fix by adding the extensions before setting the conntrack to confirmed.

---
 net/netfilter/nf_synproxy_core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_synproxy_core.c +2 -2
index d23dc79..6fd967c 100644
@@ -356,12 +356,12 @@ static int __net_init synproxy_net_init(struct net *net)
 		goto err1;
 	}
 
-	__set_bit(IPS_TEMPLATE_BIT, &ct->status);
-	__set_bit(IPS_CONFIRMED_BIT, &ct->status);
 	if (!nfct_seqadj_ext_add(ct))
 		goto err2;
 	if (!nfct_synproxy_ext_add(ct))
 		goto err2;
+	__set_bit(IPS_TEMPLATE_BIT, &ct->status);
+	__set_bit(IPS_CONFIRMED_BIT, &ct->status);
 
 	snet->tmpl = ct;
 
Signature · 1 line
1.7.10.4
author maintainer
#3 lore raw

PATCH 3/4 netfilter: SYNPROXY: let unrelated packets continue

In reply to Pablo Neira Ayuso

From: Jesper Dangaard Brouer <[email protected]>

Packets reaching SYNPROXY were default dropped, as they were most likely invalid (given the recommended state matching). This patch, changes SYNPROXY target to let packets, not consumed, continue being processed by the stack.

This will be more in line other target modules. As it will allow more flexible configurations of handling, logging or matching on packets in INVALID states.

---
 net/ipv4/netfilter/ipt_SYNPROXY.c  |    8 ++++++--
 net/ipv6/netfilter/ip6t_SYNPROXY.c |    8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)
net/ipv4/netfilter/ipt_SYNPROXY.c +6 -2
index 90e489e..67e17dc 100644
@@ -285,11 +285,15 @@ synproxy_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 					  XT_SYNPROXY_OPT_ECN);
 
 		synproxy_send_client_synack(skb, th, &opts);
-	} else if (th->ack && !(th->fin || th->rst || th->syn))
+		return NF_DROP;
+
+	} else if (th->ack && !(th->fin || th->rst || th->syn)) {
 		/* ACK from client */
 		synproxy_recv_client_ack(snet, skb, th, &opts, ntohl(th->seq));
+		return NF_DROP;
+	}
 
-	return NF_DROP;
+	return XT_CONTINUE;
 }
 
 static unsigned int ipv4_synproxy_hook(unsigned int hooknum,
net/ipv6/netfilter/ip6t_SYNPROXY.c +6 -2
index a5af0bf..19cfea8 100644
@@ -300,11 +300,15 @@ synproxy_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 					  XT_SYNPROXY_OPT_ECN);
 
 		synproxy_send_client_synack(skb, th, &opts);
-	} else if (th->ack && !(th->fin || th->rst || th->syn))
+		return NF_DROP;
+
+	} else if (th->ack && !(th->fin || th->rst || th->syn)) {
 		/* ACK from client */
 		synproxy_recv_client_ack(snet, skb, th, &opts, ntohl(th->seq));
+		return NF_DROP;
+	}
 
-	return NF_DROP;
+	return XT_CONTINUE;
 }
 
 static unsigned int ipv6_synproxy_hook(unsigned int hooknum,
Signature · 1 line
1.7.10.4
author maintainer
#4 lore raw

PATCH 4/4 netfilter: xt_TCPMSS: correct return value in tcpmss_mangle_packet

In reply to Pablo Neira Ayuso

From: Phil Oester <[email protected]>

In commit b396966c4 (netfilter: xt_TCPMSS: Fix missing fragmentation handling), I attempted to add safe fragment handling to xt_TCPMSS. However, Andy Padavan of Project N56U correctly points out that returning XT_CONTINUE in this function does not work. The callers (tcpmss_tg[46]) expect to receive a value of 0 in order to return XT_CONTINUE.

---
 net/netfilter/xt_TCPMSS.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_TCPMSS.c +1 -1
index 6113cc7..cd24290 100644
@@ -60,7 +60,7 @@ tcpmss_mangle_packet(struct sk_buff *skb,
 
 	/* This is a fragment, no TCP header is available */
 	if (par->fragoff != 0)
-		return XT_CONTINUE;
+		return 0;
 
 	if (!skb_make_writable(skb, skb->len))
 		return -1;
Signature · 1 line
1.7.10.4
maintainer
#5 lore raw
In reply to Pablo Neira Ayuso

From: Pablo Neira Ayuso <[email protected]>
Date: Wed, 4 Sep 2013 15:00:21 +0200

Quoted 7 lines

The following batch contains:

* Three fixes for the new synproxy target available in your net-next tree, from Jesper D. Brouer and Patrick McHardy.

* One fix for TCPMSS to correctly handling the fragmentation case, from Phil Oester. I'll pass this one to -stable.

Pulled, thanks Pablo.