From: James Chapman <jchapman@katalix.com>
To: netdev@vger.kernel.org
Subject: [PATCH net-next v3 02/16] l2tp: add RCU read lock to protect tunnel ptr in ip socket destroy
Date: Mon, 12 Feb 2018 17:33:25 +0000 [thread overview]
Message-ID: <1518456819-22244-3-git-send-email-jchapman@katalix.com> (raw)
In-Reply-To: <1518456819-22244-1-git-send-email-jchapman@katalix.com>
If an L2TPIP socket is closed, add RCU protection when we deref
sk_user_data to prevent races with another thread closing the same
tunnel.
refcount_t: increment on 0; use-after-free.
WARNING: CPU: 2 PID: 2892 at lib/refcount.c:153 refcount_inc+0x2b/0x30
Modules linked in:
CPU: 2 PID: 2892 Comm: pppol2tp_chaos Not tainted 4.15.0-rc9+ #1
Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
RIP: 0010:refcount_inc+0x2b/0x30
RSP: 0018:ffff880014147b50 EFLAGS: 00010282
RAX: 000000000000002b RBX: ffff8800194785c0 RCX: 0000000000000000
RDX: 0000000000000001 RSI: ffff88001ad1f758 RDI: ffff88001ad1f758
RBP: ffff880014147b50 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000001 R12: ffff8800194785c8
R13: ffff8800194785c0 R14: ffff88001a2c6c20 R15: ffff880013a9d580
FS: 0000000000000000(0000) GS:ffff88001ad00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fbc17ea7000 CR3: 0000000003022000 CR4: 00000000000006e0
Call Trace:
l2tp_tunnel_delete+0x34/0x60
l2tp_ip_destroy_sock+0x6d/0x80
sk_common_release+0x19/0xd0
l2tp_ip_close+0x89/0xa0
inet_release+0x37/0x60
sock_release+0x1a/0x70
sock_close+0xd/0x20
__fput+0xed/0x1f0
____fput+0x9/0x10
task_work_run+0x77/0xb0
do_exit+0x311/0xcf0
do_group_exit+0x47/0xc0
get_signal+0x343/0x8e0
do_signal+0x23/0x780
? find_held_lock+0x39/0xb0
exit_to_usermode_loop+0x4a/0x93
syscall_return_slowpath+0x102/0x150
entry_SYSCALL_64_fastpath+0x98/0x9a
RIP: 0033:0x7fbc172d7fcf
RSP: 002b:00007ffd524cd4d8 EFLAGS: 00000246 ORIG_RAX: 000000000000000e
RAX: 0000000000000000 RBX: 0000000000000006 RCX: 00007fbc172d7fcf
RDX: 0000000000000000 RSI: 00007ffd524cd460 RDI: 0000000000000002
RBP: 0000000000404930 R08: 0000000000000000 R09: 00007ffd524cd460
R10: 0000000000000008 R11: 0000000000000246 R12: 000000000000001e
R13: 0000000000404a03 R14: 0000000000000000 R15: 0000000000000000
Code: 55 48 89 e5 e8 87 ff ff ff 84 c0 74 02 5d c3 80 3d 97 87 bb 01 00 75 f5 48 c7 c7 58 3e cc 82 c6 05 87 87 bb 01
Fixes: 0d76751fad ("l2tp: Add L2TPv3 IP encapsulation (no UDP) support")
Signed-off-by: James Chapman <jchapman@katalix.com>
---
net/l2tp/l2tp_ip.c | 5 ++++-
net/l2tp/l2tp_ip6.c | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index ff61124fdf59..42f3c2f72bf4 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -234,15 +234,18 @@ static void l2tp_ip_close(struct sock *sk, long timeout)
static void l2tp_ip_destroy_sock(struct sock *sk)
{
struct sk_buff *skb;
- struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk);
+ struct l2tp_tunnel *tunnel;
while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL)
kfree_skb(skb);
+ rcu_read_lock();
+ tunnel = rcu_dereference_sk_user_data(sk);
if (tunnel) {
l2tp_tunnel_closeall(tunnel);
sock_put(sk);
}
+ rcu_read_unlock();
sk_refcnt_debug_dec(sk);
}
diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
index 192344688c06..be4a3eee85a9 100644
--- a/net/l2tp/l2tp_ip6.c
+++ b/net/l2tp/l2tp_ip6.c
@@ -248,16 +248,19 @@ static void l2tp_ip6_close(struct sock *sk, long timeout)
static void l2tp_ip6_destroy_sock(struct sock *sk)
{
- struct l2tp_tunnel *tunnel = l2tp_sock_to_tunnel(sk);
+ struct l2tp_tunnel *tunnel;
lock_sock(sk);
ip6_flush_pending_frames(sk);
release_sock(sk);
+ rcu_read_lock();
+ tunnel = rcu_dereference_sk_user_data(sk);
if (tunnel) {
l2tp_tunnel_closeall(tunnel);
sock_put(sk);
}
+ rcu_read_unlock();
inet6_destroy_sock(sk);
}
--
1.9.1
next prev parent reply other threads:[~2018-02-12 17:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-12 17:33 [PATCH net-next v3 00/16] l2tp: fix API races discovered by syzbot James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 01/16] l2tp: update sk_user_data while holding sk_callback_lock James Chapman
2018-02-12 17:33 ` James Chapman [this message]
2018-02-12 17:33 ` [PATCH net-next v3 03/16] l2tp: don't use inet_shutdown on tunnel destroy James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 04/16] l2tp: refactor tunnel lifetime handling wrt its socket James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 05/16] l2tp: use tunnel closing flag James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 06/16] l2tp: refactor session lifetime handling James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 07/16] l2tp: hide sessions if they are closing James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 08/16] l2tp: hide session from pppol2tp_sock_to_session if it is closing James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 09/16] l2tp: refactor pppol2tp_connect James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 10/16] l2tp: add session_free callback James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 11/16] l2tp: do session destroy using a workqueue James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 12/16] l2tp: simplify l2tp_tunnel_closeall James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 13/16] l2tp: refactor ppp session cleanup paths James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 14/16] l2tp: remove redundant sk_user_data check when creating tunnels James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 15/16] l2tp: remove unwanted error message James Chapman
2018-02-12 17:33 ` [PATCH net-next v3 16/16] l2tp: make __l2tp_session_unhash internal James Chapman
2018-02-12 19:00 ` [PATCH net-next v3 00/16] l2tp: fix API races discovered by syzbot David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1518456819-22244-3-git-send-email-jchapman@katalix.com \
--to=jchapman@katalix.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).