net: ipv6: rpl_iptunnel: Fix memory leak in rpl_input
authorJustin Iurman <justin.iurman@uliege.be>
Wed, 11 Sep 2024 17:45:57 +0000 (19:45 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 14 Sep 2024 02:55:49 +0000 (19:55 -0700)
Free the skb before returning from rpl_input when skb_cow_head() fails.
Use a "drop" label and goto instructions.

Fixes: a7a29f9c361f ("net: ipv6: add rpl sr tunnel")
Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20240911174557.11536-1-justin.iurman@uliege.be
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv6/rpl_iptunnel.c

index 2c83b7586422ddd2ae877f98e47698410e47b233..db3c19a42e1ca71bada33d0f776ccc42572c9f81 100644 (file)
@@ -263,10 +263,8 @@ static int rpl_input(struct sk_buff *skb)
        rlwt = rpl_lwt_lwtunnel(orig_dst->lwtstate);
 
        err = rpl_do_srh(skb, rlwt);
-       if (unlikely(err)) {
-               kfree_skb(skb);
-               return err;
-       }
+       if (unlikely(err))
+               goto drop;
 
        local_bh_disable();
        dst = dst_cache_get(&rlwt->cache);
@@ -286,9 +284,13 @@ static int rpl_input(struct sk_buff *skb)
 
        err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
        if (unlikely(err))
-               return err;
+               goto drop;
 
        return dst_input(skb);
+
+drop:
+       kfree_skb(skb);
+       return err;
 }
 
 static int nla_put_rpl_srh(struct sk_buff *skb, int attrtype,