Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp972050pxb; Fri, 1 Apr 2022 00:43:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfuJqq5stGRbLC9bsC0Gp3kNQo511pGA6bh4iJkVVqOoe3uoBlQOhQ0KgSoWvfBbaq41RV X-Received: by 2002:a63:77ca:0:b0:386:25a5:5ed with SMTP id s193-20020a6377ca000000b0038625a505edmr13867975pgc.30.1648799007771; Fri, 01 Apr 2022 00:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648799007; cv=none; d=google.com; s=arc-20160816; b=fBu2IC4c4j4PpEkKLvbifisKdFg+yzaGX8suoWbczW+gDCRbpPy4+F+9xaQS0beymh myQ6m/wrG4E/35q+eFs+rqo1b/90aw65ED9OXGCFV41iKsAul6Jy/FiwPVXL/i82vy9Q S+MQsMrADoHa3tSdB9dfEPEKa6G70t7X79zMWK2BohluoZCw1zNKlSE4rU6pv2UOND0Z UZFUKdOWcjvVSYUyl8d9Noh1yrRpsA2AX7nZG5n9gpDO2TajPQLIYReeCvvow06aSjw9 JseDAC5urrS4F8Ix1I4IGDPgzm3XvoiB6NtRcSQTqrKxXC1WZYHkoTz2arX19wXM0ZJd aNxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gyym09nEXYz1vXWaGFoZImcv0N4xudomjsRouLwVCy4=; b=oZyv2nt1dHCnF2ukEUdbVz95xqHY1QpgaoC1IyghQo1hlVURi5DXeSeeB6pme+JvB1 4zXcjO55zuUqrya+OhdIcquFKN6f0IkEdT8RzVdrFIVOBEgcJ0ax49XfRSJEGWWOXsR6 XVO9orZSHoLmjzRYvNj1FoxlS22IrM/7gq1NgyI3mek/iM9z3LNuVaa8RiY5nOQdtkSc vle1Q0Xf42PFdXmKXqTVlYHCpKOevQwBd86isUkA3xJX2X6JLKvVvK9TU6IYCQDZhs+t LRuFt2setASqALVFNwcmbptrqiBYyUJSLMnG6Zt4uvwdwekOSRWgmYzHxOkUrm7MgTR+ h1Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=DwM2QVqb; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 41-20020a17090a0fac00b001c9e78218basi5256312pjz.84.2022.04.01.00.42.52; Fri, 01 Apr 2022 00:43:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=DwM2QVqb; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236235AbiCaP3w (ORCPT + 99 others); Thu, 31 Mar 2022 11:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233539AbiCaP3v (ORCPT ); Thu, 31 Mar 2022 11:29:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFC8C21BC64; Thu, 31 Mar 2022 08:28:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 523D961ADE; Thu, 31 Mar 2022 15:28:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D921C340ED; Thu, 31 Mar 2022 15:28:03 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="DwM2QVqb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1648740481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gyym09nEXYz1vXWaGFoZImcv0N4xudomjsRouLwVCy4=; b=DwM2QVqbYVkY7XhqfgI0zmYswv37XQd0+mcVx/kkeM9pTOt69bIUto5IDT4l4FWZ8SjmJI bfXjvJ6tZ/GNLay1m6nO0KKiWHtPK+NEQFeJA4j0M4bAX+9StqYV88sRYEGJDSh2d/OTYf xPp4tyIxl8WNEF1jT1K+LUyi3ikv5vQ= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 9011b3a2 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Thu, 31 Mar 2022 15:28:01 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: "Jason A. Donenfeld" , Dominik Brodowski , Theodore Ts'o Subject: [PATCH v2] random: mix build-time latent entropy into pool at init Date: Thu, 31 Mar 2022 11:26:41 -0400 Message-Id: <20220331152641.169301-1-Jason@zx2c4.com> In-Reply-To: <20220331150706.124075-1-Jason@zx2c4.com> References: <20220331150706.124075-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-crypto@vger.kernel.org Prior, the "input_pool_data" array needed no real initialization, and so it was easy to mark it with __latent_entropy to populate it during compile-time. In switching to using a hash function, this required us to specifically initialize it to some specific state, which means we dropped the __latent_entropy attribute. An unfortunate side effect was this meant the pool was no longer seeded using compile-time random data. In order to bring this back, we declare an array in rand_initialize() with __latent_entropy and call mix_pool_bytes() on that at init, which accomplishes the same thing as before. We make this __initconst, so that it doesn't take up space at runtime after init. Fixes: 6e8ec2552c7d ("random: use computational hash for entropy extraction") Cc: Dominik Brodowski Cc: Theodore Ts'o Signed-off-by: Jason A. Donenfeld --- Changes v1->v2: - Use __initconst. drivers/char/random.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/char/random.c b/drivers/char/random.c index 40107f8b9e9e..1d8242969751 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -975,6 +975,11 @@ int __init rand_initialize(void) bool arch_init = true; unsigned long rv; +#if defined(LATENT_ENTROPY_PLUGIN) + static const u8 compiletime_seed[BLAKE2S_BLOCK_SIZE] __initconst __latent_entropy; + _mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed)); +#endif + for (i = 0; i < BLAKE2S_BLOCK_SIZE; i += sizeof(rv)) { if (!arch_get_random_seed_long_early(&rv) && !arch_get_random_long_early(&rv)) { -- 2.35.1