Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_conntrack: set conntrack templates again if we return NF_REPEAT

The TCP tracking code has a special case that allows to return
NF_REPEAT if we receive a new SYN packet while in TIME_WAIT state.

In this situation, the TCP tracking code destroys the existing
conntrack to start a new clean session.

[DESTROY] tcp 6 src=192.168.0.2 dst=192.168.1.2 sport=38925 dport=8000 src=192.168.1.2 dst=192.168.1.100 sport=8000 dport=38925 [ASSURED]
[NEW] tcp 6 120 SYN_SENT src=192.168.0.2 dst=192.168.1.2 sport=38925 dport=8000 [UNREPLIED] src=192.168.1.2 dst=192.168.1.100 sport=8000 dport=38925

However, this is a problem for the iptables' CT target event filtering
which will not work in this case since the conntrack template will not
be there for the new session. To fix this, we reassign the conntrack
template to the packet if we return NF_REPEAT.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>

authored by

Pablo Neira Ayuso and committed by
Patrick McHardy
c3174286 3db7e93d

+9 -2
+9 -2
net/netfilter/nf_conntrack_core.c
··· 942 942 if (set_reply && !test_and_set_bit(IPS_SEEN_REPLY_BIT, &ct->status)) 943 943 nf_conntrack_event_cache(IPCT_REPLY, ct); 944 944 out: 945 - if (tmpl) 946 - nf_ct_put(tmpl); 945 + if (tmpl) { 946 + /* Special case: we have to repeat this hook, assign the 947 + * template again to this packet. We assume that this packet 948 + * has no conntrack assigned. This is used by nf_ct_tcp. */ 949 + if (ret == NF_REPEAT) 950 + skb->nfct = (struct nf_conntrack *)tmpl; 951 + else 952 + nf_ct_put(tmpl); 953 + } 947 954 948 955 return ret; 949 956 }