Message ID | 20221105014613.113503-1-Jason@zx2c4.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp753852wru; Fri, 4 Nov 2022 19:01:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4N051MrWqcYDdLTtGydAlLkFxf+0OSbhc1ES/YFsJtbnG87+FIzov8WysHv9heIWJrtcOX X-Received: by 2002:a17:902:7d87:b0:17f:9cd0:2e03 with SMTP id a7-20020a1709027d8700b0017f9cd02e03mr38287955plm.164.1667613713271; Fri, 04 Nov 2022 19:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667613713; cv=none; d=google.com; s=arc-20160816; b=ZauiGvNEgWcq0jq3HpzKyzuCU9SlXs3Z3rFEcqM673KUC+RKDi2avHNeuoODLuE84f LYo1kgkI72OpG7pW3GE/9wLt5c34MpidyVY75Jx6Vni7invHyhGSTm6R9mlsSx6Y6OOc yKkQrp69vM9V//4vJouTsYmRzpG/E5YGv60Pim05LHPioe4eno3shBCyEKL5X4ebRZPV FC+ObFgoqUOo6yaBbgSKyK2a/TKf9YWq3orUeuKAz5I97NupDSWnkhJy3884UI0mbheZ JPwqFPVWgpsSOjA1fN6CL6F3ab4Zrh8bsMYLQmes7CJ2pCGAMgjXZc4MdXYUDMJiCQC9 aQ3Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=DVfzsmyWwLOBIsDi6l8Xg2Te/JyeRyrFJMucpVazSvA=; b=jvVtmZfEvtwosBvVmq/fQBrLP2wN9OkjZiQ2ChlYCWfbiOJ5OISoWkke23GEN6EXQM ZZLsDW5F4HJjjIUPyc0mc/WFZylpyPhX6PxpbhV8kvKz4tUUQAyRgC/4bExCVXZ8odQ+ pNslchkpdjzFB+Uz/8ST9Vc7i0bQ74M4XGtIHGgD6uNQX3uDSOAz1D34Wz3NgRZezyrj E1XJnSViFxHMTclVxPv9iVjnwFIHU4YUlsbGRm6f1Ic+432KexinohqZNEiDE/En/JmT EExXurewfvPMo889vXk+3kQ7JDDnHXeiy9EAENJePnf8X3S/6vJI8aZtRe7nl6Q44IW5 FJkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b="C9b81/Ek"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x16-20020aa78f10000000b0056e109212d8si884497pfr.287.2022.11.04.19.01.35; Fri, 04 Nov 2022 19:01:53 -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=@zx2c4.com header.s=20210105 header.b="C9b81/Ek"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbiKEBqi (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Fri, 4 Nov 2022 21:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiKEBqg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 4 Nov 2022 21:46:36 -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 3A03912A95; Fri, 4 Nov 2022 18:46:35 -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 E430FB8303B; Sat, 5 Nov 2022 01:46:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04DD4C433D6; Sat, 5 Nov 2022 01:46:31 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="C9b81/Ek" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1667612789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DVfzsmyWwLOBIsDi6l8Xg2Te/JyeRyrFJMucpVazSvA=; b=C9b81/Ek2nHkNGMf8MG0JmpYsZBqcaY8gvrJ5CH+9WpKwgqSOagajTQt3ZjNtfdH0EsrC/ SXByqG+69D3b/8KoH1QbomR2j1hRrZoAseDOlDeS1ZRLcFDzxACnJrZYjb4CkJWeizYvq/ /Fkg3bp5LJOlpuEWJqXiERX1ln52Ca0= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 05143520 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 5 Nov 2022 01:46:28 +0000 (UTC) From: "Jason A. Donenfeld" <Jason@zx2c4.com> To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, robh@kernel.org Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>, Frank Rowand <frowand.list@gmail.com> Subject: [PATCH] of: fdt: parse early params before adding bootloader randomness Date: Sat, 5 Nov 2022 02:46:13 +0100 Message-Id: <20221105014613.113503-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748619717046120451?= X-GMAIL-MSGID: =?utf-8?q?1748619717046120451?= |
Series |
of: fdt: parse early params before adding bootloader randomness
|
|
Commit Message
Jason A. Donenfeld
Nov. 5, 2022, 1:46 a.m. UTC
FDT is examined so early that it's before the first incidental call to
parse_early_param(). This is similar to EFI, except EFI actually added
an explicitly call to parse_early_param(). Let's do the same here, so
that specifying `random.trust_bootloader=0` is not ignored.
Fixes: d97c68d178fb ("random: treat bootloader trust toggle the same way as cpu trust toggle")
Cc: Rob Herring <robh@kernel.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
drivers/of/fdt.c | 3 +++
1 file changed, 3 insertions(+)
Comments
On Fri, Nov 4, 2022 at 8:46 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > > FDT is examined so early that it's before the first incidental call to > parse_early_param(). This is similar to EFI, except EFI actually added > an explicitly call to parse_early_param(). Let's do the same here, so > that specifying `random.trust_bootloader=0` is not ignored. > > Fixes: d97c68d178fb ("random: treat bootloader trust toggle the same way as cpu trust toggle") > Cc: Rob Herring <robh@kernel.org> > Cc: Frank Rowand <frowand.list@gmail.com> > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> > --- > drivers/of/fdt.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index 7b571a631639..6d959117fd4f 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -1195,6 +1195,9 @@ int __init early_init_dt_scan_chosen(char *cmdline) > > rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); > if (rng_seed && l > 0) { > + /* Parse random.trust_bootloader if it's in command line. */ > + parse_early_param(); I don't think it's good that the timing of calling this is dependent on "rng-seed" being present or not. So perhaps move it up to after the cmdline is set. Either way, the other issue is the cmdline is not necessarily fixed at this point with some architectures doing their own append/prepend/override of the cmdline. We can't seem to get common implementation there finished. I'm doubtful that corner case would actually be hit though. Rob
On Mon, Nov 07, 2022 at 11:28:20AM -0600, Rob Herring wrote: > On Fri, Nov 4, 2022 at 8:46 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > > > > FDT is examined so early that it's before the first incidental call to > > parse_early_param(). This is similar to EFI, except EFI actually added > > an explicitly call to parse_early_param(). Let's do the same here, so > > that specifying `random.trust_bootloader=0` is not ignored. > > > > Fixes: d97c68d178fb ("random: treat bootloader trust toggle the same way as cpu trust toggle") > > Cc: Rob Herring <robh@kernel.org> > > Cc: Frank Rowand <frowand.list@gmail.com> > > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> > > --- > > drivers/of/fdt.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > > index 7b571a631639..6d959117fd4f 100644 > > --- a/drivers/of/fdt.c > > +++ b/drivers/of/fdt.c > > @@ -1195,6 +1195,9 @@ int __init early_init_dt_scan_chosen(char *cmdline) > > > > rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); > > if (rng_seed && l > 0) { > > + /* Parse random.trust_bootloader if it's in command line. */ > > + parse_early_param(); > > I don't think it's good that the timing of calling this is dependent > on "rng-seed" being present or not. So perhaps move it up to after the > cmdline is set. > > Either way, the other issue is the cmdline is not necessarily fixed at > this point with some architectures doing their own > append/prepend/override of the cmdline. We can't seem to get common > implementation there finished. I'm doubtful that corner case would > actually be hit though. Hm, yea. I'm actually now having second thoughts about this one too for other reasons: FDT isn't the only arch that has this issue. It's also a problem on x86 and m68k. Maybe the random.trust_bootloader toggle should just go away, since already your bootloader can do whatever it wants to the kernel it executes? Not sure; I'll think on it a bit I guess... Jason
On 07/11/2022 18.34, Jason A. Donenfeld wrote: > On Mon, Nov 07, 2022 at 11:28:20AM -0600, Rob Herring wrote: >> On Fri, Nov 4, 2022 at 8:46 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: >>> >>> FDT is examined so early that it's before the first incidental call to >>> parse_early_param(). This is similar to EFI, except EFI actually added >>> an explicitly call to parse_early_param(). Let's do the same here, so >>> that specifying `random.trust_bootloader=0` is not ignored. >>> >>> Fixes: d97c68d178fb ("random: treat bootloader trust toggle the same way as cpu trust toggle") >>> Cc: Rob Herring <robh@kernel.org> >>> Cc: Frank Rowand <frowand.list@gmail.com> >>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> >>> --- >>> drivers/of/fdt.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c >>> index 7b571a631639..6d959117fd4f 100644 >>> --- a/drivers/of/fdt.c >>> +++ b/drivers/of/fdt.c >>> @@ -1195,6 +1195,9 @@ int __init early_init_dt_scan_chosen(char *cmdline) >>> >>> rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); >>> if (rng_seed && l > 0) { >>> + /* Parse random.trust_bootloader if it's in command line. */ >>> + parse_early_param(); >> >> I don't think it's good that the timing of calling this is dependent >> on "rng-seed" being present or not. So perhaps move it up to after the >> cmdline is set. >> >> Either way, the other issue is the cmdline is not necessarily fixed at >> this point with some architectures doing their own >> append/prepend/override of the cmdline. We can't seem to get common >> implementation there finished. I'm doubtful that corner case would >> actually be hit though. > > Hm, yea. I'm actually now having second thoughts about this one too for > other reasons: FDT isn't the only arch that has this issue. It's also a > problem on x86 and m68k. Maybe the random.trust_bootloader toggle should > just go away, since already your bootloader can do whatever it wants to > the kernel it executes? Not sure; I'll think on it a bit I guess... Well, for the FDT case it least one could preserve the ability for the bootloader to say "hey, here's a bunch of bytes, but I have reason to believe they're not as random as you'd like" by setting a boolean "rng-seed-is-crap" [pick a better name] property alongside the rng-seed property. Then the kernel logic could be CONFIG_TRUST_BOOT_LOADER && !of_get_bool("rng-seed-is-crap"). Currently, the only thing the bootloader could do in that case is to just elide the rng-seed completely (or set the not-actually-working cmdline flag). I don't think it's a loss to not have a way for the bootloader to turn on a trust-me flag. Rasmus
On Fri, Nov 18, 2022 at 09:33:53AM +0100, Rasmus Villemoes wrote: > On 07/11/2022 18.34, Jason A. Donenfeld wrote: > > On Mon, Nov 07, 2022 at 11:28:20AM -0600, Rob Herring wrote: > >> On Fri, Nov 4, 2022 at 8:46 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > >>> > >>> FDT is examined so early that it's before the first incidental call to > >>> parse_early_param(). This is similar to EFI, except EFI actually added > >>> an explicitly call to parse_early_param(). Let's do the same here, so > >>> that specifying `random.trust_bootloader=0` is not ignored. > >>> > >>> Fixes: d97c68d178fb ("random: treat bootloader trust toggle the same way as cpu trust toggle") > >>> Cc: Rob Herring <robh@kernel.org> > >>> Cc: Frank Rowand <frowand.list@gmail.com> > >>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> > >>> --- > >>> drivers/of/fdt.c | 3 +++ > >>> 1 file changed, 3 insertions(+) > >>> > >>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > >>> index 7b571a631639..6d959117fd4f 100644 > >>> --- a/drivers/of/fdt.c > >>> +++ b/drivers/of/fdt.c > >>> @@ -1195,6 +1195,9 @@ int __init early_init_dt_scan_chosen(char *cmdline) > >>> > >>> rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); > >>> if (rng_seed && l > 0) { > >>> + /* Parse random.trust_bootloader if it's in command line. */ > >>> + parse_early_param(); > >> > >> I don't think it's good that the timing of calling this is dependent > >> on "rng-seed" being present or not. So perhaps move it up to after the > >> cmdline is set. > >> > >> Either way, the other issue is the cmdline is not necessarily fixed at > >> this point with some architectures doing their own > >> append/prepend/override of the cmdline. We can't seem to get common > >> implementation there finished. I'm doubtful that corner case would > >> actually be hit though. > > > > Hm, yea. I'm actually now having second thoughts about this one too for > > other reasons: FDT isn't the only arch that has this issue. It's also a > > problem on x86 and m68k. Maybe the random.trust_bootloader toggle should > > just go away, since already your bootloader can do whatever it wants to > > the kernel it executes? Not sure; I'll think on it a bit I guess... > > Well, for the FDT case it least one could preserve the ability for the > bootloader to say "hey, here's a bunch of bytes, but I have reason to > believe they're not as random as you'd like" by setting a boolean > "rng-seed-is-crap" [pick a better name] property alongside the rng-seed > property. Then the kernel logic could be CONFIG_TRUST_BOOT_LOADER && > !of_get_bool("rng-seed-is-crap"). Currently, the only thing the > bootloader could do in that case is to just elide the rng-seed > completely (or set the not-actually-working cmdline flag). Yea I don't think we want to introduce that kind of complexity here. No more knobs :) Jason
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 7b571a631639..6d959117fd4f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1195,6 +1195,9 @@ int __init early_init_dt_scan_chosen(char *cmdline) rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); if (rng_seed && l > 0) { + /* Parse random.trust_bootloader if it's in command line. */ + parse_early_param(); + add_bootloader_randomness(rng_seed, l); /* try to clear seed so it won't be found. */