Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH net] net: fix a leak in register_netdevice()
@ 2019-12-03 13:00 Dan Carpenter
  2019-12-03 13:42 ` walter harms
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2019-12-03 13:00 UTC (permalink / raw)
  To: David S. Miller, Jiri Pirko
  Cc: Ido Schimmel, Petr Machata, Paolo Abeni, Eric Dumazet,
	Taehee Yoo, Stephen Hemminger, Alexander Lobakin, netdev,
	kernel-janitors

We have to free "dev->name_node" on this error path.

Fixes: ff92741270bf ("net: introduce name_node struct to be used in hashlist")
Reported-by: syzbot+6e13e65ffbaa33757bcb@syzkaller.appspotmail.com
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 net/core/dev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index d75fd04d4e2c..9cc4b193d8c4 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9246,7 +9246,7 @@ int register_netdevice(struct net_device *dev)
 		if (ret) {
 			if (ret > 0)
 				ret = -EIO;
-			goto out;
+			goto err_free_name;
 		}
 	}
 
@@ -9361,12 +9361,13 @@ int register_netdevice(struct net_device *dev)
 	return ret;
 
 err_uninit:
-	if (dev->name_node)
-		netdev_name_node_free(dev->name_node);
 	if (dev->netdev_ops->ndo_uninit)
 		dev->netdev_ops->ndo_uninit(dev);
 	if (dev->priv_destructor)
 		dev->priv_destructor(dev);
+err_free_name:
+	if (dev->name_node)
+		netdev_name_node_free(dev->name_node);
 	goto out;
 }
 EXPORT_SYMBOL(register_netdevice);
-- 
2.11.0


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

* Re: [PATCH net] net: fix a leak in register_netdevice()
  2019-12-03 13:00 [PATCH net] net: fix a leak in register_netdevice() Dan Carpenter
@ 2019-12-03 13:42 ` walter harms
  2019-12-03 14:12   ` [PATCH v2] " Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: walter harms @ 2019-12-03 13:42 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David S. Miller, Jiri Pirko, Ido Schimmel, Petr Machata,
	Paolo Abeni, Eric Dumazet, Taehee Yoo, Stephen Hemminger,
	Alexander Lobakin, netdev, kernel-janitors



Am 03.12.2019 14:00, schrieb Dan Carpenter:
> We have to free "dev->name_node" on this error path.
> 
> Fixes: ff92741270bf ("net: introduce name_node struct to be used in hashlist")
> Reported-by: syzbot+6e13e65ffbaa33757bcb@syzkaller.appspotmail.com
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  net/core/dev.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index d75fd04d4e2c..9cc4b193d8c4 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -9246,7 +9246,7 @@ int register_netdevice(struct net_device *dev)
>  		if (ret) {
>  			if (ret > 0)
>  				ret = -EIO;
> -			goto out;
> +			goto err_free_name;
>  		}
>  	}
>  
> @@ -9361,12 +9361,13 @@ int register_netdevice(struct net_device *dev)
>  	return ret;
>  
>  err_uninit:
> -	if (dev->name_node)
> -		netdev_name_node_free(dev->name_node);
>  	if (dev->netdev_ops->ndo_uninit)
>  		dev->netdev_ops->ndo_uninit(dev);
>  	if (dev->priv_destructor)
>  		dev->priv_destructor(dev);
> +err_free_name:
> +	if (dev->name_node)
> +		netdev_name_node_free(dev->name_node);
>  	goto out;
>  }
>  EXPORT_SYMBOL(register_netdevice);

nitpick:
netdev_name_node_free() is a wrapper for kfree().
no need to check dev->name_node.

jm2c

re,
 wh

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

* [PATCH v2] net: fix a leak in register_netdevice()
  2019-12-03 13:42 ` walter harms
@ 2019-12-03 14:12   ` " Dan Carpenter
  2019-12-03 19:19     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2019-12-03 14:12 UTC (permalink / raw)
  To: David S. Miller, Jiri Pirko, walter harms
  Cc: Ido Schimmel, Petr Machata, Paolo Abeni, Eric Dumazet,
	Taehee Yoo, Stephen Hemminger, Alexander Lobakin, netdev,
	kernel-janitors

We have to free "dev->name_node" on this error path.

Fixes: ff92741270bf ("net: introduce name_node struct to be used in hashlist")
Reported-by: syzbot+6e13e65ffbaa33757bcb@syzkaller.appspotmail.com
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: dev->name_node can't be NULL so we can remove the check for that
    in the cleanup code.

 net/core/dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index d75fd04d4e2c..c4ef4d7638ca 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9246,7 +9246,7 @@ int register_netdevice(struct net_device *dev)
 		if (ret) {
 			if (ret > 0)
 				ret = -EIO;
-			goto out;
+			goto err_free_name;
 		}
 	}
 
@@ -9361,12 +9361,12 @@ int register_netdevice(struct net_device *dev)
 	return ret;
 
 err_uninit:
-	if (dev->name_node)
-		netdev_name_node_free(dev->name_node);
 	if (dev->netdev_ops->ndo_uninit)
 		dev->netdev_ops->ndo_uninit(dev);
 	if (dev->priv_destructor)
 		dev->priv_destructor(dev);
+err_free_name:
+	netdev_name_node_free(dev->name_node);
 	goto out;
 }
 EXPORT_SYMBOL(register_netdevice);
-- 
2.11.0


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

* Re: [PATCH v2] net: fix a leak in register_netdevice()
  2019-12-03 14:12   ` [PATCH v2] " Dan Carpenter
@ 2019-12-03 19:19     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-12-03 19:19 UTC (permalink / raw)
  To: dan.carpenter
  Cc: jiri, wharms, idosch, petrm, pabeni, edumazet, ap420073, stephen,
	alobakin, netdev, kernel-janitors

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Tue, 3 Dec 2019 17:12:39 +0300

> We have to free "dev->name_node" on this error path.
> 
> Fixes: ff92741270bf ("net: introduce name_node struct to be used in hashlist")
> Reported-by: syzbot+6e13e65ffbaa33757bcb@syzkaller.appspotmail.com
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: dev->name_node can't be NULL so we can remove the check for that
>     in the cleanup code.

Applied, thanks Dan.

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-03 13:00 [PATCH net] net: fix a leak in register_netdevice() Dan Carpenter
2019-12-03 13:42 ` walter harms
2019-12-03 14:12   ` [PATCH v2] " Dan Carpenter
2019-12-03 19:19     ` David Miller

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git