Received: by 10.192.165.148 with SMTP id m20csp2481515imm; Sun, 22 Apr 2018 07:58:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/uH/13/Y0VBHMaDRxr9ZWeySzA3tCenWljdrfCVpO1sGaKPi/cDpUUlUOsStIBR+70oSw/ X-Received: by 10.98.156.7 with SMTP id f7mr16890072pfe.104.1524409102142; Sun, 22 Apr 2018 07:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409102; cv=none; d=google.com; s=arc-20160816; b=RiFIneFVQ+QyErxiYH4YRBUJT7aH7Y5/Ijg8DUhHFwTBugHLbCJfLNGpRyujT8783f KW1LfCc5sAUswEWVElIy38S1fNNV/l7kpr5MTawYCkDnHTXKyKCTFa4xTcgK44Rri3hK QaKk8Rpf3aH7COKz+XrQLZpGI2vyHJwKuXmM5wggZ1gXSUXjt6qjcoV/JpQHdfUMidZQ /n4dhp6TDIvstD/irZuzErJmiWEwzhZtTUi1e3lCyxOk3LEP57MNOoWFxzbbBdZLFpAJ npofLxySWdUyBM/fB/drDqmEiYEw56L37jWG1C4PQmC2umZJLM66jr30Grbky8MrCFH3 vfjA== 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 :arc-authentication-results; bh=7kHqg/JNfvryGWxKKrd8XCM3JqM/pVyx951S/3IkKDc=; b=yCKwYUhpmzoM9qCoEZ2OHmAlU3STrbEYlBAVdxI8UbTRsHpHCKzmrAcGnmVFKZIdGf VafZuHqxuXhY5Th6y3Dq+Pz6oYJlZUCddsd1FHKzDsjNarV1SrCUJ9/meNQWyNXVS8NN BjCkEpZnWAtiUUBSpFP8JvGm/hfw9MDjYtUu2BpTKILjDrDmZAVWVPLCmEqjOhtFC3T5 aIwfLkoTnMU7FOHX0dvkpJWtxeYTAe4Lb+P+bfifcnnq1en/EGKVqE39HXELQLarppHg rHD5STWDRXAAJNEaHY5ux2EthKCAy5acLZdqGniETIP0/d80d4+M9rkEI4xGJyKY5anG V5Ag== 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 h2-v6si9490332plr.320.2018.04.22.07.58.07; Sun, 22 Apr 2018 07:58:22 -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 S1757046AbeDVOz6 (ORCPT + 99 others); Sun, 22 Apr 2018 10:55:58 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56108 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756925AbeDVOOG (ORCPT ); Sun, 22 Apr 2018 10:14:06 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C8A96CF3; Sun, 22 Apr 2018 14:14:05 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Theodore Tso , stable@kernel.org Subject: [PATCH 4.9 75/95] random: set up the NUMA crng instances after the CRNG is fully initialized Date: Sun, 22 Apr 2018 15:53:44 +0200 Message-Id: <20180422135213.491879480@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@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.9-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 @@ -818,6 +818,32 @@ static int crng_fast_load(const char *cp return 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 + static void crng_reseed(struct crng_state *crng, struct entropy_store *r) { unsigned long flags; @@ -847,6 +873,7 @@ static void crng_reseed(struct crng_stat memzero_explicit(&buf, sizeof(buf)); crng->init_time = jiffies; if (crng == &primary_crng && crng_init < 2) { + numa_crng_init(); crng_init = 2; process_random_ready_list(); wake_up_interruptible(&crng_init_wait); @@ -1659,28 +1686,9 @@ 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); - -#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);