From patchwork Thu Jun 18 16:15:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Paasch X-Patchwork-Id: 486380 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 498F31401F6 for ; Fri, 19 Jun 2015 02:16:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=apple.com header.i=@apple.com header.b=YmF+GdIe; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932356AbbFRQP4 (ORCPT ); Thu, 18 Jun 2015 12:15:56 -0400 Received: from mail-out4.apple.com ([17.151.62.26]:59561 "EHLO mail-in4.apple.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932319AbbFRQPw (ORCPT ); Thu, 18 Jun 2015 12:15:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; d=apple.com; s=mailout2048s; c=relaxed/simple; q=dns/txt; i=@apple.com; t=1434644151; x=2298557751; h=From:Sender:Reply-To:Subject:Date:Message-id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+F5PTnbB1ONY6pngZY1ik5LZ1x+kwNhsus5DL58ILkI=; b=YmF+GdIeyV+tXaDy4p1BjkQXxwdSD67w58bqAnszbtnrI6KO70QHMJXOf4jM0xCS qztuVyAFCKcj3762fltiET8TH094YXHEj5rTZfziKQUmQ74ejbSoZG0yl6S4Ef5Y B6WdYT4FWb5hWINMNy+JSKpm5JCMJq7BoVed5XjGaYwDT7jVrIAzdNKwP0FCv4uB u2PQiUe/gpC/usCIT1MXF64lceVJU23P9A2PDVf7hohfyr5SQM9y/hBZb0qzOa/D cnoLvP3NIYjJItDCvnU6gvq4tTLtK05Wk7TUXfR0UV8rxlqyz8DfDqztda17RSlA DfsaD/lkClVd12GM+fFBEA==; Received: from relay6.apple.com (relay6.apple.com [17.128.113.90]) by mail-in4.apple.com (Apple Secure Mail Relay) with SMTP id 89.04.18963.7BEE2855; Thu, 18 Jun 2015 09:15:51 -0700 (PDT) X-AuditID: 11973e12-f79456d000004a13-03-5582eeb76434 Received: from chicory.apple.com (chicory.apple.com [17.128.115.99]) (using TLS with cipher RC4-MD5 (128/128 bits)) (Client did not present a certificate) by relay6.apple.com (Apple SCV relay) with SMTP id AF.D0.14452.D40E2855; Thu, 18 Jun 2015 08:14:21 -0700 (PDT) Received: from localhost ([17.149.226.91]) by chicory.apple.com (Oracle Communications Messaging Server 7.0.5.30.0 64bit (built Oct 22 2013)) with ESMTPSA id <0NQ500NP5EIF1U50@chicory.apple.com> for netdev@vger.kernel.org; Thu, 18 Jun 2015 09:15:51 -0700 (PDT) From: Christoph Paasch To: David Miller Cc: netdev@vger.kernel.org, Christoph Paasch , Eric Dumazet , Hannes Frederic Sowa Subject: [PATCH net v2] tcp: Do not call tcp_fastopen_reset_cipher from interrupt context Date: Thu, 18 Jun 2015 09:15:34 -0700 Message-id: <1434644134-81335-1-git-send-email-cpaasch@apple.com> X-Mailer: git-send-email 2.4.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrIJMWRmVeSWpSXmKPExsUi2FAYpbv9XVOowavFuhbHFog5MHp83iQX wBjFZZOSmpNZllqkb5fAlfH/13ymgssaFT9Wv2VqYFyk1MXIySEhYCJxe/ICZghbTOLCvfVs XYxcHEICexkl5izeyAhT9OXwG2aIRD+TxNrDr1khnC4mie/PZ4C1swloSby93c4KYosIqElM PDEBrINZYB6jxLIFF8FGCQtES7Sf3ckEYrMIqErMnj8dqIiDg1fAUeJtM9Q2OYkr16eDnSEh sIhV4vrF/SwTGPkWMDKsYhTKTczM0c3MM9FLLCjISdVLzs/dxAgKg+l2QjsYT62yOsQowMGo xMPLwNUUKsSaWFZcmXuIUZqDRUmctyoLKCSQnliSmp2aWpBaFF9UmpNafIiRiYNTqoFRVvjK laUzmz9W6kZVqMzWkponNvNKxnmla+EPCzfsYmb8yGKaWHTZ6ymf97c9+dMWnPA4JqjOm3a2 1cR3zZ7Lk0tEXM++5VR//lEq8EPt3j+LNRoOBP3izFt8tfZWeey/tXz7DjBquZ0qfGDHsffa xbXyzTmO1Semzz1cu1Nuu3jGnJgfWbt2KbEUZyQaajEXFScCAFbP1CvkAQAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCJMWRmVeSWpSXmKPExsUi2FCcrOv7oCnUYPU0dYtjC8QcGD0+b5IL YIzisklJzcksSy3St0vgyvj/az5TwWWNih+r3zI1MC5S6mLk5JAQMJH4cvgNM4QtJnHh3nq2 LkYuDiGBfiaJtYdfs0I4XUwS35/PAKtiE9CSeHu7nRXEFhFQk5h4YgIzSBGzwDxGiWULLjKC JIQFoiXaz+5kArFZBFQlZs+fDlTEwcEr4CjxtpkRYpucxJXr09kmMHIvYGRYxShQlJqTWGmm l1hQkJOql5yfu4kR7LfCqB2MDcutDjEKcDAq8fB++N0YKsSaWFZcmXuIUYKDWUmEV+5aU6gQ b0piZVVqUX58UWlOavEhRmkOFiVx3pePGkKFBNITS1KzU1MLUotgskwcnFINjEX7uk+IFnYE +k1x+/RmfpvzvkVZTg8TDk1VFp725v8JjVpPg/upHQyFv262x9keP9AYIfX4v27HpjTpeuWz 28NFNSsWTPmxsHL2vEI3ndcTVWdkbrsRK+qe4Mx0x+HDY6X8yQ6arrLJN8IVRPhOcqRFbO7b 5JF6+uNWu0UXTVit5G0FFiQsV2Ipzkg01GIuKk4EANTEtgrXAQAA Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org tcp_fastopen_reset_cipher really cannot be called from interrupt context. It allocates the tcp_fastopen_context with GFP_KERNEL and calls crypto_alloc_cipher, which allocates all kind of stuff with GFP_KERNEL. Thus, we might sleep when the key-generation is triggered by an incoming TFO cookie-request which would then happen in interrupt- context, as shown by enabling CONFIG_DEBUG_ATOMIC_SLEEP: [ 36.001813] BUG: sleeping function called from invalid context at mm/slub.c:1266 [ 36.003624] in_atomic(): 1, irqs_disabled(): 0, pid: 1016, name: packetdrill [ 36.004859] CPU: 1 PID: 1016 Comm: packetdrill Not tainted 4.1.0-rc7 #14 [ 36.006085] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014 [ 36.008250] 00000000000004f2 ffff88007f8838a8 ffffffff8171d53a ffff880075a084a8 [ 36.009630] ffff880075a08000 ffff88007f8838c8 ffffffff810967d3 ffff88007f883928 [ 36.011076] 0000000000000000 ffff88007f8838f8 ffffffff81096892 ffff88007f89be00 [ 36.012494] Call Trace: [ 36.012953] [] dump_stack+0x4f/0x6d [ 36.014085] [] ___might_sleep+0x103/0x170 [ 36.015117] [] __might_sleep+0x52/0x90 [ 36.016117] [] kmem_cache_alloc_trace+0x47/0x190 [ 36.017266] [] ? tcp_fastopen_reset_cipher+0x42/0x130 [ 36.018485] [] tcp_fastopen_reset_cipher+0x42/0x130 [ 36.019679] [] tcp_fastopen_init_key_once+0x61/0x70 [ 36.020884] [] __tcp_fastopen_cookie_gen+0x1c/0x60 [ 36.022058] [] tcp_try_fastopen+0x58f/0x730 [ 36.023118] [] tcp_conn_request+0x3e8/0x7b0 [ 36.024185] [] ? __module_text_address+0x12/0x60 [ 36.025327] [] tcp_v4_conn_request+0x51/0x60 [ 36.026410] [] tcp_rcv_state_process+0x190/0xda0 [ 36.027556] [] ? __inet_lookup_established+0x47/0x170 [ 36.028784] [] tcp_v4_do_rcv+0x16d/0x3d0 [ 36.029832] [] ? security_sock_rcv_skb+0x16/0x20 [ 36.030936] [] tcp_v4_rcv+0x77a/0x7b0 [ 36.031875] [] ? iptable_filter_hook+0x33/0x70 [ 36.032953] [] ip_local_deliver_finish+0x92/0x1f0 [ 36.034065] [] ip_local_deliver+0x9a/0xb0 [ 36.035069] [] ? ip_rcv+0x3d0/0x3d0 [ 36.035963] [] ip_rcv_finish+0x119/0x330 [ 36.036950] [] ip_rcv+0x2e7/0x3d0 [ 36.037847] [] __netif_receive_skb_core+0x552/0x930 [ 36.038994] [] __netif_receive_skb+0x27/0x70 [ 36.040033] [] process_backlog+0xd2/0x1f0 [ 36.041025] [] net_rx_action+0x122/0x310 [ 36.042007] [] __do_softirq+0x103/0x2f0 [ 36.042978] [] do_softirq_own_stack+0x1c/0x30 This patch moves the call to tcp_fastopen_init_key_once to the places where a listener socket creates its TFO-state, which always happens in user-context (either from the setsockopt, or implicitly during the listen()-call) Cc: Eric Dumazet Cc: Hannes Frederic Sowa Fixes: 222e83d2e0ae ("tcp: switch tcp_fastopen key generation to net_get_random_once") Signed-off-by: Christoph Paasch Acked-by: Eric Dumazet --- Notes: v2: Instead of reverting Hannes' patch, move the call to tcp_fastopen_init_once to the places where we enable TFO on the server-side from user-context. net/ipv4/af_inet.c | 2 ++ net/ipv4/tcp.c | 7 +++++-- net/ipv4/tcp_fastopen.c | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 8b47a4d79d04..a5aa54ea6533 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -228,6 +228,8 @@ int inet_listen(struct socket *sock, int backlog) err = 0; if (err) goto out; + + tcp_fastopen_init_key_once(true); } err = inet_csk_listen_start(sk, backlog); if (err) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index f1377f2a0472..bb2ce74f6004 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2545,10 +2545,13 @@ static int do_tcp_setsockopt(struct sock *sk, int level, case TCP_FASTOPEN: if (val >= 0 && ((1 << sk->sk_state) & (TCPF_CLOSE | - TCPF_LISTEN))) + TCPF_LISTEN))) { + tcp_fastopen_init_key_once(true); + err = fastopen_init_queue(sk, val); - else + } else { err = -EINVAL; + } break; case TCP_TIMESTAMP: if (!tp->repair) diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 46b087a27503..f9c0fb84e435 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -78,8 +78,6 @@ static bool __tcp_fastopen_cookie_gen(const void *path, struct tcp_fastopen_context *ctx; bool ok = false; - tcp_fastopen_init_key_once(true); - rcu_read_lock(); ctx = rcu_dereference(tcp_fastopen_ctx); if (ctx) {