Received: by 10.192.165.148 with SMTP id m20csp4156434imm; Mon, 30 Apr 2018 12:51:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoOv96j9eND7XFguBiHWhIbU+eLZNrJ28TGdXnlYatxldDjOQgZAWn7nP3qrry4dAIC5DT2 X-Received: by 2002:a17:902:8c91:: with SMTP id t17-v6mr13838106plo.182.1525117869437; Mon, 30 Apr 2018 12:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117869; cv=none; d=google.com; s=arc-20160816; b=cpjXQM6o9xchpqJU8SbJUcwNsZJcgfD0jdWdcMB7LDwRhfAfpXfiErYisWp4VcAC+8 QGMSZEoQwKFpEwyWNK81MQ9yj1tilzGqML47J0S5N8INJuGcrXLf8oSg7tB3O8Hxrf3r /43LMUf6PXOuxYeIJUUQ0+sC3NTHFDaSDsXZ6XedpOMlk2fxd/bY9sL8dnqR60oNFucY 8xIA5soeUsWs9OQDN7bTEMn1Jto2qK4I/96V7+VD2qC9bDQ33yc+F81glFxp67rJSYNQ L3JyHb6wIr2Mj9FJQlSUzjeAvL+KNW2rSeH2mkx7iEBc3/yu0mdtRy+ig3oNjr9f8p7r bHZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=pC7AIVFl1dYCQOFvkOidnzo7QLpcr5CtVjy/WpOfohw=; b=QsD++GnxEvHC0UCE1g/mHa2qIfMb4+erKx+30Bm8FzRw0Fm2WZDX6Ued+W2ojyN3dO /b/Z/IzwUTKfpBIlxNY6hvliRusXrputZCsLarhda/BcmXklnWuHxO+/p8MjchoglYfJ uyvkJlD573ykaFJledgfL+RsjjKpsQCMykmlxpAwyW8ZqlxFBg9SzTxXFEHgnJpCWrgb 9/rbrcsFvYTxMCHmdEcqRg3MgBZPA6aZf7lGfPciqlrVEB9STzsRxcBapXUWF7S6AGK3 vTn2G2lKhIGgT1PidcaJMyuiSG/F52rlobPblxDuPC4BbSPHjvC9XtQvqO7wp/eqEzSU uOOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12-v6si6570331pge.252.2018.04.30.12.50.55; Mon, 30 Apr 2018 12:51:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756536AbeD3Ttp (ORCPT + 99 others); Mon, 30 Apr 2018 15:49:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:35592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755158AbeD3T2L (ORCPT ); Mon, 30 Apr 2018 15:28:11 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6622A22E02; Mon, 30 Apr 2018 19:28:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6622A22E02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Theodore Tso Subject: [PATCH 4.16 006/113] random: set up the NUMA crng instances after the CRNG is fully initialized Date: Mon, 30 Apr 2018 12:23:37 -0700 Message-Id: <20180430184015.339138140@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit 8ef35c866f8862df074a49a93b0309725812dea8 upstream. Until the primary_crng is fully initialized, don't initialize the NUMA crng nodes. Otherwise users of /dev/urandom on NUMA systems before the CRNG is fully initialized can get very bad quality randomness. Of course everyone should move to getrandom(2) where this won't be an issue, but there's a lot of legacy code out there. This related to CVE-2018-1108. Reported-by: Jann Horn Fixes: 1e7f583af67b ("random: make /dev/urandom scalable for silly...") Cc: stable@kernel.org # 4.8+ Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -787,6 +787,32 @@ static void crng_initialize(struct crng_ crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1; } +#ifdef CONFIG_NUMA +static void numa_crng_init(void) +{ + int i; + struct crng_state *crng; + struct crng_state **pool; + + pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL); + for_each_online_node(i) { + crng = kmalloc_node(sizeof(struct crng_state), + GFP_KERNEL | __GFP_NOFAIL, i); + spin_lock_init(&crng->lock); + crng_initialize(crng); + pool[i] = crng; + } + mb(); + if (cmpxchg(&crng_node_pool, NULL, pool)) { + for_each_node(i) + kfree(pool[i]); + kfree(pool); + } +} +#else +static void numa_crng_init(void) {} +#endif + /* * crng_fast_load() can be called by code in the interrupt service * path. So we can't afford to dilly-dally. @@ -893,6 +919,7 @@ static void crng_reseed(struct crng_stat spin_unlock_irqrestore(&crng->lock, flags); if (crng == &primary_crng && crng_init < 2) { invalidate_batched_entropy(); + numa_crng_init(); crng_init = 2; process_random_ready_list(); wake_up_interruptible(&crng_init_wait); @@ -1731,29 +1758,10 @@ static void init_std_data(struct entropy */ static int rand_initialize(void) { -#ifdef CONFIG_NUMA - int i; - struct crng_state *crng; - struct crng_state **pool; -#endif - init_std_data(&input_pool); init_std_data(&blocking_pool); crng_initialize(&primary_crng); crng_global_init_time = jiffies; - -#ifdef CONFIG_NUMA - pool = kcalloc(nr_node_ids, sizeof(*pool), GFP_KERNEL|__GFP_NOFAIL); - for_each_online_node(i) { - crng = kmalloc_node(sizeof(struct crng_state), - GFP_KERNEL | __GFP_NOFAIL, i); - spin_lock_init(&crng->lock); - crng_initialize(crng); - pool[i] = crng; - } - mb(); - crng_node_pool = pool; -#endif return 0; } early_initcall(rand_initialize);