* [PATCH net-next] tuntap: fix possible deadlock when fail to register netdev
@ 2017-12-08 2:54 Jason Wang
2017-12-08 3:11 ` Eric Dumazet
0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2017-12-08 2:54 UTC (permalink / raw)
To: netdev, linux-kernel; +Cc: mst, Jason Wang, Eric Dumazet, Willem de Bruijn
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: 96f84061620c ("tun: add eBPF based queue selection method")
Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
drivers/net/tun.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 787cc35..f7ccd79 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -2050,8 +2050,11 @@ static int __tun_set_steering_ebpf(struct tun_struct *tun,
new->prog = prog;
}
- old = rtnl_dereference(tun->steering_prog);
+ spin_lock(&tun->lock);
+ old = rcu_dereference_protected(tun->steering_prog,
+ lock_is_held(&tun->lock));
rcu_assign_pointer(tun->steering_prog, new);
+ spin_unlock(&tun->lock);
if (old)
call_rcu(&old->rcu, tun_steering_prog_free);
@@ -2067,9 +2070,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)
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] tuntap: fix possible deadlock when fail to register netdev
2017-12-08 2:54 [PATCH net-next] tuntap: fix possible deadlock when fail to register netdev Jason Wang
@ 2017-12-08 3:11 ` Eric Dumazet
2017-12-08 3:27 ` Jason Wang
0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2017-12-08 3:11 UTC (permalink / raw)
To: Jason Wang, netdev, linux-kernel; +Cc: mst, Willem de Bruijn
On Fri, 2017-12-08 at 10:54 +0800, Jason Wang wrote:
> 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: 96f84061620c ("tun: add eBPF based queue selection method")
> Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
> Cc: Eric Dumazet <eric.dumazet@gmail.com>
> Cc: Willem de Bruijn <willemb@google.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> drivers/net/tun.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 787cc35..f7ccd79 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -2050,8 +2050,11 @@ static int __tun_set_steering_ebpf(struct
> tun_struct *tun,
> new->prog = prog;
> }
>
> - old = rtnl_dereference(tun->steering_prog);
> + spin_lock(&tun->lock);
> + old = rcu_dereference_protected(tun->steering_prog,
> + lock_is_held(&tun->lock));
> rcu_assign_pointer(tun->steering_prog, new);
> + spin_unlock(&tun->lock);
>
Hi Jason, thank you for the following up.
Have you tested this code path with lockdep enabled ?
My gut feeling is that you need spin_lock_bh() here.
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] tuntap: fix possible deadlock when fail to register netdev
2017-12-08 3:11 ` Eric Dumazet
@ 2017-12-08 3:27 ` Jason Wang
0 siblings, 0 replies; 3+ messages in thread
From: Jason Wang @ 2017-12-08 3:27 UTC (permalink / raw)
To: Eric Dumazet, netdev, linux-kernel; +Cc: mst, Willem de Bruijn
On 2017年12月08日 11:11, Eric Dumazet wrote:
> On Fri, 2017-12-08 at 10:54 +0800, Jason Wang wrote:
>> 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: 96f84061620c ("tun: add eBPF based queue selection method")
>> Reported-by: Eric Dumazet <eric.dumazet@gmail.com>
>> Cc: Eric Dumazet <eric.dumazet@gmail.com>
>> Cc: Willem de Bruijn <willemb@google.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>> drivers/net/tun.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>> index 787cc35..f7ccd79 100644
>> --- a/drivers/net/tun.c
>> +++ b/drivers/net/tun.c
>> @@ -2050,8 +2050,11 @@ static int __tun_set_steering_ebpf(struct
>> tun_struct *tun,
>> new->prog = prog;
>> }
>>
>> - old = rtnl_dereference(tun->steering_prog);
>> + spin_lock(&tun->lock);
>> + old = rcu_dereference_protected(tun->steering_prog,
>> + lock_is_held(&tun->lock));
>> rcu_assign_pointer(tun->steering_prog, new);
>> + spin_unlock(&tun->lock);
>>
> Hi Jason, thank you for the following up.
>
> Have you tested this code path with lockdep enabled ?
No I test without it.
>
> My gut feeling is that you need spin_lock_bh() here.
>
> Thanks
>
Yes, I miss the fact this the lock is used by e.g flow caches too. Will
post V2.
Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-12-08 3:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-08 2:54 [PATCH net-next] tuntap: fix possible deadlock when fail to register netdev Jason Wang
2017-12-08 3:11 ` Eric Dumazet
2017-12-08 3:27 ` Jason Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox