Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6132202iog; Thu, 23 Jun 2022 12:02:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v6xj3lAfjWiuz1gjS0arrH5cOzXW9mB5M4UkitVR2hH2YcOSsOVCTWuqbo0RUYKRJH89hb X-Received: by 2002:a63:4d65:0:b0:408:9e5c:f7b7 with SMTP id n37-20020a634d65000000b004089e5cf7b7mr8645394pgl.553.1656010927945; Thu, 23 Jun 2022 12:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656010927; cv=none; d=google.com; s=arc-20160816; b=TFm6Yurb9BM88tsiT2LnxklsAxN3pc1wxksbeWSlHKoan8T2Ght0/u2XGCLBTO362R R0aiVN6fu2Q2Y+QAdvJRfRvd6lUiVA9TIZ0FfjtpTYg1O6MxkXyBBIdenWcnQj0NnLgb yveO4kPYM7EIyR0J2tgxeAhU5ASGXFbkiENEheJJNDSYNu0FtWVOVrCy6/VUKs1jzAuO o0t1XRA8hy29UsfMv9VoabTZ8loRWjiWT2ymIQ9zeu1uV7RpZSfOLsxYfSDCZmSnSNSN r7eJh5PAlO3i3vcL1P625zIzLhwvjW7aLhcBTX3p80+xP2uX03WcOyjbZukM/+6Hy++A wAkg== 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=p0b6CnsE8WzR6C5xyg1TQqYQKjiQhTiEsKdnbFoo+e8=; b=naRHp+Qdtttk6Kxy9JlU0lsL/wy7DvLyecws9X2v1gw94OdaRwiVtK1oz9FKUXV0DC CCMiiWgRI1Kt5c1akOC5OdN04oabj42chN1HZiIPwOuOT/AQ1OlZKMz1kSGNDCluTKEt ehKHpYqbex3D/Oa/sv4ZAsVMORnm0ElxsYvOIYSbvKGOwRoDEQw4IR10chQJwq8ZcceA 9TX67HwcDp/QSeC5lglaGYfHd0fXnwCQ9TXkTunz6L6fNyjn2q4DO29Bi4VjMloNE2Am cpyNTGI3gs7hxQX/WBYdn0nirLCefB5kJga1R5mggsnA0OfLWaaF9KgiGQqn55MQLuIp otFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N1OlPeKO; 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 j11-20020a17090a2a8b00b001e312672c02si262281pjd.30.2022.06.23.12.01.55; Thu, 23 Jun 2022 12:02: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=N1OlPeKO; 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 S236227AbiFWSJY (ORCPT + 99 others); Thu, 23 Jun 2022 14:09:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236456AbiFWSHv (ORCPT ); Thu, 23 Jun 2022 14:07:51 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8D6D7A1A0; Thu, 23 Jun 2022 10:19:23 -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 F1C0FB82490; Thu, 23 Jun 2022 17:19:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39033C3411B; Thu, 23 Jun 2022 17:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004760; bh=xx+KKT3SJF3BLuWqc0e56SpWJ4CoXX325SYZ1RIsBns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N1OlPeKOjCJV7EDxcYxysAnREeTVVdP7t3Q33VptX7+KzimgkLnCgdluU9mvrX6+J JWx0n1NEAXmkUEzArmUIIWpFBnajaqV8WU+z5wy4NTmd7wFjEZWohCE4g8iUMQHSNI F0rv+Ys+L8Ol4j50GP/UwAiHqtDZx+RS2a1J/FpQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , Graham Christensen , Ard Biesheuvel , Dominik Brodowski , "Jason A. Donenfeld" Subject: [PATCH 4.19 124/234] random: treat bootloader trust toggle the same way as cpu trust toggle Date: Thu, 23 Jun 2022 18:43:11 +0200 Message-Id: <20220623164346.565775931@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 d97c68d178fbf8aaaf21b69b446f2dfb13909316 upstream. If CONFIG_RANDOM_TRUST_CPU is set, the RNG initializes using RDRAND. But, the user can disable (or enable) this behavior by setting `random.trust_cpu=0/1` on the kernel command line. This allows system builders to do reasonable things while avoiding howls from tinfoil hatters. (Or vice versa.) CONFIG_RANDOM_TRUST_BOOTLOADER is basically the same thing, but regards the seed passed via EFI or device tree, which might come from RDRAND or a TPM or somewhere else. In order to allow distros to more easily enable this while avoiding those same howls (or vice versa), this commit adds the corresponding `random.trust_bootloader=0/1` toggle. Cc: Theodore Ts'o Cc: Graham Christensen Reviewed-by: Ard Biesheuvel Reviewed-by: Dominik Brodowski Link: https://github.com/NixOS/nixpkgs/pull/165355 Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- Documentation/admin-guide/kernel-parameters.txt | 6 ++++++ drivers/char/Kconfig | 3 ++- drivers/char/random.c | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3697,6 +3697,12 @@ fully seed the kernel's CRNG. Default is controlled by CONFIG_RANDOM_TRUST_CPU. + random.trust_bootloader={on,off} + [KNL] Enable or disable trusting the use of a + seed passed by the bootloader (if available) to + fully seed the kernel's CRNG. Default is controlled + by CONFIG_RANDOM_TRUST_BOOTLOADER. + ras=option[,option,...] [KNL] RAS-specific options cec_disable [X86] --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -576,4 +576,5 @@ config RANDOM_TRUST_BOOTLOADER device randomness. Say Y here to assume the entropy provided by the booloader is trustworthy so it will be added to the kernel's entropy pool. Otherwise, say N here so it will be regarded as device input that - only mixes the entropy pool. \ No newline at end of file + only mixes the entropy pool. This can also be configured at boot with + "random.trust_bootloader=on/off". --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -940,11 +940,17 @@ static bool drain_entropy(void *buf, siz **********************************************************************/ static bool trust_cpu __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_CPU); +static bool trust_bootloader __ro_after_init = IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER); static int __init parse_trust_cpu(char *arg) { return kstrtobool(arg, &trust_cpu); } +static int __init parse_trust_bootloader(char *arg) +{ + return kstrtobool(arg, &trust_bootloader); +} early_param("random.trust_cpu", parse_trust_cpu); +early_param("random.trust_bootloader", parse_trust_bootloader); /* * The first collection of entropy occurs at system boot while interrupts @@ -1152,7 +1158,7 @@ EXPORT_SYMBOL_GPL(add_hwgenerator_random */ void add_bootloader_randomness(const void *buf, size_t size) { - if (IS_ENABLED(CONFIG_RANDOM_TRUST_BOOTLOADER)) + if (trust_bootloader) add_hwgenerator_randomness(buf, size, size * 8); else add_device_randomness(buf, size);