netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: vlan: avoid leaks on register_vlan_dev() failures
@ 2020-12-31  3:40 Jakub Kicinski
  2021-01-06  0:26 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Kicinski @ 2020-12-31  3:40 UTC (permalink / raw)
  To: davem; +Cc: netdev, f.fainelli, jouni.hogander, Jakub Kicinski

VLAN checks for NETREG_UNINITIALIZED to distinguish between
registration failure and unregistration in progress.

Since commit cb626bf566eb ("net-sysfs: Fix reference count leak")
registration failure may, however, result in NETREG_UNREGISTERED
as well as NETREG_UNINITIALIZED.

This fix is similer to cebb69754f37 ("rtnetlink: Fix
memory(net_device) leak when ->newlink fails")

Fixes: cb626bf566eb ("net-sysfs: Fix reference count leak")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
Found by code inspection and compile-tested only.

 net/8021q/vlan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index f292e0267bb9..15bbfaf943fd 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -284,7 +284,8 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
 	return 0;
 
 out_free_newdev:
-	if (new_dev->reg_state == NETREG_UNINITIALIZED)
+	if (new_dev->reg_state == NETREG_UNINITIALIZED ||
+	    new_dev->reg_state == NETREG_UNREGISTERED)
 		free_netdev(new_dev);
 	return err;
 }
-- 
2.26.2


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

* Re: [PATCH net] net: vlan: avoid leaks on register_vlan_dev() failures
  2020-12-31  3:40 [PATCH net] net: vlan: avoid leaks on register_vlan_dev() failures Jakub Kicinski
@ 2021-01-06  0:26 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2021-01-06  0:26 UTC (permalink / raw)
  To: kuba; +Cc: netdev, f.fainelli, jouni.hogander

From: Jakub Kicinski <kuba@kernel.org>
Date: Wed, 30 Dec 2020 19:40:27 -0800

> VLAN checks for NETREG_UNINITIALIZED to distinguish between
> registration failure and unregistration in progress.
> 
> Since commit cb626bf566eb ("net-sysfs: Fix reference count leak")
> registration failure may, however, result in NETREG_UNREGISTERED
> as well as NETREG_UNINITIALIZED.
> 
> This fix is similer to cebb69754f37 ("rtnetlink: Fix
> memory(net_device) leak when ->newlink fails")
> 
> Fixes: cb626bf566eb ("net-sysfs: Fix reference count leak")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> Found by code inspection and compile-tested only.

This entire area is inconsistent, and confusing at best.

Applied and queued up for -stable, thanks.


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

end of thread, other threads:[~2021-01-06  0:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-31  3:40 [PATCH net] net: vlan: avoid leaks on register_vlan_dev() failures Jakub Kicinski
2021-01-06  0:26 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).