Commit 99ee28d9 authored by George Spelvin's avatar George Spelvin Committed by Will Deacon

arm64: kexec_file: Avoid temp buffer for RNG seed

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: default avatarGeorge Spelvin <lkml@sdf.org>
Acked-by: default avatarWill Deacon <will@kernel.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20200330173801.GA9199@SDF.ORGSigned-off-by: default avatarWill Deacon <will@kernel.org>
parent 348a625d
...@@ -138,12 +138,12 @@ static int setup_dtb(struct kimage *image, ...@@ -138,12 +138,12 @@ static int setup_dtb(struct kimage *image,
/* add rng-seed */ /* add rng-seed */
if (rng_is_initialized()) { if (rng_is_initialized()) {
u8 rng_seed[RNG_SEED_SIZE]; void *rng_seed;
get_random_bytes(rng_seed, RNG_SEED_SIZE); ret = fdt_setprop_placeholder(dtb, off, FDT_PROP_RNG_SEED,
ret = fdt_setprop(dtb, off, FDT_PROP_RNG_SEED, rng_seed, RNG_SEED_SIZE, &rng_seed);
RNG_SEED_SIZE);
if (ret) if (ret)
goto out; goto out;
get_random_bytes(rng_seed, RNG_SEED_SIZE);
} else { } else {
pr_notice("RNG is not initialised: omitting \"%s\" property\n", pr_notice("RNG is not initialised: omitting \"%s\" property\n",
FDT_PROP_RNG_SEED); FDT_PROP_RNG_SEED);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment