Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6048689iog; Thu, 23 Jun 2022 10:14:42 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLVlh3xylRMXsp6uOzwTsir44VSR5mt52QyjAqSpNAp/ra6zIkaJN2PAag5yKH/3n9W2Z5 X-Received: by 2002:a05:6402:430a:b0:435:8ec9:31ec with SMTP id m10-20020a056402430a00b004358ec931ecmr11977921edc.248.1656004482560; Thu, 23 Jun 2022 10:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656004482; cv=none; d=google.com; s=arc-20160816; b=EzjaTDyXYspxvCEMrkis2iVnNXyTY7SheDxSK/qYFGA+/93w8GYVeamOMM+2GbWe47 t0Kzaio5Dx9nAXA/QitXB4nsJqso3DFfbhRJRw2vHXKlYYElx+SG1U3FTpF6CyXPI7a1 M+Jvak63nvT+vdKoEUXFqQjZzPNC2qOJIJPXJ94O49jmMjoOVravnJ9HVtAuPEMx9ZTI iM2FIXsBFi41geugnQ8XICQbXoGxeoPrwBLRbrcn9y4y7x1HAxhkFnyXj3CG1hTAF0uD chVAZclWNGxhNb/bjmV7H5MRfmY5LF0BTLDvq9AX9qx1nSqvrqbhKnGl4YfoWLnm1wij fBbQ== 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=Qr5rsteFnYsQpOuej7Q8wwJ7zCki2nqLCBnPZtm+jXU=; b=g9oHkkc3Rc3jSc71fKo7qNPovsuf7nJZNTlNzjgS3ujMDmSWyuMCn+QX5+VANPKEdQ ys1OfaNCuEne9J11q7cNqYgDa3eu7H4vTXO37ydu2TznmpHDYOW0cZTjIU39CoeBcEZC QnLN/xSNGYo7LbO4b+4aX9C4pdHi3e7Pfn0dR+qroY7iRPzQxT34dpOQWz6yU0Y8COIC E0Kq6X31IAdSUka+D8QPMLJ+gkgsdCvV93KT5HTsnYv5rclDGJyjSCWXtHDn1Q/gbvNF xF28cRuDMUCHfnjdFNXoiJrZSnr2+jIXAaNrhAtmHG4yn0mRYodXGU2H2LsuXnRyjHjB X27Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hpGL4mb0; 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 ho15-20020a1709070e8f00b006fe9db42071si3027817ejc.720.2022.06.23.10.14.17; Thu, 23 Jun 2022 10:14:42 -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=hpGL4mb0; 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 S232966AbiFWRCS (ORCPT + 99 others); Thu, 23 Jun 2022 13:02:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233672AbiFWQ6H (ORCPT ); Thu, 23 Jun 2022 12:58:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 624774ECEC; Thu, 23 Jun 2022 09:53: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 1880861F99; Thu, 23 Jun 2022 16:53:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEE47C341CA; Thu, 23 Jun 2022 16:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003217; bh=M/IUnOHbECY2+i0S5JihLZ2sBBNn7J6lnIdzKb5aEuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hpGL4mb0pfXE6O8J63jTxfd6hnh6ptN1NK+kbhYKopTBIC/LKXuS+A6RjRt4WhPc1 fNw8d9+4ZJJYIEfReHGVTx2eVHRkgdckk3rh3jJ2RSd6lTckbB3dyOi0YW+FxrvfbR 3ecYvyKYpBk8FQi1cV05PZwpN712OS0pOefp0VMs= 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.9 166/264] random: skip fast_init if hwrng provides large chunk of entropy Date: Thu, 23 Jun 2022 18:42:39 +0200 Message-Id: <20220623164348.761271106@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 af704c856e888fb044b058d731d61b46eeec499d upstream. At boot time, EFI calls add_bootloader_randomness(), which in turn calls add_hwgenerator_randomness(). Currently add_hwgenerator_randomness() feeds the first 64 bytes of randomness to the "fast init" non-crypto-grade phase. But if add_hwgenerator_randomness() gets called with more than POOL_MIN_BITS of entropy, there's no point in passing it off to the "fast init" stage, since that's enough entropy to bootstrap the real RNG. The "fast init" stage is just there to provide _something_ in the case where we don't have enough entropy to properly bootstrap the RNG. But if we do have enough entropy to bootstrap the RNG, the current logic doesn't serve a purpose. So, in the case where we're passed greater than or equal to POOL_MIN_BITS of entropy, this commit makes us skip the "fast init" phase. Cc: Dominik Brodowski Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1121,7 +1121,7 @@ void rand_initialize_disk(struct gendisk void add_hwgenerator_randomness(const void *buffer, size_t count, size_t entropy) { - if (unlikely(crng_init == 0)) { + if (unlikely(crng_init == 0 && entropy < POOL_MIN_BITS)) { size_t ret = crng_pre_init_inject(buffer, count, true); mix_pool_bytes(buffer, ret); count -= ret;