Skip to content

Commit 494e848

Browse files
Mahesh Bandewardavem330
authored andcommitted
ipvlan: Fix failure path in dev registration during link creation
When newlink creation fails at device-registration, the port->count is decremented twice. Francesco Ruggeri ([email protected]) found this issue in Macvlan and the same exists in IPvlan driver too. While fixing this issue I noticed another issue of missing unregister in case of failure, so adding it to the fix which is similar to the macvlan fix by Francesco in commit 3083796 ("macvlan: fix failure during registration v3") Reported-by: Francesco Ruggeri <[email protected]> Signed-off-by: Mahesh Bandewar <[email protected]> CC: Eric Dumazet <[email protected]> CC: Eric W. Biederman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 222e4d0 commit 494e848

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/net/ipvlan/ipvlan_main.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static int ipvlan_init(struct net_device *dev)
113113
{
114114
struct ipvl_dev *ipvlan = netdev_priv(dev);
115115
const struct net_device *phy_dev = ipvlan->phy_dev;
116+
struct ipvl_port *port = ipvlan->port;
116117

117118
dev->state = (dev->state & ~IPVLAN_STATE_MASK) |
118119
(phy_dev->state & IPVLAN_STATE_MASK);
@@ -128,6 +129,8 @@ static int ipvlan_init(struct net_device *dev)
128129
if (!ipvlan->pcpu_stats)
129130
return -ENOMEM;
130131

132+
port->count += 1;
133+
131134
return 0;
132135
}
133136

@@ -481,27 +484,21 @@ static int ipvlan_link_new(struct net *src_net, struct net_device *dev,
481484

482485
dev->priv_flags |= IFF_IPVLAN_SLAVE;
483486

484-
port->count += 1;
485487
err = register_netdevice(dev);
486488
if (err < 0)
487-
goto ipvlan_destroy_port;
489+
return err;
488490

489491
err = netdev_upper_dev_link(phy_dev, dev);
490-
if (err)
491-
goto ipvlan_destroy_port;
492+
if (err) {
493+
unregister_netdevice(dev);
494+
return err;
495+
}
492496

493497
list_add_tail_rcu(&ipvlan->pnode, &port->ipvlans);
494498
ipvlan_set_port_mode(port, mode);
495499

496500
netif_stacked_transfer_operstate(phy_dev, dev);
497501
return 0;
498-
499-
ipvlan_destroy_port:
500-
port->count -= 1;
501-
if (!port->count)
502-
ipvlan_port_destroy(phy_dev);
503-
504-
return err;
505502
}
506503

507504
static void ipvlan_link_delete(struct net_device *dev, struct list_head *head)

0 commit comments

Comments
 (0)