[PATCH] urandom-seed: use seedrng for seeding the random number generator

Etienne Champetier champetier.etienne at gmail.com
Mon Mar 28 07:18:36 PDT 2022


Hi All, Jason,

@Petr Štetiar this merge was a bit too fast to get reviews ...
Some comments inline

Le lun. 28 mars 2022 à 00:26, Jason A. Donenfeld <Jason at zx2c4.com> a écrit :
>
> The RNG can't actually be seeded from a shell script, due to the
> reliance on ioctls. For this reason, the seedrng project provides a
> basic script meant to be copy and pasted into projects like OpenWRT
> and tweaked as needed: <https://git.zx2c4.com/seedrng/about/>.
>
> This commit imports it into the urandom-seed package and wires up the
> init scripts to call it. This also is a significant improvement over the
> current init script, which does not robustly handle cleaning up of seeds
> and syncing to prevent reuse.

When urandom-seed was introduced in 2016 it was decided during review
that writing on each boot might cause too much wear to the flash.
Maybe we can say that 6 years later this is not a problem anymore, but
would love to have more devs comment
Old thread: https://www.mail-archive.com/lede-dev@lists.infradead.org/msg01225.html

Now if I understand correctly, with this patch we are writing a seed
to flash twice per boot, in preinit/81_urandom_seed and in
init.d/urandom_seed.
Also there are good chances we will never have a seed.credit at all on
many devices,
would be great if seedrng had an option "writeseed" that blocks on getrandom().

> Additionally, the existing script creates
> a new seed immediately after writing an old one, which means that the
> amount of entropy might actually regress, due to failing to credit the
> old seed.

We used getrandom to create the seeds, so when configured to write new
seed on each boot,
either we reboot too fast and we will reuse the seed (not ideal but
not catastrophic as we don't credit),
or the new seed is created after getrandom() unblock, so not sure to
understand how entropy regress.

> Closes: https://github.com/openwrt/openwrt/issues/9570
> Signed-off-by: Jason A. Donenfeld <Jason at zx2c4.com>

[snip]

> diff --git a/package/system/urandom-seed/seedrng.c b/package/system/urandom-seed/seedrng.c
> new file mode 100644
> index 0000000000..9a2cb10f55
> --- /dev/null
> +++ b/package/system/urandom-seed/seedrng.c

[snip]

> +
> +#define SEED_DIR "/etc/seedrng"

If we worry about seed reuse, we should not use /etc as it can be
restored from a backup

Best
Etienne



More information about the openwrt-devel mailing list