Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6044821iog; Thu, 23 Jun 2022 10:10:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tC/lxr/YOr2m9rnt37giW73zjs3kiDTSmyjtGhBqgZONLL+eRfVWVkq7kOP/L4mfCX7RvK X-Received: by 2002:a17:907:80ca:b0:70f:77fd:cfbd with SMTP id io10-20020a17090780ca00b0070f77fdcfbdmr9116164ejc.82.1656004217217; Thu, 23 Jun 2022 10:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656004217; cv=none; d=google.com; s=arc-20160816; b=mfyuJrTPr4Mng0cZk/jyy8w7yYUMlNbH4ES564d1NpV6OQMQwvoZUJIbAOZcBMJatS /3gI7WGb+w2zrSamJybwsgb+SH6Ho0wEbf0FCNHTLb/9PCcVYdH2nR312w29AKLR7VbX G/ZtyagxsO26CV2+druFlw3tkVtjusbtOr/5huoY9DqJ8YNa0gcPIhr4CdKe2C8FytV/ tbm5aobZoIxvL72T2H5RVChsgu9cugTDHEpP7F4/lOcw6RMKQQA3BvrHBZm8dPiFW0p/ rh0beiRNSXNrEtNoHT1mCcf9xHDHdio9ya+Fh0XxL4BqDOfmsqysWdnOzSwQqPRLl0hI 2LVg== 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=7AeohKNagI+NLSl7naclg51NRe51o/FOw48eWDvM1xg=; b=aVts9TH/e3zJCE+Ft6rP+PShmkk5wdV81gmeEeNwiOzjXdkhyshNN6G5LMR6Oj4GbE OoFZ+P7E9uprn3y2xRTuwEVix44WkMRujtPhjJMLlkh3jdokAgeUCGkYAutultoKtmqf aqUMThXRk8HFmY92+z32toCvtrxJJuQ7Aqwb8KrQS3+Af6wPF5c45cnVXJLiBP9tiWl+ dbpuaATOG+gKNynIFvGCLAdTUQKF8QlxhpjpUhhI/7v31eDClEvH5GiMB9MG0eEMrRg9 LTh/JyCsrXZeBPEzpDsScEJjCKKWoFQ6hJYA/u+MyrrJjP/vR4KHvFbaFGAzlFLnC+jl tXsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PJCp0F1P; 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 kk24-20020a170907767800b007106de7eee6si18853504ejc.478.2022.06.23.10.09.47; Thu, 23 Jun 2022 10:10:17 -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=PJCp0F1P; 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 S233353AbiFWRCj (ORCPT + 99 others); Thu, 23 Jun 2022 13:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233794AbiFWQ6c (ORCPT ); Thu, 23 Jun 2022 12:58:32 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23C4F4EF79; Thu, 23 Jun 2022 09:53:48 -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 sin.source.kernel.org (Postfix) with ESMTPS id 78F4CCE25E2; Thu, 23 Jun 2022 16:53:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07203C3411B; Thu, 23 Jun 2022 16:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656003220; bh=M4zlDLxpvDWKJBAMMHV5muwxHD/lVQ2GVlw/Mwd62jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PJCp0F1PX5fTmeufyD6QtWDKVuOKsgYQ+z+p/cJUh5wCGX9qXPaz9BGBvg2oF0OD3 JphrWCo/xpLitvjT+KE3TM716kFS0jmdSgqfO/VtQTTPdqsKkFN0QcYvogExRzxs/W a2kajUUdFGsG+TBmqIwfukJM8FJFtnsax+QWrcsM= 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.9 167/264] random: treat bootloader trust toggle the same way as cpu trust toggle Date: Thu, 23 Jun 2022 18:42:40 +0200 Message-Id: <20220623164348.789663299@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: "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/kernel-parameters.txt | 6 ++++++ drivers/char/Kconfig | 3 ++- drivers/char/random.c | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -3583,6 +3583,12 @@ bytes respectively. Such letter suffixes 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. + rcu_nocbs= [KNL] The argument is a cpu list, as described above. --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -617,4 +617,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 @@ -941,11 +941,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 @@ -1153,7 +1159,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);