All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] l2tp: fix use-after-free during module unload
@ 2016-08-30 14:05 Sabrina Dubroca
  2016-08-30 17:51 ` Sergei Shtylyov
  2016-09-01 23:34 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Sabrina Dubroca @ 2016-08-30 14:05 UTC (permalink / raw)
  To: netdev; +Cc: Sabrina Dubroca

Tunnel deletion is delayed by both a workqueue (l2tp_tunnel_delete -> wq
 -> l2tp_tunnel_del_work) and RCU (sk_destruct -> RCU ->
l2tp_tunnel_destruct).

By the time l2tp_tunnel_destruct() runs to destroy the tunnel and finish
destroying the socket, the private data reserved via the net_generic
mechanism has already been freed, but l2tp_tunnel_destruct() actually
uses this data.

Make sure tunnel deletion for the netns has completed before returning
from l2tp_net_exit() by first flushing the tunnel removal workqueue, and
then waiting for RCU callbacks to complete.

Fixes: 167eb17e0b17 ("l2tp: create tunnel sockets in the right namespace")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/l2tp/l2tp_core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 1e40dacaa137..a2ed3bda4ddc 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -1855,6 +1855,9 @@ static __net_exit void l2tp_exit_net(struct net *net)
 		(void)l2tp_tunnel_delete(tunnel);
 	}
 	rcu_read_unlock_bh();
+
+	flush_workqueue(l2tp_wq);
+	rcu_barrier();
 }
 
 static struct pernet_operations l2tp_net_ops = {
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] l2tp: fix use-after-free during module unload
  2016-08-30 14:05 [PATCH net] l2tp: fix use-after-free during module unload Sabrina Dubroca
@ 2016-08-30 17:51 ` Sergei Shtylyov
  2016-09-01 23:34 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Sergei Shtylyov @ 2016-08-30 17:51 UTC (permalink / raw)
  To: Sabrina Dubroca, netdev

Hello.

On 08/30/2016 05:05 PM, Sabrina Dubroca wrote:

> Tunnel deletion is delayed by both a workqueue (l2tp_tunnel_delete -> wq
>  -> l2tp_tunnel_del_work) and RCU (sk_destruct -> RCU ->
> l2tp_tunnel_destruct).
>
> By the time l2tp_tunnel_destruct() runs to destroy the tunnel and finish
> destroying the socket, the private data reserved via the net_generic
> mechanism has already been freed, but l2tp_tunnel_destruct() actually
> uses this data.
>
> Make sure tunnel deletion for the netns has completed before returning
> from l2tp_net_exit() by first flushing the tunnel removal workqueue, and

    The patch tells me the function is named l2tp_exit_net(). :-)

> then waiting for RCU callbacks to complete.
>
> Fixes: 167eb17e0b17 ("l2tp: create tunnel sockets in the right namespace")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> ---
>  net/l2tp/l2tp_core.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
> index 1e40dacaa137..a2ed3bda4ddc 100644
> --- a/net/l2tp/l2tp_core.c
> +++ b/net/l2tp/l2tp_core.c
> @@ -1855,6 +1855,9 @@ static __net_exit void l2tp_exit_net(struct net *net)
>  		(void)l2tp_tunnel_delete(tunnel);
>  	}
>  	rcu_read_unlock_bh();
> +
> +	flush_workqueue(l2tp_wq);
> +	rcu_barrier();
>  }
>
>  static struct pernet_operations l2tp_net_ops = {

MBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] l2tp: fix use-after-free during module unload
  2016-08-30 14:05 [PATCH net] l2tp: fix use-after-free during module unload Sabrina Dubroca
  2016-08-30 17:51 ` Sergei Shtylyov
@ 2016-09-01 23:34 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-09-01 23:34 UTC (permalink / raw)
  To: sd; +Cc: netdev

From: Sabrina Dubroca <sd@queasysnail.net>
Date: Tue, 30 Aug 2016 16:05:16 +0200

> Tunnel deletion is delayed by both a workqueue (l2tp_tunnel_delete -> wq
>  -> l2tp_tunnel_del_work) and RCU (sk_destruct -> RCU ->
> l2tp_tunnel_destruct).
> 
> By the time l2tp_tunnel_destruct() runs to destroy the tunnel and finish
> destroying the socket, the private data reserved via the net_generic
> mechanism has already been freed, but l2tp_tunnel_destruct() actually
> uses this data.
> 
> Make sure tunnel deletion for the netns has completed before returning
> from l2tp_net_exit() by first flushing the tunnel removal workqueue, and
> then waiting for RCU callbacks to complete.
> 
> Fixes: 167eb17e0b17 ("l2tp: create tunnel sockets in the right namespace")
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>

Please resubmit this with Sergei's feedback addressed.

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-01 23:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-30 14:05 [PATCH net] l2tp: fix use-after-free during module unload Sabrina Dubroca
2016-08-30 17:51 ` Sergei Shtylyov
2016-09-01 23:34 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.