diff mbox

[nf-next,4/4] netfilter: ipv6: avoid nf_iterate recursion

Message ID CANr6G5z3SYGo-f7OmKwncHFK0M01YkeWk2W9tPcQWX3LV5NEEA@mail.gmail.com
State RFC
Delegated to: Pablo Neira
Headers show

Commit Message

Joe Stringer Oct. 20, 2015, 6:25 a.m. UTC
On 17 October 2015 at 13:14, Florian Westphal <fw@strlen.de> wrote:
> @@ -606,19 +599,22 @@ struct sk_buff *nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 use
>                 spin_unlock_bh(&fq->q.lock);
>                 pr_debug("Can't insert skb to queue\n");
>                 inet_frag_put(&fq->q, &nf_frags);
> -               return skb;
> +               return -EINVAL;
>         }
>
> +       /* after queue has assumed skb ownership, only 0 or -EINPROGRESS
> +        * must be returned.
> +        */
> +       ret = -EINPROGRESS;
>         if (fq->q.flags == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
> -           fq->q.meat == fq->q.len) {
> -               ret_skb = nf_ct_frag6_reasm(fq, skb, dev);
> -               if (ret_skb == NULL)
> -                       pr_debug("Can't reassemble fragmented packets\n");
> -       }
> +           fq->q.meat == fq->q.len &&
> +           nf_ct_frag6_reasm(fq, skb, dev))
> +               ret = 0;
> +
>         spin_unlock_bh(&fq->q.lock);
>
>         inet_frag_put(&fq->q, &nf_frags);
> -       return ret_skb;
> +       return ret;
>  }
>  EXPORT_SYMBOL_GPL(nf_ct_frag6_gather);

Minor nit below, feel free to disregard if it misses some code style
guideline. The lock/unlock reads easier to me if the
unlocking/frag_put is grouped together, something like the following
incremental:

        /* after queue has assumed skb ownership, only 0 or -EINPROGRESS
@@ -611,9 +609,11 @@ int nf_ct_frag6_gather(struct net *net, struct
sk_buff *skb, u32 user)
            nf_ct_frag6_reasm(fq, skb, dev))
                ret = 0;

+unlock:
        spin_unlock_bh(&fq->q.lock);
-
        inet_frag_put(&fq->q, &nf_frags);
+       if (unlikely(ret == -EINVAL))
+               pr_debug("Can't insert skb to queue\n");
        return ret;
 }
 EXPORT_SYMBOL_GPL(nf_ct_frag6_gather);
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Florian Westphal Oct. 20, 2015, 8:18 a.m. UTC | #1
Joe Stringer <joestringer@nicira.com> wrote:
> On 17 October 2015 at 13:14, Florian Westphal <fw@strlen.de> wrote:
> > @@ -606,19 +599,22 @@ struct sk_buff *nf_ct_frag6_gather(struct net *net, struct sk_buff *skb, u32 use
> >                 spin_unlock_bh(&fq->q.lock);
> >                 pr_debug("Can't insert skb to queue\n");
> >                 inet_frag_put(&fq->q, &nf_frags);
> > -               return skb;
> > +               return -EINVAL;
> >         }
> >
> > +       /* after queue has assumed skb ownership, only 0 or -EINPROGRESS
> > +        * must be returned.
> > +        */
> > +       ret = -EINPROGRESS;
> >         if (fq->q.flags == (INET_FRAG_FIRST_IN | INET_FRAG_LAST_IN) &&
> > -           fq->q.meat == fq->q.len) {
> > -               ret_skb = nf_ct_frag6_reasm(fq, skb, dev);
> > -               if (ret_skb == NULL)
> > -                       pr_debug("Can't reassemble fragmented packets\n");
> > -       }
> > +           fq->q.meat == fq->q.len &&
> > +           nf_ct_frag6_reasm(fq, skb, dev))
> > +               ret = 0;
> > +
> >         spin_unlock_bh(&fq->q.lock);
> >
> >         inet_frag_put(&fq->q, &nf_frags);
> > -       return ret_skb;
> > +       return ret;
> >  }
> >  EXPORT_SYMBOL_GPL(nf_ct_frag6_gather);
> 
> Minor nit below, feel free to disregard if it misses some code style
> guideline. The lock/unlock reads easier to me if the
> unlocking/frag_put is grouped together, something like the following
> incremental:

I like it, will change it for v2.

Thanks!
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c
b/net/ipv6/netfilter/nf_conntrack_reasm.c
index b87dd75967d0..edfd290792f5 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -596,10 +596,8 @@  int nf_ct_frag6_gather(struct net *net, struct
sk_buff *skb, u32 user)
        spin_lock_bh(&fq->q.lock);

        if (nf_ct_frag6_queue(fq, skb, fhdr, nhoff) < 0) {
-               spin_unlock_bh(&fq->q.lock);
-               pr_debug("Can't insert skb to queue\n");
-               inet_frag_put(&fq->q, &nf_frags);
-               return -EINVAL;
+               ret = -EINVAL;
+               goto unlock;
        }