All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] can: vxcan: Fix memleak in vxcan_newlink
@ 2020-10-21  5:21 Dinghao Liu
  2020-10-21 11:20 ` Oliver Hartkopp
  0 siblings, 1 reply; 6+ messages in thread
From: Dinghao Liu @ 2020-10-21  5:21 UTC (permalink / raw)
  To: dinghao.liu, kjlu
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Jakub Kicinski, linux-can, netdev, linux-kernel

When rtnl_configure_link() fails, peer needs to be
freed just like when register_netdevice() fails.

Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
 drivers/net/can/vxcan.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c
index d6ba9426be4d..aefc5a61d239 100644
--- a/drivers/net/can/vxcan.c
+++ b/drivers/net/can/vxcan.c
@@ -244,6 +244,7 @@ static int vxcan_newlink(struct net *net, struct net_device *dev,
 
 unregister_network_device:
 	unregister_netdevice(peer);
+	free_netdev(peer);
 	return err;
 }
 
-- 
2.17.1


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

* Re: [PATCH] can: vxcan: Fix memleak in vxcan_newlink
  2020-10-21  5:21 [PATCH] can: vxcan: Fix memleak in vxcan_newlink Dinghao Liu
@ 2020-10-21 11:20 ` Oliver Hartkopp
  2020-10-22  5:28   ` dinghao.liu
  2020-10-22 16:14   ` Jakub Kicinski
  0 siblings, 2 replies; 6+ messages in thread
From: Oliver Hartkopp @ 2020-10-21 11:20 UTC (permalink / raw)
  To: Dinghao Liu, kjlu
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Jakub Kicinski, linux-can, netdev, linux-kernel



On 21.10.20 07:21, Dinghao Liu wrote:
> When rtnl_configure_link() fails, peer needs to be
> freed just like when register_netdevice() fails.
> 
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>

Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>

Btw. as the vxcan.c driver bases on veth.c the same issue can be found 
there!

At this point:
https://elixir.bootlin.com/linux/latest/source/drivers/net/veth.c#L1398

err_register_dev:
         /* nothing to do */
err_configure_peer:
         unregister_netdevice(peer);
         return err; <<<<<<<<<<<<<<<<<<<<<<<

err_register_peer:
         free_netdev(peer);
         return err;
}

IMO the return must be removed to fall through the next label and free 
the netdevice too.

Would you like so send a patch for veth.c too?

Best regards,
Oliver

> ---
>   drivers/net/can/vxcan.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/can/vxcan.c b/drivers/net/can/vxcan.c
> index d6ba9426be4d..aefc5a61d239 100644
> --- a/drivers/net/can/vxcan.c
> +++ b/drivers/net/can/vxcan.c
> @@ -244,6 +244,7 @@ static int vxcan_newlink(struct net *net, struct net_device *dev,
>   
>   unregister_network_device:
>   	unregister_netdevice(peer);
> +	free_netdev(peer);
>   	return err;
>   }
>   
> 

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

* Re: Re: [PATCH] can: vxcan: Fix memleak in vxcan_newlink
  2020-10-21 11:20 ` Oliver Hartkopp
@ 2020-10-22  5:28   ` dinghao.liu
  2020-10-22 16:14   ` Jakub Kicinski
  1 sibling, 0 replies; 6+ messages in thread
From: dinghao.liu @ 2020-10-22  5:28 UTC (permalink / raw)
  To: Oliver Hartkopp
  Cc: kjlu, Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Jakub Kicinski, linux-can, netdev, linux-kernel

> 
> On 21.10.20 07:21, Dinghao Liu wrote:
> > When rtnl_configure_link() fails, peer needs to be
> > freed just like when register_netdevice() fails.
> > 
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> 
> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
> 
> Btw. as the vxcan.c driver bases on veth.c the same issue can be found 
> there!
> 
> At this point:
> https://elixir.bootlin.com/linux/latest/source/drivers/net/veth.c#L1398
> 
> err_register_dev:
>          /* nothing to do */
> err_configure_peer:
>          unregister_netdevice(peer);
>          return err; <<<<<<<<<<<<<<<<<<<<<<<
> 
> err_register_peer:
>          free_netdev(peer);
>          return err;
> }
> 
> IMO the return must be removed to fall through the next label and free 
> the netdevice too.
> 
> Would you like so send a patch for veth.c too?
> 

Sure.

Regards,
Dinghao

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

* Re: [PATCH] can: vxcan: Fix memleak in vxcan_newlink
  2020-10-21 11:20 ` Oliver Hartkopp
  2020-10-22  5:28   ` dinghao.liu
@ 2020-10-22 16:14   ` Jakub Kicinski
  2020-10-22 17:34     ` Oliver Hartkopp
  1 sibling, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2020-10-22 16:14 UTC (permalink / raw)
  To: Oliver Hartkopp
  Cc: Dinghao Liu, kjlu, Wolfgang Grandegger, Marc Kleine-Budde,
	David S. Miller, linux-can, netdev, linux-kernel

On Wed, 21 Oct 2020 13:20:16 +0200 Oliver Hartkopp wrote:
> On 21.10.20 07:21, Dinghao Liu wrote:
> > When rtnl_configure_link() fails, peer needs to be
> > freed just like when register_netdevice() fails.
> > 
> > Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>  
> 
> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
> 
> Btw. as the vxcan.c driver bases on veth.c the same issue can be found 
> there!
> 
> At this point:
> https://elixir.bootlin.com/linux/latest/source/drivers/net/veth.c#L1398
> 
> err_register_dev:
>          /* nothing to do */
> err_configure_peer:
>          unregister_netdevice(peer);
>          return err; <<<<<<<<<<<<<<<<<<<<<<<
> 
> err_register_peer:
>          free_netdev(peer);
>          return err;
> }
> 
> IMO the return must be removed to fall through the next label and free 
> the netdevice too.
> 
> Would you like so send a patch for veth.c too?

Ah, this is where Liu Dinghao got the veth suggestion :)

Does vxcan actually need this patch?

static void vxcan_setup(struct net_device *dev)
{
	[...]
        dev->needs_free_netdev  = true;

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

* Re: [PATCH] can: vxcan: Fix memleak in vxcan_newlink
  2020-10-22 16:14   ` Jakub Kicinski
@ 2020-10-22 17:34     ` Oliver Hartkopp
  2020-10-22 17:38       ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: Oliver Hartkopp @ 2020-10-22 17:34 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Dinghao Liu, kjlu, Wolfgang Grandegger, Marc Kleine-Budde,
	David S. Miller, linux-can, netdev, linux-kernel



On 22.10.20 18:14, Jakub Kicinski wrote:
> On Wed, 21 Oct 2020 13:20:16 +0200 Oliver Hartkopp wrote:
>> On 21.10.20 07:21, Dinghao Liu wrote:
>>> When rtnl_configure_link() fails, peer needs to be
>>> freed just like when register_netdevice() fails.
>>>
>>> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
>>
>> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
>>
>> Btw. as the vxcan.c driver bases on veth.c the same issue can be found
>> there!
>>
>> At this point:
>> https://elixir.bootlin.com/linux/latest/source/drivers/net/veth.c#L1398
>>
>> err_register_dev:
>>           /* nothing to do */
>> err_configure_peer:
>>           unregister_netdevice(peer);
>>           return err; <<<<<<<<<<<<<<<<<<<<<<<
>>
>> err_register_peer:
>>           free_netdev(peer);
>>           return err;
>> }
>>
>> IMO the return must be removed to fall through the next label and free
>> the netdevice too.
>>
>> Would you like so send a patch for veth.c too?
> 
> Ah, this is where Liu Dinghao got the veth suggestion :)
> 
> Does vxcan actually need this patch?
> 
> static void vxcan_setup(struct net_device *dev)
> {
> 	[...]
>          dev->needs_free_netdev  = true;
> 

Oh!

In fact the vxcan.c is really similar to veth.c in these code snippets - 
so I wondered why this never had been seen in veth.c.

Then vxcan.c doesn't need that patch too :-/

Thanks for the heads up!

@Marc: Can you please make sure that it doesn't get into upstream? Tnx!

Best,
Oliver


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

* Re: [PATCH] can: vxcan: Fix memleak in vxcan_newlink
  2020-10-22 17:34     ` Oliver Hartkopp
@ 2020-10-22 17:38       ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2020-10-22 17:38 UTC (permalink / raw)
  To: Oliver Hartkopp, Jakub Kicinski
  Cc: Dinghao Liu, kjlu, Wolfgang Grandegger, David S. Miller,
	linux-can, netdev, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 514 bytes --]

On 10/22/20 7:34 PM, Oliver Hartkopp wrote:
> @Marc: Can you please make sure that it doesn't get into upstream? Tnx!

Ok, I've removed

    can: vxcan: Fix memleak in vxcan_newlink  [Dinghao Liu]

from my linux-can/testing.

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: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2020-10-22 17:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21  5:21 [PATCH] can: vxcan: Fix memleak in vxcan_newlink Dinghao Liu
2020-10-21 11:20 ` Oliver Hartkopp
2020-10-22  5:28   ` dinghao.liu
2020-10-22 16:14   ` Jakub Kicinski
2020-10-22 17:34     ` Oliver Hartkopp
2020-10-22 17:38       ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.