2020-10-22 13:41:33

by Dinghao Liu

[permalink] [raw]
Subject: [PATCH] net-veth: Fix memleak in veth_newlink

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

Signed-off-by: Dinghao Liu <[email protected]>
---
drivers/net/veth.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 8c737668008a..6c68094399cc 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1405,8 +1405,6 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
/* nothing to do */
err_configure_peer:
unregister_netdevice(peer);
- return err;
-
err_register_peer:
free_netdev(peer);
return err;
--
2.17.1


2020-10-22 18:07:12

by Jakub Kicinski

[permalink] [raw]
Subject: Re: [PATCH] net-veth: Fix memleak in veth_newlink

On Thu, 22 Oct 2020 13:42:33 +0800 Dinghao Liu wrote:
> When rtnl_configure_link() fails, peer needs to be
> freed just like when register_netdevice() fails.
>
> Signed-off-by: Dinghao Liu <[email protected]>

Can you see this leak or are you just sending this based on your
reading of the code?

netdev should be freed by the core:

static void veth_setup(struct net_device *dev)
{
ether_setup(dev);

[...]
dev->needs_free_netdev = true;

> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index 8c737668008a..6c68094399cc 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -1405,8 +1405,6 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
> /* nothing to do */
> err_configure_peer:
> unregister_netdevice(peer);
> - return err;
> -
> err_register_peer:
> free_netdev(peer);
> return err;