From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB846C6FA86 for ; Tue, 27 Sep 2022 06:35:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 476828E00AE; Tue, 27 Sep 2022 02:35:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4261D8E00AA; Tue, 27 Sep 2022 02:35:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 317188E00AE; Tue, 27 Sep 2022 02:35:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 246338E00AA for ; Tue, 27 Sep 2022 02:35:21 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E6ACBA06AB for ; Tue, 27 Sep 2022 06:35:20 +0000 (UTC) X-FDA: 79956903600.15.2090DC0 Received: from isilmar-4.linta.de (isilmar-4.linta.de [136.243.71.142]) by imf04.hostedemail.com (Postfix) with ESMTP id 35A8140004 for ; Tue, 27 Sep 2022 06:35:20 +0000 (UTC) X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES Received: from owl.dominikbrodowski.net (owl.brodo.linta [10.2.0.111]) by isilmar-4.linta.de (Postfix) with ESMTPSA id C6814201327; Tue, 27 Sep 2022 06:35:17 +0000 (UTC) Received: by owl.dominikbrodowski.net (Postfix, from userid 1000) id 0FD2E80536; Tue, 27 Sep 2022 08:35:10 +0200 (CEST) Date: Tue, 27 Sep 2022 08:35:10 +0200 From: Dominik Brodowski To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, Kees Cook , Andrew Morton , stable@vger.kernel.org Subject: Re: [PATCH v2 1/2] random: split initialization into early step and later step Message-ID: References: <20220926213130.1508261-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220926213130.1508261-1-Jason@zx2c4.com> ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=none (imf04.hostedemail.com: domain of linux@dominikbrodowski.net has no SPF policy when checking 136.243.71.142) smtp.mailfrom=linux@dominikbrodowski.net; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664260520; a=rsa-sha256; cv=none; b=jKJT83aNDpLL6XyHmlYAo65jp6HYERCZy4zx+2P1z+J1x8tQPmXEL/cQpVXBPBwqFwdGhF RA/oRtvTYt+5Wq0RucmLeFr+EEKUaxhV/64NioLw9xQqmktpQPOxX95byR7R5xpNr+DRZD wo5TvPbzmSr06+8srU5UYALOH0g7iFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664260520; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SBMGM6+2Z/ixqQYdWeAELZ6LNs3350/MmWMj81IrLYw=; b=Pj60+LQu6k7JfLgxwWyMKiimIoEbxJZ+E7mOZpySEdFZ/MCHMxjs9AQ611EUcQfTsPF8K/ cT87iNIAMKM2xfedvSBTLjMFG2t0gFoxgdKvNvFIL7bwiHwm2KpEMXfiev3M9CWuMg3FXS 9lj0hLjloDu9i9BeLc4/isZ63S5TSDA= X-Stat-Signature: q6ux3joros6e7yufod3db47o9a9ec7ob X-Rspamd-Queue-Id: 35A8140004 Authentication-Results: imf04.hostedemail.com; dkim=none; spf=none (imf04.hostedemail.com: domain of linux@dominikbrodowski.net has no SPF policy when checking 136.243.71.142) smtp.mailfrom=linux@dominikbrodowski.net; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1664260520-566566 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Am Mon, Sep 26, 2022 at 11:31:29PM +0200 schrieb Jason A. Donenfeld: > The full RNG initialization relies on some timestamps, made possible > with general functions like time_init() and timekeeping_init(). However, > these are only available rather late in initialization. Meanwhile, other > things, such as memory allocator functions, make use of the RNG much > earlier. > > So split RNG initialization into two phases. We can give arch randomness > very early on, and then later, after timekeeping and such are available, > initialize the rest. > > This ensures that, for example, slabs are properly randomized if RDRAND > is available. Without this, CONFIG_SLAB_FREELIST_RANDOM=y loses a degree > of its security, because its random seed is potentially deterministic, > since it hasn't yet incorporated RDRAND. It also makes it possible to > use a better seed in kfence, which currently relies on only the cycle > counter. > > Another positive consequence is that on systems with RDRAND, running > with CONFIG_WARN_ALL_UNSEEDED_RANDOM=y results in no warnings at all. Nice improvement. One question, though: > #if defined(LATENT_ENTROPY_PLUGIN) > static const u8 compiletime_seed[BLAKE2S_BLOCK_SIZE] __initconst __latent_entropy; > @@ -803,34 +798,46 @@ int __init random_init(const char *command_line) > i += longs; > continue; > } > - entropy[0] = random_get_entropy(); > - _mix_pool_bytes(entropy, sizeof(*entropy)); > arch_bits -= sizeof(*entropy) * 8; > ++i; > } Previously, random_get_entropy() was mixed into the pool ARRAY_SIZE(entropy) times. > +/* > + * This is called a little bit after the prior function, and now there is > + * access to timestamps counters. Interrupts are not yet enabled. > + */ > +void __init random_init(void) > +{ > + unsigned long entropy = random_get_entropy(); > + ktime_t now = ktime_get_real(); > + > + _mix_pool_bytes(utsname(), sizeof(*(utsname()))); But now, it's only mixed into the pool once. Is this change on purpose? Thanks, Dominik