diff mbox series

net: handle the return value of pskb_carve_frag_list() correctly

Message ID 20200815084641.18417-1-linmiaohe@huawei.com
State Accepted
Delegated to: David Miller
Headers show
Series net: handle the return value of pskb_carve_frag_list() correctly | expand

Commit Message

Miaohe Lin Aug. 15, 2020, 8:46 a.m. UTC
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>
---
 net/core/skbuff.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

David Miller Aug. 16, 2020, 11:01 p.m. UTC | #1
From: Miaohe Lin <linmiaohe@huawei.com>
Date: Sat, 15 Aug 2020 04:46:41 -0400

> +	/* 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;

On error, the caller is going to kfree_skb(skb) which will take care of the
frag list.
David Miller Aug. 18, 2020, 10:57 p.m. UTC | #2
From: Miaohe Lin <linmiaohe@huawei.com>
Date: Sat, 15 Aug 2020 04:46:41 -0400

> 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>

Applied, thanks.
diff mbox series

Patch

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index bca0d3c7f114..afbc1a79dc8a 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -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);