Skip to contentSkip to conversation

netfilter: SYNPROXY: fix process non tcp packet bug in {ipv4,ipv6}_synproxy_hook

PATCH Applied Lin Zhang 2 participants 3 messages Sep 30, 2017 – Oct 3, 2017

Subsystems (3)

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore

Lin Zhang

author
#0 lore raw

PATCH v2 1/1 netfilter: SYNPROXY: fix process non tcp packet bug in {ipv4,ipv6}_synproxy_hook

In function {ipv4,ipv6}_synproxy_hook we expect a normal tcp packet, but the real server maybe reply an icmp error packet related to the exist tcp conntrack, so we will access wrong tcp data.

For fix it, check for the protocol field and only process tcp traffic.

---
changelog:

v1 -> v2:
* we only deal with TCP traffic, per Pablo Neira.

---
 net/ipv4/netfilter/ipt_SYNPROXY.c  | 3 ++-
 net/ipv6/netfilter/ip6t_SYNPROXY.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/netfilter/ipt_SYNPROXY.c +2 -1
index 811689e..13bec90 100644
@@ -330,7 +330,8 @@ static unsigned int ipv4_synproxy_hook(void *priv,
 	if (synproxy == NULL)
 		return NF_ACCEPT;
 
-	if (nf_is_loopback_packet(skb))
+	if (nf_is_loopback_packet(skb) ||
+	    ip_hdr(skb)->protocol != IPPROTO_TCP)
 		return NF_ACCEPT;
 
 	thoff = ip_hdrlen(skb);
net/ipv6/netfilter/ip6t_SYNPROXY.c +2 -1
index a5cd43d..af19c16 100644
@@ -347,7 +347,8 @@ static unsigned int ipv6_synproxy_hook(void *priv,
 	if (synproxy == NULL)
 		return NF_ACCEPT;
 
-	if (nf_is_loopback_packet(skb))
+	if (nf_is_loopback_packet(skb) ||
+	    ipv6_hdr(skb)->protocol != IPPROTO_TCP)
 		return NF_ACCEPT;
 
 	nexthdr = ipv6_hdr(skb)->nexthdr;
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Lin Zhang

In function {ipv4,ipv6}_synproxy_hook we expect a normal tcp packet, but the real server maybe reply an icmp error packet related to the exist tcp conntrack, so we will access wrong tcp data.

For fix it, check for the protocol field and only process tcp traffic.

Applied, thanks.

I have made minor comestic changes to patch title:

netfilter: SYNPROXY: skip non-TCP packets from {ipv4,ipv6}_synproxy_hook

for the record.

#2 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 5 lines · Lin Zhang

In function {ipv4,ipv6}_synproxy_hook we expect a normal tcp packet, but the real server maybe reply an icmp error packet related to the exist tcp conntrack, so we will access wrong tcp data.

For fix it, check for the protocol field and only process tcp traffic.

Quoted 7 lines

Applied, thanks.

I have made minor comestic changes to patch title:

netfilter: SYNPROXY: skip non-TCP packets from {ipv4,ipv6}_synproxy_hook

for the record.

I have to keep this back, sorry.

This has been not compiled tested.

net/ipv6/netfilter/ip6t_SYNPROXY.c: In function ‘ipv6_synproxy_hook’:
net/ipv6/netfilter/ip6t_SYNPROXY.c:351:19: error: ‘struct ipv6hdr’ has no member named ‘protocol’

      ipv6_hdr(skb)->protocol != IPPROTO_TCP)
                   ^