Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp873057ybb; Sat, 28 Mar 2020 12:12:19 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvSuRewZ5E9Qkb9R3nFBSzsGPT0tKQgtdfQUxikSYYa8x3WHVjy51m4QOAQBs/+TB03m6SX X-Received: by 2002:a05:6808:4e:: with SMTP id v14mr3173906oic.70.1585422739855; Sat, 28 Mar 2020 12:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585422739; cv=none; d=google.com; s=arc-20160816; b=GxUkV1FiTGgmtxanJJcI46TjUEFsQbuYJA8bPL407weKSi09Jj/6jtO5rAnyYxhxDY pZfg7CF/5m1ST74T6iCckPWe24wF/y5sP0Zo6DReX0VS8JkwBat0Hn8p7GMqzgFYDjhu ClW9ziwkWbjBhyl3+ZuOGVljG3K22FFi/hl9CT989qc9Ud6OY2sX1ObtGlUb6dpvHIwK BljumA0vNr3PDlaF3WJnhkXmrujHMuq0xv20Z4r3JIjEuok0o97NQ5uWciphQ68RSGip 5uDBBvovkqwwMPYJWBoylk8jFmbdYlwaqL+U6G3MLHi0GvqIy1WjXJKhPDkFUZe/sTks j7VA== 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=AP+1qId3R/yF3OuH9WI1UJKSGs0Ex2bEojikXrSbq98=; b=Qe084H1NmRKu7+P+WOig2ypc/5fa4xGap+oIdnK+tcibIb7FFWs7WkY/iVwEC16Wzz lIFYNeW+q3wHug8I/z/4IZ8mtGyD1zqKRJnEc70mo3z2b5HYaKj7kmuoCdgKVURnmPcM EcUrUDsMrETcoP6mam5n5UNy/msu1UARKYo50wLeQQvDv7WQVil8gp9oES94M5TSVQSw 7LUlHH4c9h8wTEdiOlL+kVq6V2p76JuuLct7BxQd/9BPn3j2+EVnN+qGwoYIKh57IAdD AJKf2vEL0Tuv4HxluKhqZm4/MJRGDIvZ3ZDTZDei/X5b9asKcCld6PG9UOJhoOC7Q4Un +FJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Sk88MhJO; 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 l75si3803567oig.59.2020.03.28.12.12.06; Sat, 28 Mar 2020 12:12:19 -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=Sk88MhJO; 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 S1726981AbgC1TEw (ORCPT + 99 others); Sat, 28 Mar 2020 15:04:52 -0400 Received: from mail-il1-f195.google.com ([209.85.166.195]:41243 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726220AbgC1TEv (ORCPT ); Sat, 28 Mar 2020 15:04:51 -0400 Received: by mail-il1-f195.google.com with SMTP id t6so8358013ilj.8 for ; Sat, 28 Mar 2020 12:04:50 -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=AP+1qId3R/yF3OuH9WI1UJKSGs0Ex2bEojikXrSbq98=; b=Sk88MhJOXT+yZvT3IzSNNVPqpypHQwBvXLRR0hKLFRtdqYUq+QMn0Y8tms1RA8D2bq 9NK7sIn6jnFSLisf5wIXycz1rXYpaMOo/AUuSZz5C41VgNwMMARLDFW9AUPXeOacVQ5f VqjPPebPuB7i6P9j+xOD+coJl4yF1fp1iHCLs= 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=AP+1qId3R/yF3OuH9WI1UJKSGs0Ex2bEojikXrSbq98=; b=YseiRcNUVTp5KcwcW8ykp2Nra1/xECCgofJGypJcRCdNCJ0P/Pberpnu0ApQC2fu+s 3tHgUxUHqKvpvQHqsmYELxBKyuT8vlmPJUHLyD6QYH5gfj64eTZzL0+5tUDHC1oBFU6O 1aeMd/XKdchZdMnW+DAPg/sNX6MJH9UmUMkdXv8cTS6M1v9CNwsHBk865w/raPAM3G4x 2kH9VbAGLC5D1yqoYX0jSV+TY193hEGgoXbfUQ9k3gTs/ZWEOtZTYfuavzETgkfSdcQ5 PcENGvMqirAo7V5dwiyPRdHFtHgs4i28vC05UkHgtyMoEZZWRKjbRCT+/ENSuJ/xmxXG Kh6A== X-Gm-Message-State: ANhLgQ1vRh/+mkjBO/QCzxDUfM7bh5N5vlJKdq7j/7IFbtDMpVZT0ZaX 2iDw/pmyBkGDRtVsYIWetR8cviA4dqVDAAlGSnYbgT2Fiqg= X-Received: by 2002:a92:8517:: with SMTP id f23mr5046513ilh.106.1585422289417; Sat, 28 Mar 2020 12:04:49 -0700 (PDT) MIME-Version: 1.0 References: <202003281643.02SGhMtr029198@sdf.org> In-Reply-To: <202003281643.02SGhMtr029198@sdf.org> From: Hsin-Yi Wang Date: Sun, 29 Mar 2020 03:04:24 +0800 Message-ID: Subject: Re: [RFC PATCH v1 39/50] arm: kexec_file: Avoid temp buffer for RNG seed To: George Spelvin Cc: lkml , Catalin Marinas , Will Deacon , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" 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 Sun, Mar 29, 2020 at 12:43 AM George Spelvin wrote: > > After using get_random_bytes(), you want to wipe the buffer > afterward so the seed remains secret. > > In this case, we can eliminate the temporary buffer entirely. > fdt_setprop_placeholder returns a pointer to the property value > buffer, allowing us to put the random data directy in there without > using a temporary buffer at all. Faster and less stack all in one. > > Signed-off-by: George Spelvin > Cc: Hsin-Yi Wang > Cc: Catalin Marinas > Cc: Will Deacon > Cc: linux-arm-kernel@lists.infradead.org Acked-by: Hsin-Yi Wang > --- > arch/arm64/kernel/machine_kexec_file.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c > index 7b08bf9499b6b..69e25bb96e3fb 100644 > --- a/arch/arm64/kernel/machine_kexec_file.c > +++ b/arch/arm64/kernel/machine_kexec_file.c > @@ -106,12 +106,12 @@ static int setup_dtb(struct kimage *image, > > /* add rng-seed */ > if (rng_is_initialized()) { > - u8 rng_seed[RNG_SEED_SIZE]; > - get_random_bytes(rng_seed, RNG_SEED_SIZE); > - ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed, > - RNG_SEED_SIZE); > + void *rng_seed; > + ret = fdt_setprop_placeholder(dtb, off, FDT_PROP_RNG_SEED, > + RNG_SEED_SIZE, &rng_seed); > if (ret) > goto out; > + get_random_bytes(rng_seed, RNG_SEED_SIZE); > } else { > pr_notice("RNG is not initialised: omitting \"%s\" property\n", > FDT_PROP_RNG_SEED); > -- > 2.26.0 >