* [PATCH] can: usb: fix a possible memory leak in esd_usb2_start_xmit
@ 2022-02-25 6:00 Hangyu Hua
2022-02-25 15:56 ` Marc Kleine-Budde
0 siblings, 1 reply; 5+ messages in thread
From: Hangyu Hua @ 2022-02-25 6:00 UTC (permalink / raw)
To: wg, mkl, davem, kuba, stefan.maetje, mailhol.vincent, paskripkin,
thunder.leizhen
Cc: linux-can, netdev, linux-kernel, Hangyu Hua
As in case of ems_usb_start_xmit, dev_kfree_skb needs to be called when
usb_submit_urb fails to avoid possible refcount leaks.
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
drivers/net/can/usb/esd_usb2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
index 286daaaea0b8..7b5e6c250d00 100644
--- a/drivers/net/can/usb/esd_usb2.c
+++ b/drivers/net/can/usb/esd_usb2.c
@@ -810,7 +810,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
usb_unanchor_urb(urb);
stats->tx_dropped++;
-
+ dev_kfree_skb(skb);
if (err == -ENODEV)
netif_device_detach(netdev);
else
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: usb: fix a possible memory leak in esd_usb2_start_xmit
2022-02-25 6:00 [PATCH] can: usb: fix a possible memory leak in esd_usb2_start_xmit Hangyu Hua
@ 2022-02-25 15:56 ` Marc Kleine-Budde
2022-02-28 2:05 ` Hangyu Hua
0 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2022-02-25 15:56 UTC (permalink / raw)
To: Hangyu Hua
Cc: wg, davem, kuba, stefan.maetje, mailhol.vincent, paskripkin,
thunder.leizhen, linux-can, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1239 bytes --]
On 25.02.2022 14:00:19, Hangyu Hua wrote:
> As in case of ems_usb_start_xmit, dev_kfree_skb needs to be called when
> usb_submit_urb fails to avoid possible refcount leaks.
Thanks for your patch. Have you tested that there is actually a mem
leak? Please have a look at the can_free_echo_skb() function that is
called a few lines earlier.
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
> drivers/net/can/usb/esd_usb2.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
> index 286daaaea0b8..7b5e6c250d00 100644
> --- a/drivers/net/can/usb/esd_usb2.c
> +++ b/drivers/net/can/usb/esd_usb2.c
> @@ -810,7 +810,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
> usb_unanchor_urb(urb);
>
> stats->tx_dropped++;
> -
> + dev_kfree_skb(skb);
> if (err == -ENODEV)
> netif_device_detach(netdev);
> else
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: usb: fix a possible memory leak in esd_usb2_start_xmit
2022-02-25 15:56 ` Marc Kleine-Budde
@ 2022-02-28 2:05 ` Hangyu Hua
2022-02-28 7:51 ` Marc Kleine-Budde
0 siblings, 1 reply; 5+ messages in thread
From: Hangyu Hua @ 2022-02-28 2:05 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: wg, davem, kuba, stefan.maetje, mailhol.vincent, paskripkin,
thunder.leizhen, linux-can, netdev, linux-kernel
Hi
I get it. But this means ems_usb_start_xmit have a redundant
dev_kfree_skb beacause can_put_echo_skb delete original skb and
can_free_echo_skb delete the cloned skb. While this code is harmless do
you think we need to delete it ?
Thanks.
On 2022/2/25 23:56, Marc Kleine-Budde wrote:
> On 25.02.2022 14:00:19, Hangyu Hua wrote:
>> As in case of ems_usb_start_xmit, dev_kfree_skb needs to be called when
>> usb_submit_urb fails to avoid possible refcount leaks.
>
> Thanks for your patch. Have you tested that there is actually a mem
> leak? Please have a look at the can_free_echo_skb() function that is
> called a few lines earlier.
>
>> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
>> ---
>> drivers/net/can/usb/esd_usb2.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
>> index 286daaaea0b8..7b5e6c250d00 100644
>> --- a/drivers/net/can/usb/esd_usb2.c
>> +++ b/drivers/net/can/usb/esd_usb2.c
>> @@ -810,7 +810,7 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
>> usb_unanchor_urb(urb);
>>
>> stats->tx_dropped++;
>> -
>> + dev_kfree_skb(skb);
>> if (err == -ENODEV)
>> netif_device_detach(netdev);
>> else
>
> regards,
> Marc
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] can: usb: fix a possible memory leak in esd_usb2_start_xmit
2022-02-28 2:05 ` Hangyu Hua
@ 2022-02-28 7:51 ` Marc Kleine-Budde
2022-02-28 8:06 ` Hangyu Hua
0 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2022-02-28 7:51 UTC (permalink / raw)
To: Hangyu Hua
Cc: wg, davem, kuba, stefan.maetje, mailhol.vincent, paskripkin,
thunder.leizhen, linux-can, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 900 bytes --]
On 28.02.2022 10:05:03, Hangyu Hua wrote:
> I get it. But this means ems_usb_start_xmit have a redundant
> dev_kfree_skb beacause can_put_echo_skb delete original skb and
> can_free_echo_skb delete the cloned skb. While this code is harmless
> do you think we need to delete it ?
ACK. This dev_kfree_skb() should be deleted:
| err = usb_submit_urb(urb, GFP_ATOMIC);
| if (unlikely(err)) {
| can_free_echo_skb(netdev, context->echo_index, NULL);
|
| usb_unanchor_urb(urb);
| usb_free_coherent(dev->udev, size, buf, urb->transfer_dma);
| dev_kfree_skb(skb);
Can you create a patch?
regards,
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] can: usb: fix a possible memory leak in esd_usb2_start_xmit
2022-02-28 7:51 ` Marc Kleine-Budde
@ 2022-02-28 8:06 ` Hangyu Hua
0 siblings, 0 replies; 5+ messages in thread
From: Hangyu Hua @ 2022-02-28 8:06 UTC (permalink / raw)
To: Marc Kleine-Budde
Cc: wg, davem, kuba, stefan.maetje, mailhol.vincent, paskripkin,
thunder.leizhen, linux-can, netdev, linux-kernel
Yes. I will create a patch later.
Thanks.
On 2022/2/28 15:51, Marc Kleine-Budde wrote:
> On 28.02.2022 10:05:03, Hangyu Hua wrote:
>> I get it. But this means ems_usb_start_xmit have a redundant
>> dev_kfree_skb beacause can_put_echo_skb delete original skb and
>> can_free_echo_skb delete the cloned skb. While this code is harmless
>> do you think we need to delete it ?
>
> ACK. This dev_kfree_skb() should be deleted:
>
> | err = usb_submit_urb(urb, GFP_ATOMIC);
> | if (unlikely(err)) {
> | can_free_echo_skb(netdev, context->echo_index, NULL);
> |
> | usb_unanchor_urb(urb);
> | usb_free_coherent(dev->udev, size, buf, urb->transfer_dma);
> | dev_kfree_skb(skb);
>
> Can you create a patch?
>
> regards,
> Marc
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-02-28 8:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25 6:00 [PATCH] can: usb: fix a possible memory leak in esd_usb2_start_xmit Hangyu Hua
2022-02-25 15:56 ` Marc Kleine-Budde
2022-02-28 2:05 ` Hangyu Hua
2022-02-28 7:51 ` Marc Kleine-Budde
2022-02-28 8:06 ` Hangyu Hua
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®