Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2933524iog; Mon, 20 Jun 2022 07:46:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sLUuDGRWcZikwZPZ1jDVi0fgaw5iW6THTw5al1+o4wlxpniLMbip9ivx6PoL6DfJ3YUOG6 X-Received: by 2002:a17:902:a607:b0:168:f08d:d04 with SMTP id u7-20020a170902a60700b00168f08d0d04mr24297932plq.70.1655736417623; Mon, 20 Jun 2022 07:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736417; cv=none; d=google.com; s=arc-20160816; b=dEAZc2SBSZr8Elwb7kH9Eo2plL37H6Nmvvyi2nlC2Hmec2PKFTVhnP29KJk2SNFcRL MRtJAiy2/67YeHji1TiLUTwZPj0xzdcxCwkkT/S4SDydHGhrmDyWlZ/raZu2atv0ouVX x14uTEw7y1cA02QdHNfls34hhqTxxJiXUhaO2iYkx6tVz07AGnjATKQmX4UtE6Wh90uW dLlMUAiq0KKmuEUF2mnErk7mnzFpF9cpOx8kA/a0img9TPOq/dWdpNP+Q5M9uSHLL17m tbissFuhNEuExsktLS2j6yrJHl99WEoBXeLp9p5442s2NXGoRHXJe0kZwwDPeRTVXQOc Ns6Q== 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=76eASVNU+K1V0FBPtqqUhQyvN7vN87iBGABPDc5nv5Y=; b=eHwMtZx0tbzml3rVGvcbLuyrsPiv+m1otZx6lI58Fscyb0+xPmEQ49kBnAi2Cak3I9 2HFU2SEsKF4tl3H2XDjZyiJ0ogudYFVLRnjYGg51+Y3veyHkEcWtfcBzBPPoi4XXV/ur dhwGXKpdUFC0JqWL+0l7BxL0QWjIemovkz+u1p0jxOWEiFOhwbsIfB1mT46532TA4GwB TSXZcnzslYlP2lWCu7R55gQ+eAymJqSQAxYNvH+HzGVUzCMyHeh/JX7JsTDn1fUZ0VD8 AANKvq26AgPqmbusM82H8QsoE2RGTbg4n3drmSNeAoxsDcgyocmbxNzUX8I8+kSahhnF UY4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eDa9nYR2; 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 d9-20020a656209000000b00408b78ce298si16469335pgv.669.2022.06.20.07.46.45; Mon, 20 Jun 2022 07:46:57 -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=eDa9nYR2; 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 S1348978AbiFTNu4 (ORCPT + 99 others); Mon, 20 Jun 2022 09:50:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349197AbiFTNsb (ORCPT ); Mon, 20 Jun 2022 09:48:31 -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 1097C2F03B; Mon, 20 Jun 2022 06:17:47 -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 427A8B811C6; Mon, 20 Jun 2022 13:16:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DBFAC3411B; Mon, 20 Jun 2022 13:16:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655730985; bh=kLu6oEFnz7kWzqySjKoPppP6306WDVKu2D0M9xJxpzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eDa9nYR2rklghfW4NFDB2DRU1lmpfU47m5lotZyGzXqqXMlH+a0uNYYpeL+C7RuEz sQJlT2QYBa9ijqDKBoadRxzYREndaTZupTRPZoF0CZ248gHFzMKcErUv0mASNZ7mKv 1VPuQ0YUmBDlMUXfNX+C5acDLmt32vH90Zi/9YyM= 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.4 118/240] random: skip fast_init if hwrng provides large chunk of entropy Date: Mon, 20 Jun 2022 14:50:19 +0200 Message-Id: <20220620124742.432273887@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124737.799371052@linuxfoundation.org> References: <20220620124737.799371052@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 @@ -1120,7 +1120,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;