Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2441081ioo; Sat, 28 May 2022 13:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwV2gIyRfBep7QQzTSWBU5Dzqmy6SMD7RwbMxDkXxw988TtJwe67dpZJHm0vCWixf+0QtF0 X-Received: by 2002:a17:902:cf4a:b0:161:64f4:52d8 with SMTP id e10-20020a170902cf4a00b0016164f452d8mr48540936plg.83.1653770905440; Sat, 28 May 2022 13:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653770905; cv=none; d=google.com; s=arc-20160816; b=tphnDzQ7D4ZQd4LB18HzJKPLyORH43ktYSwNTG7wT8iQ8X328n+jQZMaX3Il/aE1QV ythZhGMZtmHoMQcenCT886QIvB4+pVvCV0DhRCzFMW2tpdE9B5Ho/S+LZ77Y4X2P0sKc 828hkBSh6ALpdSDnZLyXOjmBtXTOz5kvv2pM4eAh1pVObZrXLtfIk3eSAh+OyaTTdhSk oiIBy5UEIJHUKIsozGaB6XIPoSVD8RTN57/LcMSMCPe/Qx0dXbmPPgy6y52LQxWhE/X0 PzWTUNDWwvIHPnNFTy9H96+KGDVsxPebMEIvMBmvLXj03zxUEzvY1QxgKWplw3yJFOVX GlnQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kTDrxLfnh2o+r/+iWX0QShTeJb24Hzc+ZJGJvqhL0BU=; b=t90MdzC8gADdfOU8nG4v9AqEMzbpnbyvTExNzpkdjM+Ba1MqxDmVUuxiGBcvbVQQ3V 6mJiTjSeg6oXvP6bqvN2/eg60ii9kUluIZMxnZSAYzAs+XILbIBdg9TzlxnFlDBrwFch gCJkMCHrHYB3qhnf4IbQH+ZWFjTR6sdue9oJOTwI4W0pcrdspMxenhAoFk/gBW5FCcbx kxQ6e0FpAgCsORhMqfTNTPaO0rLD+WQ063HnsLCPvMly63fzcef/++hvxE5cZjbQNUmR vs3W6bWc1Ti5jz7wRrn/nSOpNCwnJvp1xC1DuOeeS6GYf5fBFnbINq/We9M3k51Vpp4F Xrww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Eee3oIAU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d16-20020a056a00245000b005181502b103si11692790pfj.322.2022.05.28.13.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 13:48:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Eee3oIAU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C71156F91; Sat, 28 May 2022 12:57:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350042AbiE0I6x (ORCPT + 99 others); Fri, 27 May 2022 04:58:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345982AbiE0I6E (ORCPT ); Fri, 27 May 2022 04:58:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42323119909; Fri, 27 May 2022 01:54:46 -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 666DA61D52; Fri, 27 May 2022 08:54:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3923AC385A9; Fri, 27 May 2022 08:54:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653641685; bh=++xc5O0Pwzj5zTbMW+RdWvafvORy33rPu/1F0IGR7Uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eee3oIAUoQTm8G5AeFhfGPKj7MzpU8fGv/mBbXFpmPxVrJ9N63UZYoZ4tI6QaiiAl kd542vekUCQCCDlzaHrBlrgT3VvdfPnyui0HGu0bmJsbRBmIXjkQy4uQNvt1vON3B5 jy2c3uP7fg7WURbG9ju2kdA/KPRfN9et2OrAYvCk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Brodowski , "Jason A. Donenfeld" Subject: [PATCH 5.18 34/47] random: credit architectural init the exact amount Date: Fri, 27 May 2022 10:50:14 +0200 Message-Id: <20220527084807.032837553@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527084801.223648383@linuxfoundation.org> References: <20220527084801.223648383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: "Jason A. Donenfeld" commit 12e45a2a6308105469968951e6d563e8f4fea187 upstream. RDRAND and RDSEED can fail sometimes, which is fine. We currently initialize the RNG with 512 bits of RDRAND/RDSEED. We only need 256 bits of those to succeed in order to initialize the RNG. Instead of the current "all or nothing" approach, actually credit these contributions the amount that is actually contributed. Reviewed-by: Dominik Brodowski Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -899,9 +899,8 @@ early_param("random.trust_bootloader", p */ int __init random_init(const char *command_line) { - size_t i; ktime_t now = ktime_get_real(); - bool arch_init = true; + unsigned int i, arch_bytes; unsigned long rv; #if defined(LATENT_ENTROPY_PLUGIN) @@ -909,11 +908,12 @@ int __init random_init(const char *comma _mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed)); #endif - for (i = 0; i < BLAKE2S_BLOCK_SIZE; i += sizeof(rv)) { + for (i = 0, arch_bytes = BLAKE2S_BLOCK_SIZE; + i < BLAKE2S_BLOCK_SIZE; i += sizeof(rv)) { if (!arch_get_random_seed_long_early(&rv) && !arch_get_random_long_early(&rv)) { rv = random_get_entropy(); - arch_init = false; + arch_bytes -= sizeof(rv); } _mix_pool_bytes(&rv, sizeof(rv)); } @@ -924,8 +924,8 @@ int __init random_init(const char *comma if (crng_ready()) crng_reseed(); - else if (arch_init && trust_cpu) - credit_init_bits(BLAKE2S_BLOCK_SIZE * 8); + else if (trust_cpu) + credit_init_bits(arch_bytes * 8); return 0; }