Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6145795iog; Thu, 23 Jun 2022 12:17:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uUSbLmXmMu3cgKJbPAM28SL3z+CEXxJiinTWCRkTwIIoFLb/9TbYirdavcWgFCl69YQ2cE X-Received: by 2002:a05:6a00:c89:b0:525:43d2:e925 with SMTP id a9-20020a056a000c8900b0052543d2e925mr10937487pfv.47.1656011841760; Thu, 23 Jun 2022 12:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011841; cv=none; d=google.com; s=arc-20160816; b=TLOQvdDyG6bYJ2D0xT9KcEopD7sIKNND1HzDjZqStAEb674WuNUr9ge1NFvEedC3Wg HpZ6GjqGBhqmX0jE6Qs6fKbjI0bQQOpc23N03JK/BaKGvR5Dk3GTf8rElysc7ZWw8jCE rIZaHLUTpkFgp/FcM+KUAOwxHMKN3A6kh7Ql82j1gwIQ9xC4KSCXC4lTpvi7KBLB8cfh 41i+xlKzAtIJ3d8g5ePBcoVkTSltOiVU8eQInMarmzBKMaFSnL17K34O3o+REsanRAxz 9TwsGI/gyA2czXZRQM5q8NZn3VM0cvH64RmyyUI2kdwWrSQ3uimjM6B2wOPKp9ko+21K PMQw== 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=I8w+0rvI3T08/fw8fLnplYH3DZurxiHJDyHY6noIFEec64cS5LTQNbtxLwoBkKN9Sx 2KIRG+3BBs/JDswZIU6hcXWbWOveu6DimSL2RDlIMoUi3C8Jxb7S5YwlvdgoJa1Enm5c 9j4sFsMmeuWvvhsbqioTk+BRv8oEAhq0BLRB1HxvIm28a2EQgifATTuxwIFS1EQC/yrV RMmfkDrbtU289qdEQ5bxRJ9usimD9p5uVO+njPfaMudQmeF/fLslzaLO8HyGkMIpX5dx FK8hWyfrG4OS35DpZt1C/dU1Bsf32FdgA3hT55k3q+tcSCG7zpq7QJrgAqe27g0lZlIK 7HNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dh6wpsBj; 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 4-20020a631444000000b003fcb1ba3c4fsi25361091pgu.313.2022.06.23.12.17.10; Thu, 23 Jun 2022 12:17:21 -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=dh6wpsBj; 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 S236135AbiFWSHC (ORCPT + 99 others); Thu, 23 Jun 2022 14:07:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236012AbiFWSGL (ORCPT ); Thu, 23 Jun 2022 14:06:11 -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 5C6D61DA45; Thu, 23 Jun 2022 10:18:36 -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 126C1B824B9; Thu, 23 Jun 2022 17:18:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6788BC3411B; Thu, 23 Jun 2022 17:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004713; bh=XxK0OtvwNhgUMCOyhriJ/+qNy/K+HjGgOW3wfyCgR3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dh6wpsBj+NFVwSyOB0+0I4R25ujqhhVmlpf114SIAzweRjYKjE7BbBUxJdX0CMZj1 2PTNOpT6HKIKR2boNuQ2n0VeGdu/6fzSC6ZR+tgsb/b092XTFDs3yXAoHZS91+9qas yUk1f77cJoMmaikCtymk6GnvvDRDONSTAvbZOOm0= 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 4.19 085/234] random: ensure early RDSEED goes through mixer on init Date: Thu, 23 Jun 2022 18:42:32 +0200 Message-Id: <20220623164345.463768112@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 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;