Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp487583rwb; Mon, 26 Sep 2022 23:36:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM51A8iT4R7I/rksBtKM77O6c24do9Y51nnyMgLxUiy5MxG74HtonU5FG7ytY09yEt+jSHrX X-Received: by 2002:a17:902:7589:b0:178:4ded:a90a with SMTP id j9-20020a170902758900b001784deda90amr25955776pll.74.1664260616527; Mon, 26 Sep 2022 23:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664260616; cv=none; d=google.com; s=arc-20160816; b=NEgOeLz4wKHQpz9g+BSyXRAhyCCjxIdkNd2Cr8GfZa6E3VJxoARTP549I7BcPq2fS2 GaQRLsZYQwgl2EINO7R71t1p5uTe5mp7OvK4eRekRnG6uWlJl2BXYwwH/nkImyRzkmiq trm3HkHizGg5A3WRrStzt27kFNuOKRei1rZxQJxugaBE0EBmAzP2EUKnUQd8vvF+90VG KUxXGsFhJ7I0sAt8JKhHtA6AoX6NRat8Oe/BtLwZaDfmSnONxS/Kujo5jpAYVuXswYtf wShYa6jbiY8ylK+xSAxOyNINDC48lOWFwGxF96YqmaFNn+3mck2X6baoLCkMrNqfCric vHIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=SBMGM6+2Z/ixqQYdWeAELZ6LNs3350/MmWMj81IrLYw=; b=ISlZL/CxB0RPZsK3OoiVeFt3vMHOcZKyk42Gf0NkK1W+Qe3BYuMUlLEXEhGbAINSfn a1OYO6VOnggK4HkPHmHXgxiIhHN8a+BpN24TiVrpJWvz3HI5IrElYTQEUv5LWThjMcyS teHIUrNZstsF/L+nopRwhLGRvZUfR2onUNOj1Sr+2zFECq/y7LX0rG/szlHrxlarJAO/ 1r49aFRY86nwCG+uRzr6pIODiFT3Cp3dHgSf6Aa1kQgj3p3UBpFigk3N8l2ay/FEWiLS SOGGRoA8URYNAFVKU5It/wWDc0Dk8dVoe2NSnS8hEAOSo38zna9dXzo6SJiuRQVCL5AQ OHuw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo14-20020a17090b1c8e00b002008f10f7bcsi1192454pjb.17.2022.09.26.23.36.44; Mon, 26 Sep 2022 23:36:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230008AbiI0Gf1 (ORCPT + 99 others); Tue, 27 Sep 2022 02:35:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbiI0GfY (ORCPT ); Tue, 27 Sep 2022 02:35:24 -0400 Received: from isilmar-4.linta.de (isilmar-4.linta.de [136.243.71.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEBBC5D10A for ; Mon, 26 Sep 2022 23:35:19 -0700 (PDT) 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> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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