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

netfilter: nf_conntrack: fix ct refcount leak in l4proto->error()

This patch fixes a refcount leak of ct objects that may occur if
l4proto->error() assigns one conntrack object to one skbuff. In
that case, we have to skip further processing in nf_conntrack_in().

With this patch, we can also fix wrong return values (-NF_ACCEPT)
for special cases in ICMP[v6] that should not bump the invalid/error
statistic counters.

Reported-by: Zoltan Menyhart <Zoltan.Menyhart@bull.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

+5 -2
+1 -1
net/ipv4/netfilter/nf_conntrack_proto_icmp.c
··· 160 160 /* Update skb to refer to this connection */ 161 161 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general; 162 162 skb->nfctinfo = *ctinfo; 163 - return -NF_ACCEPT; 163 + return NF_ACCEPT; 164 164 } 165 165 166 166 /* Small and modified version of icmp_rcv */
+1 -1
net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
··· 177 177 /* Update skb to refer to this connection */ 178 178 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general; 179 179 skb->nfctinfo = *ctinfo; 180 - return -NF_ACCEPT; 180 + return NF_ACCEPT; 181 181 } 182 182 183 183 static int
+3
net/netfilter/nf_conntrack_core.c
··· 922 922 ret = -ret; 923 923 goto out; 924 924 } 925 + /* ICMP[v6] protocol trackers may assign one conntrack. */ 926 + if (skb->nfct) 927 + goto out; 925 928 } 926 929 927 930 ct = resolve_normal_ct(net, tmpl, skb, dataoff, pf, protonum,