From patchwork Thu Jun 18 00:28:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Paasch X-Patchwork-Id: 486024 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 51507140284 for ; Thu, 18 Jun 2015 10:47:21 +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=c8fZ7lqH; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751869AbbFRArK (ORCPT ); Wed, 17 Jun 2015 20:47:10 -0400 Received: from mail-out7.apple.com ([17.151.62.29]:59965 "EHLO mail-in7.apple.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750856AbbFRArG (ORCPT ); Wed, 17 Jun 2015 20:47:06 -0400 X-Greylist: delayed 900 seconds by postgrey-1.27 at vger.kernel.org; Wed, 17 Jun 2015 20:47:06 EDT DKIM-Signature: v=1; a=rsa-sha256; d=apple.com; s=mailout2048s; c=relaxed/simple; q=dns/txt; i=@apple.com; t=1434587525; x=2298501125; 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=E+Q1N7F1kXBBney0hdoIpzvC/iOHQ++3Qgv5fr8u8+g=; b=c8fZ7lqHVtU3sbkfbQEdhUqM7HD450SgoSa+GILaE0Gdys4UgdeLov47tNeeM1td EY5RJ/PnolUM7nZtAiTBdP57+vugbMoiET5k2AdIrV2MHi0mMvkDX6A6qW4jmCvf RVu3FsfJ5JxVC47rl25SPO54tC+w4xON7gFpoYPCeXPLyNeFFwRzzL4ZOtQ8beTo usAyxmI32//nds5YnRQqdP6+RAOLz1nDcsShZOqy40U7REPR54YIj3lBcQkXwEkn edNe46uQwoUfc7y2hlxFW6p7JR5yOJiSLQGOXqgohVK31hPOJRX1qDIwosTimlkQ em5ssngeIBGZcHd8EAznpA==; Received: from relay6.apple.com (relay6.apple.com [17.128.113.90]) by mail-in7.apple.com (Apple Secure Mail Relay) with SMTP id 3C.6E.09370.58112855; Wed, 17 Jun 2015 17:32:05 -0700 (PDT) X-AuditID: 11973e16-f79856d00000249a-09-55821185f07a 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 3C.CE.14452.B1302855; Wed, 17 Jun 2015 16:30:35 -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 <0NQ400HYL6THTJ10@chicory.apple.com> for netdev@vger.kernel.org; Wed, 17 Jun 2015 17:32:05 -0700 (PDT) From: Christoph Paasch To: netdev@vger.kernel.org Cc: David Miller , Christoph Paasch , Hannes Frederic Sowa Subject: [PATCH net] Revert "tcp: switch tcp_fastopen key generation to net_get_random_once" Date: Wed, 17 Jun 2015 17:28:19 -0700 Message-id: <1434587299-60271-1-git-send-email-cpaasch@apple.com> X-Mailer: git-send-email 2.4.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrIJMWRmVeSWpSXmKPExsUi2FAYpdsq2BRqcPq2kcWxBWIOjB6fN8kF MEZx2aSk5mSWpRbp2yVwZfTsvsBW0GtUce9LP3sD436tLkZODgkBE4k7i1ayQthiEhfurWfr YuTiEBLYyyjxuKmXHabobk8jVKKfSWLxj22sEE4Xk8SSm81g7WwCWhJvb7eD2SICUhIfd2xn ByliFmhklFjct40JJCEsECex8tdqoCIODhYBVYkTrwJAwrwCjhIPN/RDbZOTuHJ9Otg2CYF5 rBIvXy5hmsDIt4CRYRWjUG5iZo5uZp65XmJBQU6qXnJ+7iZGUBhMtxPbwfhwldUhRgEORiUe XgauplAh1sSy4srcQ4zSHCxK4ryVbxtDhQTSE0tSs1NTC1KL4otKc1KLDzEycXBKNTAyeSre 3b87ujjXccEluUwfqZXrLf9NP9J+cjH/j7MiOVMY186pudyq8dci/nTu0RCB+cuvbZ3z/0VK 0fme683X+mKNjsxMqU9NrLoR2bu74ppo/rpDp7/VSlrM+N5zdvoDlWSGevHU1StCHi5k+xbX tuh/ZXjlHbFJfjJ8Km8e37nE5nWmWVVViaU4I9FQi7moOBEA1dqxKeQBAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrCJMWRmVeSWpSXmKPExsUi2FCcrCvN3BRq8PWinsWxBWIOjB6fN8kF MEZx2aSk5mSWpRbp2yVwZfTsvsBW0GtUce9LP3sD436tLkZODgkBE4m7PY1sELaYxIV764Fs Lg4hgX4micU/trFCOF1MEktuNrOCVLEJaEm8vd0OZosISEl83LGdHaSIWaCRUWJx3zYmkISw QJzEyl+rgYo4OFgEVCVOvAoACfMKOEo83NDPDrFNTuLK9elsExi5FzAyrGIUKErNSaw000ss KMhJ1UvOz93ECPZbYdQOxoblVocYBTgYlXh4P/xuDBViTSwrrsw9xCjBwawkwlv+ASjEm5JY WZValB9fVJqTWnyIUZqDRUmc9+WjhlAhgfTEktTs1NSC1CKYLBMHp1QDY920sqOrLl0+WX9Q cmUI17pnobds2Ncyl0jqzv5meT7TpmfhSamUj1XFlTUyZ9Q797TKV96uKt9Y/YTjf5a9sNjk Dz7bHvxX5NJePbU3ek06l+XsC2XP53778f3U/Z2fThTlGnmEhzsuyai6s7h6x5ej+Wsi+2yO 9F+NOV0VwDy7MPTvtDb3HUosxRmJhlrMRcWJAGMjQ77XAQAA Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This reverts commit 222e83d2e0aecb6a5e8d42b1a8d51332a1eba960. 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 There does not seem to be a better way to handle this. We could try to make the call to kmalloc and crypto_alloc_cipher during bootup, and then generate the random value only on-the-fly (when the first TFO-SYN comes in) with net_get_random_once in order to have the better entropy that comes with doing the late initialisation of the random value. But that's probably net-next material. Cc: Hannes Frederic Sowa Fixes: 222e83d2e0ae ("tcp: switch tcp_fastopen key generation to net_get_random_once") Signed-off-by: Christoph Paasch --- include/net/tcp.h | 1 - net/ipv4/sysctl_net_ipv4.c | 5 ----- net/ipv4/tcp_fastopen.c | 27 +++++++++++---------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 6d204f3f9df8..f27a4e6bae11 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1359,7 +1359,6 @@ bool tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, struct request_sock *req, struct tcp_fastopen_cookie *foc, struct dst_entry *dst); -void tcp_fastopen_init_key_once(bool publish); #define TCP_FASTOPEN_KEY_LENGTH 16 /* Fastopen key context */ diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index c3852a7ff3c7..46d6b3817b41 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -231,11 +231,6 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write, ret = -EINVAL; goto bad_key; } - /* Generate a dummy secret but don't publish it. This - * is needed so we don't regenerate a new key on the - * first invocation of tcp_fastopen_cookie_gen - */ - tcp_fastopen_init_key_once(false); tcp_fastopen_reset_cipher(user_key, TCP_FASTOPEN_KEY_LENGTH); } diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 46b087a27503..67377acff6a5 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -14,20 +14,6 @@ struct tcp_fastopen_context __rcu *tcp_fastopen_ctx; static DEFINE_SPINLOCK(tcp_fastopen_ctx_lock); -void tcp_fastopen_init_key_once(bool publish) -{ - static u8 key[TCP_FASTOPEN_KEY_LENGTH]; - - /* tcp_fastopen_reset_cipher publishes the new context - * atomically, so we allow this race happening here. - * - * All call sites of tcp_fastopen_cookie_gen also check - * for a valid cookie, so this is an acceptable risk. - */ - if (net_get_random_once(key, sizeof(key)) && publish) - tcp_fastopen_reset_cipher(key, sizeof(key)); -} - static void tcp_fastopen_ctx_free(struct rcu_head *head) { struct tcp_fastopen_context *ctx = @@ -78,8 +64,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) { @@ -313,3 +297,14 @@ fastopen: return false; } EXPORT_SYMBOL(tcp_try_fastopen); + +static int __init tcp_fastopen_init(void) +{ + __u8 key[TCP_FASTOPEN_KEY_LENGTH]; + + get_random_bytes(key, sizeof(key)); + tcp_fastopen_reset_cipher(key, sizeof(key)); + return 0; +} + +late_initcall(tcp_fastopen_init);