Skip to content

Commit a53cb29

Browse files
mark-blochdavem330
authored andcommitted
vxlan: fix use-after-free on deletion
Adding a vxlan interface to a socket isn't symmetrical, while adding is done in vxlan_open() the deletion is done in vxlan_dellink(). This can cause a use-after-free error when we close the vxlan interface before deleting it. We add vxlan_vs_del_dev() to match vxlan_vs_add_dev() and call it from vxlan_stop() to match the call from vxlan_open(). Fixes: 56ef9c9 ("vxlan: Move socket initialization to within rtnl scope") Acked-by: Jiri Benc <[email protected]> Tested-by: Roi Dayan <[email protected]> Signed-off-by: Mark Bloch <[email protected]> Acked-by: Roopa Prabhu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 78b07ac commit a53cb29

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/net/vxlan.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static const u8 all_zeros_mac[ETH_ALEN + 2];
5959

6060
static int vxlan_sock_add(struct vxlan_dev *vxlan);
6161

62+
static void vxlan_vs_del_dev(struct vxlan_dev *vxlan);
63+
6264
/* per-network namespace private data for this module */
6365
struct vxlan_net {
6466
struct list_head vxlan_list;
@@ -1081,6 +1083,8 @@ static void vxlan_sock_release(struct vxlan_dev *vxlan)
10811083
rcu_assign_pointer(vxlan->vn4_sock, NULL);
10821084
synchronize_net();
10831085

1086+
vxlan_vs_del_dev(vxlan);
1087+
10841088
if (__vxlan_sock_release_prep(sock4)) {
10851089
udp_tunnel_sock_release(sock4->sock);
10861090
kfree(sock4);
@@ -2356,6 +2360,15 @@ static void vxlan_cleanup(unsigned long arg)
23562360
mod_timer(&vxlan->age_timer, next_timer);
23572361
}
23582362

2363+
static void vxlan_vs_del_dev(struct vxlan_dev *vxlan)
2364+
{
2365+
struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id);
2366+
2367+
spin_lock(&vn->sock_lock);
2368+
hlist_del_init_rcu(&vxlan->hlist);
2369+
spin_unlock(&vn->sock_lock);
2370+
}
2371+
23592372
static void vxlan_vs_add_dev(struct vxlan_sock *vs, struct vxlan_dev *vxlan)
23602373
{
23612374
struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id);
@@ -3300,15 +3313,9 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
33003313
static void vxlan_dellink(struct net_device *dev, struct list_head *head)
33013314
{
33023315
struct vxlan_dev *vxlan = netdev_priv(dev);
3303-
struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id);
33043316

33053317
vxlan_flush(vxlan, true);
33063318

3307-
spin_lock(&vn->sock_lock);
3308-
if (!hlist_unhashed(&vxlan->hlist))
3309-
hlist_del_rcu(&vxlan->hlist);
3310-
spin_unlock(&vn->sock_lock);
3311-
33123319
gro_cells_destroy(&vxlan->gro_cells);
33133320
list_del(&vxlan->next);
33143321
unregister_netdevice_queue(dev, head);

0 commit comments

Comments
 (0)