Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2322867ybb; Mon, 30 Mar 2020 04:09:44 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvNcZxH7Zy3SKbpakfWSYxhwS2ozQ9vZshvucHaqc4UVp/J2vxVhLDcnC/JeRBs4JWPY6Zf X-Received: by 2002:a05:6830:1408:: with SMTP id v8mr8373677otp.123.1585566583976; Mon, 30 Mar 2020 04:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585566583; cv=none; d=google.com; s=arc-20160816; b=gqEKDcJ/9/IwcXJuSthGw3HkiI9/d8eA9VnTnrPx+U2Uw6GRDV/3ituiPnh/hwveZ3 WcVdOxA3gHh22qQGZ/SdhXL+R0pO0zUGVHb5OE2bpSj2zzreN1cPtPXaL8bsIlTZqY66 Buv1I9wOXlzSH3TqI6COJxuFA2daPGBROGer5xtz8S98gC7byjzT0E5Yjwhm5mC1Fz7u CnpgY6NGobYDacLEslTKLB7zNdsiZgT0j3RKCnEO7gVtd/Y/EA8xalzy9hQo9jD8Qhek 8psP/zO1/+HzBtxLRJkzNypKpzg+wGYJjGVpAiTSVnH/6kfuKmEu4sBs0GEXRgCDUUAK cbIw== 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=oKcjF5Z/77yMcg9BcpHb7Uj/fx+4WV2tr9VeAJZVAvw=; b=tCKPDAqiMHdve6IM68kPkL19WRHGqHWp0vVkVgoAIoUQnIQyu4gi4r+Q4BwQsXY+by sj482ffiJ7UCf8axYstZpSNo6ay4JSovUrCH+w291SCgfgWZ/HDSFmNXo6v8RvHgGab9 I7jP+lGltS1/RDhZYpMsA7AFZSBiRsze2ubxtPtVfnBfU+H80Ay8UbkGLqz84GTGskLF 9Hh0enlsw/rWqLfCLxS3R9x1dbtVhTMB+e4WLnkmpJPMvAqJcS+77zOp5Xkm4LQXylIx ltgCMPSNL359x2lAvFJoGBdT842NzPdTBGl7eq9HTmipbyx2tF2JkSCJB2Z+lEXMULKc aHbw== 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 y3si6232095otq.204.2020.03.30.04.09.30; Mon, 30 Mar 2020 04:09:43 -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 S1729577AbgC3LH4 (ORCPT + 99 others); Mon, 30 Mar 2020 07:07:56 -0400 Received: from foss.arm.com ([217.140.110.172]:50358 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729254AbgC3LH4 (ORCPT ); Mon, 30 Mar 2020 07:07:56 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE84D31B; Mon, 30 Mar 2020 04:07:55 -0700 (PDT) Received: from C02TD0UTHF1T.local (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D7A853F52E; Mon, 30 Mar 2020 04:07:53 -0700 (PDT) Date: Mon, 30 Mar 2020 12:07:51 +0100 From: Mark Rutland To: George Spelvin Cc: linux-kernel@vger.kernel.org, Hsin-Yi Wang , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , James Morse Subject: Re: [RFC PATCH v1 39/50] arm: kexec_file: Avoid temp buffer for RNG seed Message-ID: <20200330110751.GC1309@C02TD0UTHF1T.local> References: <202003281643.02SGhMtr029198@sdf.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202003281643.02SGhMtr029198@sdf.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi George, Nit: s/arm/arm64/ in the title On Tue, Dec 10, 2019 at 10:45:27AM -0500, 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 > --- > 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); This looks sane to me, so FWIW: Acked-by: Mark Rutland Mark. > } else { > pr_notice("RNG is not initialised: omitting \"%s\" property\n", > FDT_PROP_RNG_SEED); > -- > 2.26.0 >