Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6030191iog; Thu, 23 Jun 2022 09:54:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ssdXsvG4IWDG2RDI4Zovxaz24LiEs7ndbHN6Pb3AhcC3x6toBDqzDhQWHmmr1k5QDSbzp9 X-Received: by 2002:a50:fb9a:0:b0:435:6c0e:3342 with SMTP id e26-20020a50fb9a000000b004356c0e3342mr11829547edq.337.1656003283150; Thu, 23 Jun 2022 09:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656003283; cv=none; d=google.com; s=arc-20160816; b=bA2xP7dfiJaeGNCo0x5OA/cddtOut5P8m9H2no9CYoUk5thBsGNcjkeayDtJ48K1Pa 975FMgHp3FX91NhqAJIeufoY8O2AncPvt3GIU6rjuu9aenkbybDATEOydbfCitJlRDLZ P60OpbpqSezg0CDYivxdokDx1NQ6aZlLF2CokFfxqdDq9lQqIkxKxlT+td8ycftnJ2wh m4Lw6ZyazodBHGUnLDhxwK0ivTTNv4Np6vKkNjBJWfw5pvBC+THF4zofGpMhasVZLOdm 3bMqtuHvZnntkqn/5qx5kFKnELU5Ga/8fMa51RUUGFRwwqhfk+HxD4Co3+/4i0d32La0 IDdA== 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=xOsUEvVLZrml/YoC9NojDxb5g31nYcD2X2PMKHd60yc=; b=FBoa9hI8Ctg8ckUtzWQdFi+O0n8NGBuw0Y83UgkWFIn9nxtxTJCF+CZGMsfn3xuszD FfqSmp8W50W2wpFTk5c9NJNtOZSW04TGyE/Sl0wjeNLWGSKshagGCUMBa7/k/b6x3SfF wHyI6VYnsLQHGZmTD9GkzK1+1HMYMul9f90p9EMxeDrVwOHYDvVUMfSbzVX1fmVVDyAd xcOoSOnbbkC9Cp8hc4FTjgWKEPOTL0va21CRVyhy8OeTW7jmpu/1PeV1iCZHUaJFvVK2 8z4hAfK0+mD5oUdTD/abN+w4iTmD5RBY2uz1la8eyasw4hR744bmjqZQHLyKICaPKMuD BZ6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=caNQrGhp; 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 i8-20020a1709064fc800b0070dfd895c81si28128328ejw.647.2022.06.23.09.54.17; Thu, 23 Jun 2022 09:54:43 -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=caNQrGhp; 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 S232614AbiFWQru (ORCPT + 99 others); Thu, 23 Jun 2022 12:47:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232629AbiFWQq5 (ORCPT ); Thu, 23 Jun 2022 12:46:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6794049F92; Thu, 23 Jun 2022 09:46:55 -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 A38C0B82486; Thu, 23 Jun 2022 16:46:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01E4AC3411B; Thu, 23 Jun 2022 16:46:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656002810; bh=lvn/PPf44nfUMChZGL8ksDAmVaLVyZF9u/g6Comv+j8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=caNQrGhpK7NZwjkjeXnudJN4pDTiHYi0BVgbuD++WdYqGEdCIFrxWailXHJg2b6oi woTjN/uhwccAIDl9P2i2gFM0Vr+mH0HT+gqyh+gE5+fH1+CqzSCVYIOaUekDS4NDxi gJNke2T19C1yJg6wbv6VMDo0ZJuncfbgGx/oA600= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , "Jason A. Donenfeld" Subject: [PATCH 4.9 032/264] random: add a config option to trust the CPUs hwrng Date: Thu, 23 Jun 2022 18:40:25 +0200 Message-Id: <20220623164344.977732101@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: Theodore Ts'o commit 39a8883a2b989d1d21bd8dd99f5557f0c5e89694 upstream. This gives the user building their own kernel (or a Linux distribution) the option of deciding whether or not to trust the CPU's hardware random number generator (e.g., RDRAND for x86 CPU's) as being correctly implemented and not having a back door introduced (perhaps courtesy of a Nation State's law enforcement or intelligence agencies). This will prevent getrandom(2) from blocking, if there is a willingness to trust the CPU manufacturer. Signed-off-by: Theodore Ts'o Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/Kconfig | 14 ++++++++++++++ drivers/char/random.c | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -595,3 +595,17 @@ source "drivers/char/xillybus/Kconfig" endmenu +config RANDOM_TRUST_CPU + bool "Trust the CPU manufacturer to initialize Linux's CRNG" + depends on X86 || S390 || PPC + default n + help + Assume that CPU manufacturer (e.g., Intel or AMD for RDSEED or + RDRAND, IBM for the S390 and Power PC architectures) is trustworthy + for the purposes of initializing Linux's CRNG. Since this is not + something that can be independently audited, this amounts to trusting + that CPU manufacturer (perhaps with the insistence or mandate + of a Nation State's intelligence or law enforcement agencies) + has not installed a hidden back door to compromise the CPU's + random number generation facilities. + --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -783,6 +783,7 @@ static void invalidate_batched_entropy(v static void crng_initialize(struct crng_state *crng) { int i; + int arch_init = 1; unsigned long rv; memcpy(&crng->state[0], "expand 32-byte k", 16); @@ -793,10 +794,18 @@ static void crng_initialize(struct crng_ _get_random_bytes(&crng->state[4], sizeof(__u32) * 12); for (i = 4; i < 16; i++) { if (!arch_get_random_seed_long(&rv) && - !arch_get_random_long(&rv)) + !arch_get_random_long(&rv)) { rv = random_get_entropy(); + arch_init = 0; + } crng->state[i] ^= rv; } +#ifdef CONFIG_RANDOM_TRUST_CPU + if (arch_init) { + crng_init = 2; + pr_notice("random: crng done (trusting CPU's manufacturer)\n"); + } +#endif crng->init_time = jiffies - CRNG_RESEED_INTERVAL - 1; }