Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4461348yba; Sun, 19 May 2019 20:16:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyCj7FHbDGCu/D7z6GClu4gWqf+NzQngUtNTeJJfd5L4YeJIBIpDfg97e8rulszISoRRrSg X-Received: by 2002:a62:6444:: with SMTP id y65mr78217781pfb.148.1558322165779; Sun, 19 May 2019 20:16:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558322165; cv=none; d=google.com; s=arc-20160816; b=kicvxs+Byb/3E7dUauwrCi7J2VO1Kc/nKxoleVnDzS+PhLFgSYEvvhet8bJe99d901 zV69wozPr0z7pPNcZyoPMOEFPQPQgUadJ38kUkxMynrRdbL3vDkGpn/1kQU4l4MOE9ve FMFsho5sVj14rXS9Cem3EyetjjGnHExQYJkU3ZEJvKc1fp4QETrJjET/Rd0EZYCyJlAx QkUVAIDatuynQNeNR42V1unVQQhzlsXyCM64RjCNWJivgtkss5t/Uj7GAu9VWEUDFdM4 Hr4EcSzcbNvgwljitGav7095hly+COQ3QTXkZsFXoWhYk4aKZ4hi1lg6Z85CdmBJF6Xh yI5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0al1JPf1p4k1Xk2X9+xnd+opR9sCtlA9+Q7CGf2wkdc=; b=WJshP1QJgS/6OQGamL1NigUwuSQRknP0PNhRQqAwvYo+hWYFQ7pgdN/aR/CT7IWpz6 0vdpFp+1lTVMGsOfVhOn3EImk//t+QB/JLWFwOZF8rMpT5Qvay1BtscUsoOvne95rCJs iqiBCLMq/999ZTQ/0+GM6D/veHbj/irfWyZuwSvUxDbC4BXnezgoF/2Rzl6FiFLwjts1 0u503VSRIh+aaPrYQQDd2RCLKT2tse/ZLJ71FuqMsLbSE4+Us5zvmwdJyHxcCAVeX3w+ 47Uzn8Vn7sgU97cDpCPmsdID6YBv3aYbrVWeVQ7Eisa+Bu/5IUQ2myGHMWpdIa8LTh6H FNUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T6NKMFeM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u143si18676084pfc.203.2019.05.19.20.15.51; Sun, 19 May 2019 20:16:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T6NKMFeM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728719AbfESXzA (ORCPT + 99 others); Sun, 19 May 2019 19:55:00 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:33437 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726739AbfESXy7 (ORCPT ); Sun, 19 May 2019 19:54:59 -0400 Received: by mail-qt1-f196.google.com with SMTP id m32so14405521qtf.0 for ; Sun, 19 May 2019 16:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0al1JPf1p4k1Xk2X9+xnd+opR9sCtlA9+Q7CGf2wkdc=; b=T6NKMFeM174EdWJEdEKuDliPahKZ9qUMazWV6/jMf/XLDI7pD39ukI1sK8O2e85XBf RYmOIOG+XLoy0h+NvsmkaHjgqQudFNjBk9hLgPr4DUNG6sIXuHOUJzKZLbYApGEko7an wAzAzUXOS9ZogWkCbeW5ONopU7yGZXHpJl2lE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0al1JPf1p4k1Xk2X9+xnd+opR9sCtlA9+Q7CGf2wkdc=; b=qyYvISYuBEVII6O6dOfZy1k3/DkkHeMM4DPtKhz9KSGskcZj2BLgTGGOSj6ztKgP+E a3+0bQKWm4QbkrOZ6yPY9Xi4jIrEqOSGJ9OVJ25UXsA3xTciX5ymkRB/49TaJgDc+VNT Qq1/+p7NZ+Gyh+HgqbTqdbQtp1dmJek6Kx0heK1yy6Aj9Q1C8oSnetgGcArJ0+mq39Cj 9xOtTWrkJcI1M18pDUbX4H4SEK2G+L0UciIkRoI6z+wMZLVjHFFPaicsnm7r92tQlEC+ JT8pWQ4Y0OTE8coD1qUxfntRY0M3vrS2IKjikDEEZZOm8W1H4vVhlQDnt+16hd15x3h6 s/Fg== X-Gm-Message-State: APjAAAVpAAdjW30tGU5jArab6XIBcMF/4wPtrtrNXyKBA3aLzHEIL7X1 CS3SDUVyJXzqKODXO6Vh57iBcaDfcDpuA/FivoTwzQ== X-Received: by 2002:ac8:3524:: with SMTP id y33mr59412515qtb.159.1558310098407; Sun, 19 May 2019 16:54:58 -0700 (PDT) MIME-Version: 1.0 References: <20190519160446.320-1-hsinyi@chromium.org> <20190519160446.320-2-hsinyi@chromium.org> In-Reply-To: <20190519160446.320-2-hsinyi@chromium.org> From: Nicolas Boichat Date: Mon, 20 May 2019 07:54:47 +0800 Message-ID: Subject: Re: [PATCH v4 2/3] fdt: add support for rng-seed To: Hsin-Yi Wang Cc: linux-arm Mailing List , Rob Herring , devicetree@vger.kernel.org, lkml , Frank Rowand , Catalin Marinas , Will Deacon , Andrew Morton , Mike Rapoport , Ard Biesheuvel , Miles Chen , James Morse , Andrew Murray , Mark Rutland , Jun Yao , Yu Zhao , Robin Murphy , Laura Abbott , Stephen Boyd , Kees Cook Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 20, 2019 at 1:09 AM Hsin-Yi Wang wrote: > > Introducing a chosen node, rng-seed, which is an entropy that can be > passed to kernel called very early to increase initial device > randomness. Bootloader should provide this entropy and the value is > read from /chosen/rng-seed in DT. > > Signed-off-by: Hsin-Yi Wang > --- > change log v2->v4: > * v3 abandoned > * fix doc error > --- > Documentation/devicetree/bindings/chosen.txt | 14 ++++++++++++++ > drivers/of/fdt.c | 10 ++++++++++ > 2 files changed, 24 insertions(+) > > diff --git a/Documentation/devicetree/bindings/chosen.txt b/Documentation/devicetree/bindings/chosen.txt > index 45e79172a646..678e81bc4383 100644 > --- a/Documentation/devicetree/bindings/chosen.txt > +++ b/Documentation/devicetree/bindings/chosen.txt > @@ -28,6 +28,20 @@ mode) when EFI_RNG_PROTOCOL is supported, it will be overwritten by > the Linux EFI stub (which will populate the property itself, using > EFI_RNG_PROTOCOL). > > +rng-seed > +----------- > + > +This property serves as an entropy to add device randomness. It is parsed > +as a byte array, e.g. > + > +/ { > + chosen { > + rng-seed = <0x31 0x95 0x1b 0x3c 0xc9 0xfa 0xb3 ...>; > + }; > +}; > + > +This random value should be provided by bootloader. > + > stdout-path > ----------- > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index de893c9616a1..7f3d72921b23 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include Alphabetical order. > > #include /* for COMMAND_LINE_SIZE */ > #include > @@ -1079,6 +1080,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, > { > int l; > const char *p; > + const void *rng_seed; > > pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); > > @@ -1113,6 +1115,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, > > pr_debug("Command line is: %s\n", (char*)data); > > + rng_seed = of_get_flat_dt_prop(node, "rng-seed", &l); > + if (rng_seed && l > 0) { > + add_device_randomness(rng_seed, l); > + > + /* try to clear seed so it won't be found. */ > + fdt_delprop(initial_boot_params, node, "rng-seed"); I'm a little bit concerned about this, as we really want the rng-seed value to be wiped, and not kept in memory (even if it's hard to access). IIUC, fdt_delprop splices the device tree, so it'll override "rng-seed" property with whatever device tree entries follow it. However, if rng-seed is the last property (or if the entries that follow are smaller than rng-seed), the seed will stay in memory (or part of it). fdt_nop_property in v2 would erase it for sure. I don't know if there is a way to make sure that rng-seed is removed for good while still deleting the property (maybe modify fdt_splice_ to do a memset(.., 0) of the moved chunk?). > + } > + > /* break now */ > return 1; > } > -- > 2.20.1 >