Commit 6db92468 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

vxlan: Fix error path in __vxlan_dev_create()

When a failure occurs in rtnl_configure_link(), the current code
calls unregister_netdevice() to roll back the earlier call to
register_netdevice(), and jumps to errout, which calls
vxlan_fdb_destroy().

However unregister_netdevice() calls transitively ndo_uninit, which is
vxlan_uninit(), and that already takes care of deleting the default FDB
entry by calling vxlan_fdb_delete_default(). Since the entry added
earlier in __vxlan_dev_create() is exactly the default entry, the
cleanup code in the errout block always leads to double free and thus a
panic.

Besides, since vxlan_fdb_delete_default() always destroys the FDB entry
with notification enabled, the deletion of the default entry is notified
even before the addition was notified.

Instead, move the unregister_netdevice() call after the manual destroy,
which solves both problems.

Fixes: 0241b836 ("vxlan: fix default fdb entry netlink notify ordering during netdev create")
Signed-off-by: default avatarPetr Machata <petrm@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6ad0b5a4
...@@ -3259,6 +3259,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, ...@@ -3259,6 +3259,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
struct vxlan_net *vn = net_generic(net, vxlan_net_id); struct vxlan_net *vn = net_generic(net, vxlan_net_id);
struct vxlan_dev *vxlan = netdev_priv(dev); struct vxlan_dev *vxlan = netdev_priv(dev);
struct vxlan_fdb *f = NULL; struct vxlan_fdb *f = NULL;
bool unregister = false;
int err; int err;
err = vxlan_dev_configure(net, dev, conf, false, extack); err = vxlan_dev_configure(net, dev, conf, false, extack);
...@@ -3284,12 +3285,11 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, ...@@ -3284,12 +3285,11 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
err = register_netdevice(dev); err = register_netdevice(dev);
if (err) if (err)
goto errout; goto errout;
unregister = true;
err = rtnl_configure_link(dev, NULL); err = rtnl_configure_link(dev, NULL);
if (err) { if (err)
unregister_netdevice(dev);
goto errout; goto errout;
}
/* notify default fdb entry */ /* notify default fdb entry */
if (f) if (f)
...@@ -3297,9 +3297,16 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev, ...@@ -3297,9 +3297,16 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
list_add(&vxlan->next, &vn->vxlan_list); list_add(&vxlan->next, &vn->vxlan_list);
return 0; return 0;
errout: errout:
/* unregister_netdevice() destroys the default FDB entry with deletion
* notification. But the addition notification was not sent yet, so
* destroy the entry by hand here.
*/
if (f) if (f)
vxlan_fdb_destroy(vxlan, f, false); vxlan_fdb_destroy(vxlan, f, false);
if (unregister)
unregister_netdevice(dev);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment