linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit
@ 2021-03-28  7:50 Lv Yunlong
  2021-03-29  1:20 ` patchwork-bot+netdevbpf
  2021-05-03  6:06 ` Xie He
  0 siblings, 2 replies; 3+ messages in thread
From: Lv Yunlong @ 2021-03-28  7:50 UTC (permalink / raw)
  To: khc, davem, kuba; +Cc: netdev, linux-kernel, Lv Yunlong

In pvc_xmit, if __skb_pad(skb, pad, false) failed, it will free
the skb in the first time and goto drop. But the same skb is freed
by kfree_skb(skb) in the second time in drop.

Maintaining the original function unchanged, my patch adds a new
label out to avoid the double free if __skb_pad() failed.

Fixes: f5083d0cee08a ("drivers/net/wan/hdlc_fr: Improvements to the code of pvc_xmit")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 drivers/net/wan/hdlc_fr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index 0720f5f92caa..4d9dc7d15908 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -415,7 +415,7 @@ static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)
 
 		if (pad > 0) { /* Pad the frame with zeros */
 			if (__skb_pad(skb, pad, false))
-				goto drop;
+				goto out;
 			skb_put(skb, pad);
 		}
 	}
@@ -448,8 +448,9 @@ static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)
 	return NETDEV_TX_OK;
 
 drop:
-	dev->stats.tx_dropped++;
 	kfree_skb(skb);
+out:
+	dev->stats.tx_dropped++;
 	return NETDEV_TX_OK;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit
  2021-03-28  7:50 [PATCH] drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit Lv Yunlong
@ 2021-03-29  1:20 ` patchwork-bot+netdevbpf
  2021-05-03  6:06 ` Xie He
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-03-29  1:20 UTC (permalink / raw)
  To: Lv Yunlong; +Cc: khc, davem, kuba, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Sun, 28 Mar 2021 00:50:08 -0700 you wrote:
> In pvc_xmit, if __skb_pad(skb, pad, false) failed, it will free
> the skb in the first time and goto drop. But the same skb is freed
> by kfree_skb(skb) in the second time in drop.
> 
> Maintaining the original function unchanged, my patch adds a new
> label out to avoid the double free if __skb_pad() failed.
> 
> [...]

Here is the summary with links:
  - drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit
    https://git.kernel.org/netdev/net/c/1b479fb80160

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit
  2021-03-28  7:50 [PATCH] drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit Lv Yunlong
  2021-03-29  1:20 ` patchwork-bot+netdevbpf
@ 2021-05-03  6:06 ` Xie He
  1 sibling, 0 replies; 3+ messages in thread
From: Xie He @ 2021-05-03  6:06 UTC (permalink / raw)
  To: Lv Yunlong; +Cc: khc, davem, kuba, netdev, linux-kernel

> In pvc_xmit, if __skb_pad(skb, pad, false) failed, it will free
> the skb in the first time and goto drop. But the same skb is freed
> by kfree_skb(skb) in the second time in drop.
> 
> Maintaining the original function unchanged, my patch adds a new
> label out to avoid the double free if __skb_pad() failed.
> 
> Fixes: f5083d0cee08a ("drivers/net/wan/hdlc_fr: Improvements to the code of pvc_xmit")
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> ---
>  drivers/net/wan/hdlc_fr.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
> index 0720f5f92caa..4d9dc7d15908 100644
> --- a/drivers/net/wan/hdlc_fr.c
> +++ b/drivers/net/wan/hdlc_fr.c
> @@ -415,7 +415,7 @@ static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)
>  
>  		if (pad > 0) { /* Pad the frame with zeros */
>  			if (__skb_pad(skb, pad, false))
> -				goto drop;
> +				goto out;
>  			skb_put(skb, pad);
>  		}
>  	}
> @@ -448,8 +448,9 @@ static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)
>  	return NETDEV_TX_OK;
>  
>  drop:
> -	dev->stats.tx_dropped++;
>  	kfree_skb(skb);
> +out:
> +	dev->stats.tx_dropped++;
>  	return NETDEV_TX_OK;
>  }
> 

1. This patch is incorrect. "__skb_pad" will NOT free the skb on failure
when its "free_on_error" parameter is "false".

2. If you think you fix my commit, please CC me so that I can review
your patch.

I have sent another patch to revert this.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-03  6:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-28  7:50 [PATCH] drivers/net/wan/hdlc_fr: Fix a double free in pvc_xmit Lv Yunlong
2021-03-29  1:20 ` patchwork-bot+netdevbpf
2021-05-03  6:06 ` Xie He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).