Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6131568iog; Thu, 23 Jun 2022 12:01:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s0HW+m36vVqsrvLsu29ZAiSXCWk2a7JsifkCfMBede8lXzfmTBXM2gRd9eTcFUAsnmoYmV X-Received: by 2002:aa7:8889:0:b0:51c:41b6:6e2e with SMTP id z9-20020aa78889000000b0051c41b66e2emr42414291pfe.46.1656010892679; Thu, 23 Jun 2022 12:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656010892; cv=none; d=google.com; s=arc-20160816; b=nhnuSJrDes0Y+2tdHy86erTJOcp/vf+Un69kpugvBODLrXmRURCrrEALM8UVTYevrB TTGPYTpPC+DPx0w5zOsfY7+32ChardqCYuvUgZuOfkwBgsNnmu9x6JZFkgoEILWd4A93 V+x6JB8AExhHBM1HPqOoxVkLkr+aYr7YRX36z/TjgT78SKYMrOmlMzJSFM3zGfBXuzCA EafJki3anLVtZgvDqS7+/VqbiijMpCisVcqiscH9I1ERRb4177lEB4+3uY5Cq4zRnlnm 661i69/JpQbxUzekoMKHCosGRjqcsPBz65RxR/yEYjp5wUYTxvO2kf4Mjc2ugZsP/8Wq BNgw== 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=64V29H5Xi95ZW3TylPs4/JthxcXUrDfYVdoGbOa6PeA=; b=erI+M6RZeJCfLMwVrppyXN5H+aEkmtri6ipW1AYY5RZK+d7EUd0umwaZWL3fHXM369 +imrLiq04t0iAP0g6ZydSzbSH0ZkTn03KC75cEGcF+yohQGm0jWV9VZJkqdoJqn6oqmU rQpxXRdzqsTEtemo16KitC/uAnoYH6cpprqAIPWey30IF6sfWlbd3gleP7B5YkT+MkIu DT6xMrp6hnBVNDkNZAe/nA5ouGPEME/328/eQTmskhJ5k6EFP6aHzNMPHA4yo40WM/cJ 9nFiKviH0Rn+Qw1ayYK0pHWUzAn3H7FGRxaky5WRX0W+ttUtIR+r/whBu3irlbGVzm4B ye6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=w3MSHNBJ; 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 c11-20020a170903234b00b00161739962ffsi468740plh.163.2022.06.23.12.01.20; Thu, 23 Jun 2022 12:01:32 -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=w3MSHNBJ; 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 S236655AbiFWSPP (ORCPT + 99 others); Thu, 23 Jun 2022 14:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236535AbiFWSOg (ORCPT ); Thu, 23 Jun 2022 14:14:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1217A9B772; Thu, 23 Jun 2022 10:21:21 -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 8E1B1B82490; Thu, 23 Jun 2022 17:21:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E38A8C3411B; Thu, 23 Jun 2022 17:21:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004878; bh=YEOkS9rYWaYZ21ChQDwOws+yUKUG4JodqoNMAASmEAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w3MSHNBJPF6/0jCXg1qnGtbnZ2JvwQ8Nr+SnG2rQ5hu/6J7KF0qSpyUjpq/UUC0FW wsJVj9ZJoDyy6JjU+OejqCeK4o2x5uFJlyJkZolu5Uh7qzEn4oW12LdrJbISEEXVDx t3IUrdP+TR00htjDg/8htmsbxmDLTeFYcMfNf8oY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" Subject: [PATCH 4.19 180/234] random: account for arch randomness in bits Date: Thu, 23 Jun 2022 18:44:07 +0200 Message-Id: <20220623164348.144426488@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 77fc95f8c0dc9e1f8e620ec14d2fb65028fb7adc upstream. Rather than accounting in bytes and multiplying (shifting), we can just account in bits and avoid the shift. The main motivation for this is there are other patches in flux that expand this code a bit, and avoiding the duplication of "* 8" everywhere makes things a bit clearer. Cc: stable@vger.kernel.org Fixes: 12e45a2a6308 ("random: credit architectural init the exact amount") Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -809,7 +809,7 @@ early_param("random.trust_bootloader", p int __init random_init(const char *command_line) { ktime_t now = ktime_get_real(); - unsigned int i, arch_bytes; + unsigned int i, arch_bits; unsigned long entropy; #if defined(LATENT_ENTROPY_PLUGIN) @@ -817,12 +817,12 @@ int __init random_init(const char *comma _mix_pool_bytes(compiletime_seed, sizeof(compiletime_seed)); #endif - for (i = 0, arch_bytes = BLAKE2S_BLOCK_SIZE; + for (i = 0, arch_bits = BLAKE2S_BLOCK_SIZE * 8; i < BLAKE2S_BLOCK_SIZE; i += sizeof(entropy)) { if (!arch_get_random_seed_long_early(&entropy) && !arch_get_random_long_early(&entropy)) { entropy = random_get_entropy(); - arch_bytes -= sizeof(entropy); + arch_bits -= sizeof(entropy) * 8; } _mix_pool_bytes(&entropy, sizeof(entropy)); } @@ -834,7 +834,7 @@ int __init random_init(const char *comma if (crng_ready()) crng_reseed(); else if (trust_cpu) - _credit_init_bits(arch_bytes * 8); + _credit_init_bits(arch_bits); return 0; }