Skip to contentSkip to conversation

net: vlan: avoid leaks on register_vlan_dev() failures

PATCH In review Jakub Kicinski 2 participants 2 messages Dec 31, 2020 – Jan 6, 2021

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net: vlan: avoid leaks on register_vlan_dev() failures

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")

---
Found by code inspection and compile-tested only.

 net/8021q/vlan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/8021q/vlan.c +2 -1
index f292e0267bb9..15bbfaf943fd 100644
@@ -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;
 }
Signature · 1 line
2.26.2
maintainer
#1 lore raw

From: Jakub Kicinski <[email protected]>
Date: Wed, 30 Dec 2020 19:40:27 -0800

Quoted 7 lines

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.

Quoted 7 lines

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

Fixes cb626bf566eb ("net-sysfs: Fix reference count leak")

---
Found by code inspection and compile-tested only.

This entire area is inconsistent, and confusing at best.

Applied and queued up for -stable, thanks.