]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: handle the return value of pskb_carve_frag_list() correctly
authorMiaohe Lin <linmiaohe@huawei.com>
Sat, 15 Aug 2020 08:46:41 +0000 (04:46 -0400)
committerDavid S. Miller <davem@davemloft.net>
Tue, 18 Aug 2020 22:56:56 +0000 (15:56 -0700)
pskb_carve_frag_list() may return -ENOMEM in pskb_carve_inside_nonlinear().
we should handle this correctly or we would get wrong sk_buff.

Fixes: 6fa01ccd8830 ("skbuff: Add pskb_extract() helper function")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/skbuff.c

index 5c3b906aeef3dc240a1ffd35a5493f9c4fcd2073..e18184ffa9c3fa65426979be78257cfaf9776a4c 100644 (file)
@@ -5987,9 +5987,13 @@ static int pskb_carve_inside_nonlinear(struct sk_buff *skb, const u32 off,
        if (skb_has_frag_list(skb))
                skb_clone_fraglist(skb);
 
-       if (k == 0) {
-               /* split line is in frag list */
-               pskb_carve_frag_list(skb, shinfo, off - pos, gfp_mask);
+       /* split line is in frag list */
+       if (k == 0 && pskb_carve_frag_list(skb, shinfo, off - pos, gfp_mask)) {
+               /* skb_frag_unref() is not needed here as shinfo->nr_frags = 0. */
+               if (skb_has_frag_list(skb))
+                       kfree_skb_list(skb_shinfo(skb)->frag_list);
+               kfree(data);
+               return -ENOMEM;
        }
        skb_release_data(skb);