Skip to content

Commit 3083796

Browse files
Francesco Ruggeridavem330
authored andcommitted
macvlan: fix failure during registration v3
If macvlan_common_newlink fails in register_netdevice after macvlan_init then it decrements port->count twice, first in macvlan_uninit (from register_netdevice or rollback_registered) and then again in macvlan_common_newlink. A similar problem may exist in the ipvlan driver. This patch consolidates modifications to port->count into macvlan_init and macvlan_uninit (thanks to Eric Biederman for suggesting this approach). v3: remove macvtap specific bits. Signed-off-by: Francesco Ruggeri <[email protected]> Acked-by: "Eric W. Biederman" <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 713d4dd commit 3083796

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/net/macvlan.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ static int macvlan_init(struct net_device *dev)
795795
{
796796
struct macvlan_dev *vlan = netdev_priv(dev);
797797
const struct net_device *lowerdev = vlan->lowerdev;
798+
struct macvlan_port *port = vlan->port;
798799

799800
dev->state = (dev->state & ~MACVLAN_STATE_MASK) |
800801
(lowerdev->state & MACVLAN_STATE_MASK);
@@ -812,6 +813,8 @@ static int macvlan_init(struct net_device *dev)
812813
if (!vlan->pcpu_stats)
813814
return -ENOMEM;
814815

816+
port->count += 1;
817+
815818
return 0;
816819
}
817820

@@ -1312,10 +1315,9 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
13121315
return err;
13131316
}
13141317

1315-
port->count += 1;
13161318
err = register_netdevice(dev);
13171319
if (err < 0)
1318-
goto destroy_port;
1320+
return err;
13191321

13201322
dev->priv_flags |= IFF_MACVLAN;
13211323
err = netdev_upper_dev_link(lowerdev, dev);
@@ -1330,10 +1332,6 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
13301332

13311333
unregister_netdev:
13321334
unregister_netdevice(dev);
1333-
destroy_port:
1334-
port->count -= 1;
1335-
if (!port->count)
1336-
macvlan_port_destroy(lowerdev);
13371335

13381336
return err;
13391337
}

0 commit comments

Comments
 (0)