Re: [PATCH] can: vxcan: Fix memleak in vxcan_newlink
From: Oliver Hartkopp
Date: Wed Oct 21 2020 - 07:23:39 EST
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@xxxxxxxxxx>
Acked-by: Oliver Hartkopp <socketcan@xxxxxxxxxxxx>
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;
}