diff options
author | Alexander Couzens <lynxis@fe80.eu> | 2015-09-28 05:32:42 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-09-29 01:39:10 -0400 |
commit | 06a15f51cf3618e32a73871ee6a547ef7fd902b5 (patch) | |
tree | 5d7f25db11b5b985c7366d8bf954aeca976f2b2b | |
parent | 661dfc65f7981481ba2e31aaa702371e82336e56 (diff) |
l2tp: protect tunnel->del_work by ref_count
There is a small chance that tunnel_free() is called before tunnel->del_work scheduled
resulting in a zero pointer dereference.
Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
Acked-by: James Chapman <jchapman@katalix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/l2tp/l2tp_core.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index f6b090df3930..afca2eb4dfa7 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c | |||
@@ -1319,7 +1319,7 @@ static void l2tp_tunnel_del_work(struct work_struct *work) | |||
1319 | tunnel = container_of(work, struct l2tp_tunnel, del_work); | 1319 | tunnel = container_of(work, struct l2tp_tunnel, del_work); |
1320 | sk = l2tp_tunnel_sock_lookup(tunnel); | 1320 | sk = l2tp_tunnel_sock_lookup(tunnel); |
1321 | if (!sk) | 1321 | if (!sk) |
1322 | return; | 1322 | goto out; |
1323 | 1323 | ||
1324 | sock = sk->sk_socket; | 1324 | sock = sk->sk_socket; |
1325 | 1325 | ||
@@ -1341,6 +1341,8 @@ static void l2tp_tunnel_del_work(struct work_struct *work) | |||
1341 | } | 1341 | } |
1342 | 1342 | ||
1343 | l2tp_tunnel_sock_put(sk); | 1343 | l2tp_tunnel_sock_put(sk); |
1344 | out: | ||
1345 | l2tp_tunnel_dec_refcount(tunnel); | ||
1344 | } | 1346 | } |
1345 | 1347 | ||
1346 | /* Create a socket for the tunnel, if one isn't set up by | 1348 | /* Create a socket for the tunnel, if one isn't set up by |
@@ -1636,8 +1638,13 @@ EXPORT_SYMBOL_GPL(l2tp_tunnel_create); | |||
1636 | */ | 1638 | */ |
1637 | int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) | 1639 | int l2tp_tunnel_delete(struct l2tp_tunnel *tunnel) |
1638 | { | 1640 | { |
1641 | l2tp_tunnel_inc_refcount(tunnel); | ||
1639 | l2tp_tunnel_closeall(tunnel); | 1642 | l2tp_tunnel_closeall(tunnel); |
1640 | return (false == queue_work(l2tp_wq, &tunnel->del_work)); | 1643 | if (false == queue_work(l2tp_wq, &tunnel->del_work)) { |
1644 | l2tp_tunnel_dec_refcount(tunnel); | ||
1645 | return 1; | ||
1646 | } | ||
1647 | return 0; | ||
1641 | } | 1648 | } |
1642 | EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); | 1649 | EXPORT_SYMBOL_GPL(l2tp_tunnel_delete); |
1643 | 1650 | ||