Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2697294ybb; Mon, 30 Mar 2020 11:07:03 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtr3vkZacL7mw+8S35HYbIGF13DzXi0zWYLRKfEewOIeOVyL8D09K82lFFewBYmhRwyhEcD X-Received: by 2002:a4a:d30c:: with SMTP id g12mr281015oos.16.1585591623010; Mon, 30 Mar 2020 11:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585591623; cv=none; d=google.com; s=arc-20160816; b=EndjaO3T8qeQOfgrN9j94wN+XcL4OLybwD85Y7ELQbCJyWgOaPgcEM1cSESKr/DqOs B0tZdl8hxxFkBsvwpQ9ZApqNwt2RMxkdSvwMagw69N9OPQA5qswabVP+3taEf657eTLy b25xnM2tCEdCzyPWvAC8mzNo15ChJvZCZ+Yr9es3015D6Lj7XDnRyEHYINFTrnKU/5+L rfMLzZva4gbCx+b4xWsa8a2Tjf0NCSVK0Nbtl0D+2ALsjFvKmzCZKxOJqom9WDQMpr49 zBMkHFWSQrzaMaq1WV0YTknFOjx2w7Sx08TO6Zrtt4Z2ndVcVpRtkoiWppdeiUJeZXjZ WNfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=fdtaeUXt8mnL3dyxiaWPeixvWhRHNpC46XexuZGn5cU=; b=fJMJDGzrnwloQ0mKaRpexEeKrGPQOhxkxrtTGsautO1XcX9cd8Wp3g/L4pL6qf3odk JzYgtkkLa3UoXObaippvNNaD0spIZzB7hsJKiYZEhD4skj0J2ng56iRuh4UkkF/Tkzh0 cQFlwp0OdqmmE08jr/fj5Tox8tgA2TUd5PS7B+j2hzL4ClMAgJB/v9LU63RsiaWn7/p5 UeC8g47IePUDyTLxFRveQjBB5xyRF6Phdgi4ziHcWAr97y0rH+CFcrwL9McPW0rDVjhR SUkjyK2pHDDpt95UYFup6Smrj1/mVmjY60BhCTCzAVr4W1u5vb38ROS2Uh1aNvlCmtjc oxlQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f129si5927161oia.243.2020.03.30.11.06.50; Mon, 30 Mar 2020 11:07:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729390AbgC3RiW (ORCPT + 99 others); Mon, 30 Mar 2020 13:38:22 -0400 Received: from mx.sdf.org ([205.166.94.20]:52290 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbgC3RiW (ORCPT ); Mon, 30 Mar 2020 13:38:22 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02UHc2SK002031 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Mon, 30 Mar 2020 17:38:02 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02UHc1dq024983; Mon, 30 Mar 2020 17:38:01 GMT Date: Mon, 30 Mar 2020 17:38:01 +0000 From: George Spelvin To: Will Deacon Cc: linux-kernel@vger.kernel.org, Hsin-Yi Wang , Catalin Marinas , linux-arm-kernel@lists.infradead.org, lkml@sdf.org Subject: [PATCH v2] arm64: kexec_file: Avoid temp buffer for RNG seed Message-ID: <20200330173801.GA9199@SDF.ORG> References: <202003281643.02SGhMtr029198@sdf.org> <20200330133701.GA10633@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200330133701.GA10633@willie-the-truck> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 directly in there without using a temporary buffer at all. Faster and less stack all in one. Signed-off-by: George Spelvin Acked-by: Will Deacon Cc: Hsin-Yi Wang Cc: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org --- v2: Typos in commit message fixed. Thank you, I'd be delighted if you'd apply it to the arm64 tree directly! I can take it out of my patch series and off my plate. Now that I'm looking at it some more, I want to change fdt_setprop_placeholder to return an ERR_PTR. Must. Stop. Scope. Creep. 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