Commit 124da8f6 authored by Jason Wang's avatar Jason Wang Committed by David S. Miller

tuntap: fix possible deadlock when fail to register netdev

Private destructor could be called when register_netdev() fail with
rtnl lock held. This will lead deadlock in tun_free_netdev() who tries
to hold rtnl_lock. Fixing this by switching to use spinlock to
synchronize.

Fixes: 96f84061 ("tun: add eBPF based queue selection method")
Reported-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 66c5c5b5
......@@ -2048,8 +2048,11 @@ static int __tun_set_steering_ebpf(struct tun_struct *tun,
new->prog = prog;
}
old = rtnl_dereference(tun->steering_prog);
spin_lock_bh(&tun->lock);
old = rcu_dereference_protected(tun->steering_prog,
lockdep_is_held(&tun->lock));
rcu_assign_pointer(tun->steering_prog, new);
spin_unlock_bh(&tun->lock);
if (old)
call_rcu(&old->rcu, tun_steering_prog_free);
......@@ -2065,9 +2068,7 @@ static void tun_free_netdev(struct net_device *dev)
free_percpu(tun->pcpu_stats);
tun_flow_uninit(tun);
security_tun_dev_free_security(tun->security);
rtnl_lock();
__tun_set_steering_ebpf(tun, NULL);
rtnl_unlock();
}
static void tun_setup(struct net_device *dev)
......
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