Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6147174iog; Thu, 23 Jun 2022 12:19:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ubVnqacs8g3bqwLjgGkfcRTILwzzMPCuu1VaBFYWa7BYK55mOCbSPOJt7oB0JxuyoO8sE0 X-Received: by 2002:a62:6411:0:b0:50a:81df:bfa6 with SMTP id y17-20020a626411000000b0050a81dfbfa6mr42674301pfb.26.1656011947380; Thu, 23 Jun 2022 12:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011947; cv=none; d=google.com; s=arc-20160816; b=X+pK7ZMpjuUoEqMsT6F4KujbBJtVUPhUfrNOHqtQ1rKpvAA7j4u5/nlk5yc5Hk4837 pKRr3qOUKUH7qHL/qFMisP/l+zmshZ4wDpjCHiX5FOGu4OfNI4IndX6DyQm2IjNuBuqn ihC6QR3Y6LxYn7yZ+Ypd+B5i2EapAfZ0GvC1zhn80trEc7zsRdBvCkJxXXhzkjuce9BF pjn9Jwqwj1vWsBIGHNFfyrRHWr6L4sMGQ+jou6TnSEyDdm0OXx13xF7UA+TncqXtmpF7 SXSu6z4Ltk/v3gx1baZTlzg0Jno7ylAqvG7VS3WVI2AjwLoxmQTJ6pHna7kSNGTsYiw6 z8eQ== 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=PQwxMLE2z7jBC0DsQ45EVx1cmK+Lwk8h7uuTmaA8/fY=; b=IYhVvbF6FCaPoJ/R46mFAAjscl6JRrZF5n4t+nZDGB7nHgrclYyIpWQRNaJ9+PjTQ7 jymCDXxLc+7vapiUIgd+Ph5aKpa+rDszTQcxRPmX2XZElby1MNJDdJNrzAhL2SuZcquj AVes4i0VjmfJ6IBZEggFPfKFEhM0WGpdJlqocDifjWHTsmbvOwJEA+IReeQtGw8I4glR rbJ9o/IlUOFkFsl6BF4e/MeMgIL8Z9e09CSofhZsWIVjA0gboPNWLzZAgfs6YUDwVHes GyyGK0Z5fL+XnzMEvM7pfnlvqUYmHa6LYjJUx4rD6cEvcuEs6Oi0FfTViYqvnoFrOKtK u15Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="N/8axGyw"; 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 j64-20020a638043000000b0040c9f150eacsi15953793pgd.568.2022.06.23.12.18.55; Thu, 23 Jun 2022 12:19:07 -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="N/8axGyw"; 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 S235644AbiFWR5L (ORCPT + 99 others); Thu, 23 Jun 2022 13:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236031AbiFWRxr (ORCPT ); Thu, 23 Jun 2022 13:53:47 -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 71589AC8D6; Thu, 23 Jun 2022 10:14:42 -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 2FDC8B82489; Thu, 23 Jun 2022 17:14:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DDE9C3411B; Thu, 23 Jun 2022 17:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004479; bh=NngK8zJ9xOgR7UIyAU/43ZE+nhhVWSxmb/OOH9fQejc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N/8axGywhq8hzLk1Tl/lfMePdNH8+/a2FKkuTlO48JPyOXLmA5J533TcvpY+46szX Dr6ZQ7ZU80npFX+SRR+1k2iDMxRaFcWqrF3QaZ+cJi6ykolyyXfTL+OczyhlIU66Ol 6xBKGtMZg1/CLyerrw//r6fPRw/HSVFm2N2fM8FE= 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 052/234] random: do not re-init if crng_reseed completes before primary init Date: Thu, 23 Jun 2022 18:41:59 +0200 Message-Id: <20220623164344.538866268@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 9c3ddde3f811aabbb83778a2a615bf141b4909ef upstream. If the bootloader supplies sufficient material and crng_reseed() is called very early on, but not too early that wqs aren't available yet, then we might transition to crng_init==2 before rand_initialize()'s call to crng_initialize_primary() made. Then, when crng_initialize_primary() is called, if we're trusting the CPU's RDRAND instructions, we'll needlessly reinitialize the RNG and emit a message about it. This is mostly harmless, as numa_crng_init() will allocate and then free what it just allocated, and excessive calls to invalidate_batched_entropy() aren't so harmful. But it is funky and the extra message is confusing, so avoid the re-initialization all together by checking for crng_init < 2 in crng_initialize_primary(), just as we already do in crng_reseed(). Reviewed-by: 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 @@ -829,7 +829,7 @@ static void __init crng_initialize_prima { memcpy(&crng->state[0], "expand 32-byte k", 16); _extract_entropy(&input_pool, &crng->state[4], sizeof(__u32) * 12, 0); - if (crng_init_try_arch_early(crng) && trust_cpu) { + if (crng_init_try_arch_early(crng) && trust_cpu && crng_init < 2) { invalidate_batched_entropy(); numa_crng_init(); crng_init = 2;