Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6139388iog; Thu, 23 Jun 2022 12:09:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1szAQt7eEanJdHRvh64I3H/Ban4enpcuNJKISNbXL6HALzQnwgJaNjWyr7i/AKzwyLfdUEH X-Received: by 2002:a17:906:6483:b0:712:1bfe:eda2 with SMTP id e3-20020a170906648300b007121bfeeda2mr9336652ejm.306.1656011396614; Thu, 23 Jun 2022 12:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011396; cv=none; d=google.com; s=arc-20160816; b=ybBmxfGnrpnSXQ+SvudgFshvr1vEKuBpiAOuoCcKyfcA8ucZzySmYRn8rpckscDfmI l1Ne04yXc6xA1GbJnXszhNXwNZS9L+R81rSL5Rh/nR9Tof2Y62+P2MuHNUCTjta4a5ip TxsAXPwki3KHdWnVYLau7sXXzbVPG+yROHK5uSwX2/12qyrOqW/Ph/6pwnbrCUaEuOaG 5it6HKZwNwPIYjCeulp/eLiaJH+bvJ7n/yspSdR27Zzc8TgzP40D8hXPdUlR77Ftbik/ YVCjuuaMtBANxzlQ/lz0hd5wxBurvS5TwhanKvIS4zkJAxKgsCRXkYi+3ANc+00+vQVa z+FQ== 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=F97ChRkoctajL1fXJpdJSvEZHSbj/pZLwfkYAQQ7gcg=; b=v9OH7izcimtoshlGZb0lt5GZLY8oFD9x9KIF83FIToOPCfaXV4zIbSKQqv8A+Q1cs7 wdqHdUmiq8zW4OiRDixohpBjEdOErHQrpYuhaYi5DojuAelcHTpOz0aqXjsFqVeRXUR7 4Sb7ZqCpCSuzrXtDzCXAOJxVPf0NgsmnWRga5laBTSYPzVrz50xZ96iRY0FaStr+rZvL 9esj4b/cXTrCYqAJ725+j8DDN9ppnY3SEgg+GbQ0CsDGmQYrHSKA002qpzqsE0aq63xQ dRfHCravJD0tn326n3bP4eNUw8tOjca2sKKQCyQTgeWlKT0vmYDKTAeGSNGA2lM27/70 PCgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X09bLFR+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw8-20020a170907a0c800b00718ccb0a135si3474875ejc.507.2022.06.23.12.09.31; Thu, 23 Jun 2022 12:09: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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X09bLFR+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232949AbiFWSNV (ORCPT + 99 others); Thu, 23 Jun 2022 14:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234085AbiFWSMD (ORCPT ); Thu, 23 Jun 2022 14:12:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E3D9BD5FC; Thu, 23 Jun 2022 10:20:27 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7E458B82490; Thu, 23 Jun 2022 17:20:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6554C3411B; Thu, 23 Jun 2022 17:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004825; bh=IVqg8u+gF0ORv3w81IDPWbZ8HpMy12YNLIg3Mycg8fk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X09bLFR+sWOQ46JBCHF+z0rr6IBt5QYnRecp8z7KKdt7P4cneSaHP3p53U7Xc5Ngf H4ukPLtqd5DdKa6IKYLNlhrOISU7p4c0XLrLv4vORkUyu+wfDp/QavRtrfDLCrnFKf TfHuiIak/ySVW/ugbphGCyrDgfvoeKOzfmALP52g= 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 4.19 161/234] random: credit architectural init the exact amount Date: Thu, 23 Jun 2022 18:43:48 +0200 Message-Id: <20220623164347.610451960@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-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 @@ -891,9 +891,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) @@ -901,11 +900,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)); } @@ -916,8 +916,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; }