netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Chapman <jchapman@katalix.com>
To: netdev@vger.kernel.org
Cc: kbuild-all@01.org
Subject: [PATCH net-next v2 03/16] l2tp: don't use inet_shutdown on tunnel destroy
Date: Mon, 12 Feb 2018 10:11:07 +0000	[thread overview]
Message-ID: <1518430280-16671-4-git-send-email-jchapman@katalix.com> (raw)
In-Reply-To: <1518430280-16671-1-git-send-email-jchapman@katalix.com>

Previously, if a tunnel was closed, we called inet_shutdown to mark
the socket as unconnected such that userspace would get errors and
then close the socket. This could race with userspace closing the
socket. Instead, leave userspace to close the socket in its own time
(our tunnel will be detached anyway).

Fixes: 309795f4be ("l2tp: Add netlink control API for L2TP")

 BUG: unable to handle kernel NULL pointer dereference at 00000000000000a0
 IP: __lock_acquire+0x263/0x1630
 PGD 0 P4D 0
 Oops: 0000 [#1] SMP KASAN
 Modules linked in:
 CPU: 2 PID: 42 Comm: kworker/u8:2 Not tainted 4.15.0-rc7+ #129
 Workqueue: l2tp l2tp_tunnel_del_work
 RIP: 0010:__lock_acquire+0x263/0x1630
 RSP: 0018:ffff88001a37fc70 EFLAGS: 00010002
 RAX: 0000000000000001 RBX: 0000000000000088 RCX: 0000000000000000
 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
 RBP: ffff88001a37fd18 R08: 0000000000000001 R09: 0000000000000000
 R10: 0000000000000000 R11: 00000000000076fd R12: 00000000000000a0
 R13: ffff88001a3722c0 R14: 0000000000000001 R15: 0000000000000000
 FS:  0000000000000000(0000) GS:ffff88001ad00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 00000000000000a0 CR3: 000000001730b000 CR4: 00000000000006e0
 Call Trace:
  ? __lock_acquire+0xc77/0x1630
  ? console_trylock+0x11/0xa0
  lock_acquire+0x117/0x230
  ? lock_sock_nested+0x3a/0xa0
  _raw_spin_lock_bh+0x3a/0x50
  ? lock_sock_nested+0x3a/0xa0
  lock_sock_nested+0x3a/0xa0
  inet_shutdown+0x33/0xf0
  l2tp_tunnel_del_work+0x60/0xef
  process_one_work+0x1ea/0x5f0
  ? process_one_work+0x162/0x5f0
  worker_thread+0x48/0x3e0
  ? trace_hardirqs_on+0xd/0x10
  kthread+0x108/0x140
  ? process_one_work+0x5f0/0x5f0
  ? kthread_stop+0x2a0/0x2a0
  ret_from_fork+0x24/0x30
 Code: 00 41 81 ff ff 1f 00 00 0f 87 7a 13 00 00 45 85 f6 49 8b 85
 68 08 00 00 0f 84 ae 03 00 00 c7 44 24 18 00 00 00 00 e9 f0 00 00 00 <49> 81 3c
 24 80 93 3f 83 b8 00 00 00 00 44 0f 44 c0 83 fe 01 0f
 RIP: __lock_acquire+0x263/0x1630 RSP: ffff88001a37fc70
 CR2: 00000000000000a0
---
 net/l2tp/l2tp_core.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index de7dce64173f..b68ae77e021e 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -1329,17 +1329,10 @@ static void l2tp_tunnel_del_work(struct work_struct *work)
 
 	sock = sk->sk_socket;
 
-	/* If the tunnel socket was created by userspace, then go through the
-	 * inet layer to shut the socket down, and let userspace close it.
-	 * Otherwise, if we created the socket directly within the kernel, use
+	/* If the tunnel socket was created within the kernel, use
 	 * the sk API to release it here.
-	 * In either case the tunnel resources are freed in the socket
-	 * destructor when the tunnel socket goes away.
 	 */
-	if (tunnel->fd >= 0) {
-		if (sock)
-			inet_shutdown(sock, 2);
-	} else {
+	if (tunnel->fd < 0) {
 		if (sock) {
 			kernel_sock_shutdown(sock, SHUT_RDWR);
 			sock_release(sock);
-- 
1.9.1

  parent reply	other threads:[~2018-02-12 10:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 10:11 [PATCH net-next v2 00/16] l2tp: fix API races discovered by syzbot James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 01/16] l2tp: update sk_user_data while holding sk_callback_lock James Chapman
2018-02-12 16:21   ` David Miller
2018-02-12 18:33   ` Guillaume Nault
2018-02-12 10:11 ` [PATCH net-next v2 02/16] l2tp: add RCU read lock to protect tunnel ptr in ip socket destroy James Chapman
2018-02-12 16:22   ` David Miller
2018-02-12 18:35   ` Guillaume Nault
2018-02-12 10:11 ` James Chapman [this message]
2018-02-12 16:22   ` [PATCH net-next v2 03/16] l2tp: don't use inet_shutdown on tunnel destroy David Miller
2018-02-12 17:23     ` James Chapman
2018-02-12 18:41   ` Guillaume Nault
2018-02-12 10:11 ` [PATCH net-next v2 04/16] l2tp: refactor tunnel lifetime handling wrt its socket James Chapman
2018-02-12 18:48   ` Guillaume Nault
2018-02-15  8:23   ` kbuild test robot
2018-02-12 10:11 ` [PATCH net-next v2 05/16] l2tp: use tunnel closing flag James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 06/16] l2tp: refactor session lifetime handling James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 07/16] l2tp: hide sessions if they are closing James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 08/16] l2tp: hide session from pppol2tp_sock_to_session if it is closing James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 09/16] l2tp: refactor pppol2tp_connect James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 10/16] l2tp: add session_free callback James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 11/16] l2tp: do session destroy using a workqueue James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 12/16] l2tp: simplify l2tp_tunnel_closeall James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 13/16] l2tp: refactor ppp session cleanup paths James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 14/16] l2tp: remove redundant sk_user_data check when creating tunnels James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 15/16] l2tp: remove unwanted error message James Chapman
2018-02-12 10:11 ` [PATCH net-next v2 16/16] l2tp: make __l2tp_session_unhash internal James Chapman
2018-02-12 18:52 ` [PATCH net-next v2 00/16] l2tp: fix API races discovered by syzbot Guillaume Nault

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=1518430280-16671-4-git-send-email-jchapman@katalix.com \
    --to=jchapman@katalix.com \
    --cc=kbuild-all@01.org \
    --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).