Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2933266iog; Mon, 20 Jun 2022 07:46:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vTAWPy2sexO7ds6KCiuWuqGuWTndyIc5CdL0/7ffeS0QPyLbgSKDHjCMyJ+fzC3g9S5PO6 X-Received: by 2002:a17:90b:4a42:b0:1ec:adee:e298 with SMTP id lb2-20020a17090b4a4200b001ecadeee298mr4928574pjb.161.1655736400746; Mon, 20 Jun 2022 07:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655736400; cv=none; d=google.com; s=arc-20160816; b=Oy33Jp8McNz1ZyBFuV+40Hv5Zux7zXewUWGA2BxLtAf/QKyr9k2T5AWbODQAThn32t tDMHe/SR810nYxwGMEeaeILZ+w8lezdXlng9C8FrLp8VWDc3rxjXTVc+sLndEl2IwA+F t36pfZSDozfAg4m+lKbHyGPtjMm7vFeQ7MDfjAv0aO83iocEOgtLREkWS6CR9rqDs04U ridGVksqrr6evCM030C+CNoHJc4E4SQ1Ivbcmpv+MrZ0SJrZhLz7Wjp+g2kEyem76RoA Ed0ZOD3Rma5iANZ/uTRtNcUCns/2OMQ0mJzDwE7eY7W5xN2aYtl5rt/dtemm5SPB1VBy VklA== 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=yUAAyqSUHhzcwYcP3kI/7tVFXHdP73WwgqmhpKz6Z8M=; b=nJwr+U7LTbDdTQ4LSlisb110C7gGxx6l70kANTs5N5W1s82lVktm0hzHdxDO0x3YWg o1gWxA1qZrMmUfC19LQmNHI4Vjnthu7ZIXbt9sYF0EigZCmVkWswcuv0XBWuBUtqbP4N BtJzPIqCyvRf5fsRavmG73y8ZuMcdKxOMiQQzP/yOCTy/qR0IghFUO0mA0ntl9pKxkqe iIhj3QSJ9kWSFotvSjM2rgJYTDCDFzlEILnlPiZnhaL1CyeNXbMER9Kvp91IfUmZ7cMG QTfN0rjAiOb9kKwEFif3ki0+EW3Q0+Ccp42nRsR6DUH30QtGAWMoEYfvn9/SE6js9aIt FRGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Iy0fn3K5; 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 r8-20020a634408000000b004051ff78ee2si16251848pga.454.2022.06.20.07.46.28; Mon, 20 Jun 2022 07:46:40 -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=Iy0fn3K5; 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 S1346391AbiFTNjz (ORCPT + 99 others); Mon, 20 Jun 2022 09:39:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346930AbiFTNiC (ORCPT ); Mon, 20 Jun 2022 09:38:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53F651F2DA; Mon, 20 Jun 2022 06:14:12 -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 F41FB60A21; Mon, 20 Jun 2022 13:14:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 008FDC3411C; Mon, 20 Jun 2022 13:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655730850; bh=XxK0OtvwNhgUMCOyhriJ/+qNy/K+HjGgOW3wfyCgR3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iy0fn3K5kTz3c8H0QVEhk0cqLfticW76N0FARTivMB9rylQiSDG+cXeeDEfBfJ95v 2747trTdywZdAdIAkbeBYx+S+810mM8QTz9XSR+vxowdHgMxv5Msvo8is0Q8WSDWg1 GLe1Egt8tWo7YLniNftM+bHlpXBpO/SeKwm1jdiA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Dominik Brodowski , Eric Biggers , "Jason A. Donenfeld" Subject: [PATCH 5.4 076/240] random: ensure early RDSEED goes through mixer on init Date: Mon, 20 Jun 2022 14:49:37 +0200 Message-Id: <20220620124740.824953394@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 a02cf3d0dd77244fd5333ac48d78871de459ae6d upstream. Continuing the reasoning of "random: use RDSEED instead of RDRAND in entropy extraction" from this series, at init time we also don't want to be xoring RDSEED directly into the crng. Instead it's safer to put it into our entropy collector and then re-extract it, so that it goes through a hash function with preimage resistance. As a matter of hygiene, we also order these now so that the RDSEED byte are hashed in first, followed by the bytes that are likely more predictable (e.g. utsname()). Cc: Theodore Ts'o Reviewed-by: Dominik Brodowski Reviewed-by: Eric Biggers Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1208,24 +1208,18 @@ int __init rand_initialize(void) bool arch_init = true; unsigned long rv; - mix_pool_bytes(&now, sizeof(now)); for (i = BLAKE2S_BLOCK_SIZE; i > 0; i -= sizeof(rv)) { - if (!arch_get_random_seed_long(&rv) && - !arch_get_random_long(&rv)) - rv = random_get_entropy(); - mix_pool_bytes(&rv, sizeof(rv)); - } - mix_pool_bytes(utsname(), sizeof(*(utsname()))); - - extract_entropy(&primary_crng.state[4], sizeof(u32) * 12); - for (i = 4; i < 16; i++) { if (!arch_get_random_seed_long_early(&rv) && !arch_get_random_long_early(&rv)) { rv = random_get_entropy(); arch_init = false; } - primary_crng.state[i] ^= rv; + mix_pool_bytes(&rv, sizeof(rv)); } + mix_pool_bytes(&now, sizeof(now)); + mix_pool_bytes(utsname(), sizeof(*(utsname()))); + + extract_entropy(&primary_crng.state[4], sizeof(u32) * 12); if (arch_init && trust_cpu && crng_init < 2) { invalidate_batched_entropy(); crng_init = 2;