netfilter: ipv6: nf_defrag: drop mangled skb on ream error
authorFlorian Westphal <fw@strlen.de>
Tue, 29 Nov 2016 01:17:34 +0000 (02:17 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 29 Nov 2016 19:23:58 +0000 (20:23 +0100)
Dmitry Vyukov reported GPF in network stack that Andrey traced down to
negative nh offset in nf_ct_frag6_queue().

Problem is that all network headers before fragment header are pulled.
Normal ipv6 reassembly will drop the skb when errors occur further down
the line.

netfilter doesn't do this, and instead passed the original fragment
along.  That was also fine back when netfilter ipv6 defrag worked with
cloned fragments, as the original, pristine fragment was passed on.

So we either have to undo the pull op, or discard such fragments.
Since they're malformed after all (e.g. overlapping fragment) it seems
preferrable to just drop them.

Same for temporary errors -- it doesn't make sense to accept (and
perhaps forward!) only some fragments of same datagram.

Fixes: 029f7f3b8701cc7ac ("netfilter: ipv6: nf_defrag: avoid/free clone operations")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Debugged-by: Andrey Konovalov <andreyknvl@google.com>
Diagnosed-by: Eric Dumazet <Eric Dumazet <edumazet@google.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/ipv6/netfilter/nf_conntrack_reasm.c
net/ipv6/netfilter/nf_defrag_ipv6_hooks.c

index e4347aeb2e65337a1adbf82f66befc22a83c6606..9948b5ce52dad3a823edede517f17069bd7226dc 100644 (file)
@@ -576,11 +576,11 @@ int nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 user)
        /* Jumbo payload inhibits frag. header */
        if (ipv6_hdr(skb)->payload_len == 0) {
                pr_debug("payload len = 0\n");
-               return -EINVAL;
+               return 0;
        }
 
        if (find_prev_fhdr(skb, &prevhdr, &nhoff, &fhoff) < 0)
-               return -EINVAL;
+               return 0;
 
        if (!pskb_may_pull(skb, fhoff + sizeof(*fhdr)))
                return -ENOMEM;
index f7aab5ab93a558bd7d60010e15ca15169d1d0ba7..f06b0471f39fc0130f9db69e6c05330e8d5c6909 100644 (file)
@@ -69,7 +69,7 @@ static unsigned int ipv6_defrag(void *priv,
        if (err == -EINPROGRESS)
                return NF_STOLEN;
 
-       return NF_ACCEPT;
+       return err == 0 ? NF_ACCEPT : NF_DROP;
 }
 
 static struct nf_hook_ops ipv6_defrag_ops[] = {