Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6130516iog; Thu, 23 Jun 2022 12:00:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s5VtcrPtj3HrqV4eAHS8yN6iODsW4vdqWl7UOOullV6wzX1XPixkKgLbdmH1uEMNu51EjK X-Received: by 2002:a05:6402:320f:b0:435:7236:e312 with SMTP id g15-20020a056402320f00b004357236e312mr12665448eda.115.1656010826010; Thu, 23 Jun 2022 12:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656010826; cv=none; d=google.com; s=arc-20160816; b=J/XrVoje61SndLayCmqnsHC5ZV2cKt1uN4dMQFVdeOunxO0KiLNFIujPZ5a3Qr6qLK P4SV3IDqa/47c5mLDbTGL8TuS61SMWRat8W6dNr+T3/IUm94eDbqH2aLfrY5604LYUCU xsOKVgW0OhZF0EqN6tvi5vNZ0TrV+5o2ArazMmaDaQRI8afgGbrIOQBsXqgNF2jTvO8+ Omqv3rwSSAIIfS1ZWVw/12QtD9EfEvKmFxdak+2dzwaTQYnTQD+pg362AOfDUgu5C3eN vcom/krTnVKD3eiDbh1yMh5JkCxDDXSNlVOqZAexbp2WaPUD88qp4JEtZhYvq5rJAQSp 3Jhw== 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=cB9Uun6AyuSlgRmhyRoKrfH0uNpEfZKIJCIZEsPMSSs=; b=AmeBTjfmxV8qk41xYlwhdNZdaAsB8up/N2pMPhMA1aM3FfE/IxBFLQzJQd7bh9raNg Yux+ALbWGDDvUPShk3lMSlSkpjBD1L8r6hpqVi5OYabKPjlI6ARJIj1ldctBkH52kQFo 9PBUQ7WkImvicQTpNInHTJqzo+/GUqS3ezDDnTnA92ArS7IEGdLf8sreunyBg0oqacWU Fognhrw6OWu8Os/cPmQa1u+335CmTWI92rBH2bQGLOJZFuWGebQZEfK2/NkVK6WvxYMk cIGgEWTCNYEEdBVvC7oDTDgBhzKaPJO8wOwPH0ppcWh3bV+lLOj15qzhH4dEq6cInZAY uX1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rwskWJTx; 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 b15-20020a056402350f00b004357f76325dsi392556edd.294.2022.06.23.12.00.00; Thu, 23 Jun 2022 12:00:25 -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=rwskWJTx; 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 S229921AbiFWRKS (ORCPT + 99 others); Thu, 23 Jun 2022 13:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233523AbiFWRHv (ORCPT ); Thu, 23 Jun 2022 13:07:51 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FA98532CF; Thu, 23 Jun 2022 09:56:37 -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 sin.source.kernel.org (Postfix) with ESMTPS id D94FECE25D9; Thu, 23 Jun 2022 16:56:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1A92C3411B; Thu, 23 Jun 2022 16:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003391; bh=vJPXOeeC3FCKT/u6V/OCG3+dTJvaDL4jhwrp+j1TVh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rwskWJTxgDvoQhTqBK2+OMoO4yIgM4ZZQ9zwOJYwDbQxOJJbXYMFuUkMcukzkmXD1 whzJDTXwJQzSssai4Yg1mww7kzwTFePzIYToF8jxqn6TlWQxMXEzdnTBTazmNhpnCM 0AB/GWuchfExgoyCeTWihPbRnRbvrGWTH92ldEWE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" Subject: [PATCH 4.9 224/264] random: account for arch randomness in bits Date: Thu, 23 Jun 2022 18:43:37 +0200 Message-Id: <20220623164350.416389763@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164344.053938039@linuxfoundation.org> References: <20220623164344.053938039@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 @@ -810,7 +810,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) @@ -818,12 +818,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)); } @@ -835,7 +835,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; }