From patchwork Mon Sep 21 07:58:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 11788681 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 780CD618 for ; Mon, 21 Sep 2020 08:00:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D07720874 for ; Mon, 21 Sep 2020 08:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726461AbgIUIAI (ORCPT ); Mon, 21 Sep 2020 04:00:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:57542 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726518AbgIUH70 (ORCPT ); Mon, 21 Sep 2020 03:59:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8BDA5B514; Mon, 21 Sep 2020 07:59:59 +0000 (UTC) From: Nicolai Stange To: "Theodore Y. Ts'o" Cc: linux-crypto@vger.kernel.org, LKML , Arnd Bergmann , Greg Kroah-Hartman , "Eric W. Biederman" , "Alexander E. Patrakov" , "Ahmed S. Darwish" , Willy Tarreau , Matthew Garrett , Vito Caputo , Andreas Dilger , Jan Kara , Ray Strode , William Jon McCann , zhangjs , Andy Lutomirski , Florian Weimer , Lennart Poettering , Peter Matthias , Marcelo Henrique Cerri , Roman Drahtmueller , Neil Horman , Randy Dunlap , Julia Lawall , Dan Carpenter , Andy Lavr , Eric Biggers , "Jason A. Donenfeld" , =?utf-8?q?Stephan_M=C3=BCller?= , Torsten Duwe , Petr Tesarik , Nicolai Stange Subject: [RFC PATCH 18/41] random: move arch_get_random_seed() calls in crng_reseed() into own loop Date: Mon, 21 Sep 2020 09:58:34 +0200 Message-Id: <20200921075857.4424-19-nstange@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200921075857.4424-1-nstange@suse.de> References: <20200921075857.4424-1-nstange@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org x86's RDSEED/RDRAND insns have reportedly been slowed down significantly due to the ucode update required to mitigate against the "Special Register Buffer Data Sampling" vulnerability (CVE-2020-0543) and should not get invoked from the interrupt path anymore. In preparation of getting rid of that arch_get_random_long() call currently found in add_interrupt_randomness(), move those arch_get_random_long() calls in crng_reseed() into a separate loop and outside of the crng->lock. There is no functional change. Signed-off-by: Nicolai Stange --- drivers/char/random.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index a49805d0d23c..1945249597e0 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1200,14 +1200,18 @@ static void crng_reseed(struct crng_state *crng, struct entropy_store *r) _crng_backtrack_protect(&primary_crng, buf.block, CHACHA_KEY_SIZE); } - spin_lock_irqsave(&crng->lock, flags); + for (i = 0; i < 8; i++) { unsigned long rv; if (!arch_get_random_seed_long(&rv) && !arch_get_random_long(&rv)) rv = random_get_entropy(); - crng->state[i+4] ^= buf.key[i] ^ rv; + buf.key[i] ^= rv; } + + spin_lock_irqsave(&crng->lock, flags); + for (i = 0; i < 8; i++) + crng->state[i+4] ^= buf.key[i]; memzero_explicit(&buf, sizeof(buf)); crng->init_time = jiffies; spin_unlock_irqrestore(&crng->lock, flags);