]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
net: vlan: avoid leaks on register_vlan_dev() failures
authorJakub Kicinski <kuba@kernel.org>
Thu, 31 Dec 2020 03:40:27 +0000 (19:40 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 17 Jan 2021 13:04:19 +0000 (14:04 +0100)
[ Upstream commit 55b7ab1178cbf41f979ff83236d3321ad35ed2ad ]

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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/8021q/vlan.c

index 5e99504539559e39f45e873171e53a565195b7bc..512ada90657b24b67c1de20c173ad09b15e37465 100644 (file)
@@ -277,7 +277,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;
 }