1
0
Fork 0

macvlan: Fix one possible double free

Because the macvlan_uninit would free the macvlan port, so there is one
double free case in macvlan_common_newlink. When the macvlan port is just
created, then register_netdevice or netdev_upper_dev_link failed and they
would invoke macvlan_uninit. Then it would reach the macvlan_port_destroy
which triggers the double free.

Signed-off-by: Gao Feng <gfree.wind@vip.163.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
hifive-unleashed-5.1
Gao Feng 2017-12-26 21:44:32 +08:00 committed by David S. Miller
parent 3bb23421a5
commit d02fd6e7d2
1 changed files with 6 additions and 1 deletions

View File

@ -1444,9 +1444,14 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
return 0;
unregister_netdev:
/* macvlan_uninit would free the macvlan port */
unregister_netdevice(dev);
return err;
destroy_macvlan_port:
if (create)
/* the macvlan port may be freed by macvlan_uninit when fail to register.
* so we destroy the macvlan port only when it's valid.
*/
if (create && macvlan_port_get_rtnl(dev))
macvlan_port_destroy(port->dev);
return err;
}