Re: [PATCH] random: allow writes to /dev/urandom to influence fast init

From: Theodore Ts'o
Date: Tue Mar 22 2022 - 23:35:51 EST


On Tue, Mar 22, 2022 at 01:14:36PM -0600, Jason A. Donenfeld wrote:
> So this patch fixes the issue by including /dev/urandom writes as part
> of the "fast init", but not crediting it as part of the fast init
> counter. This is more or less exactly what's already done for
> kernel-sourced entropy whose quality we don't know, when we use
> add_device_randomness(), which both contributes to the input pool and to
> the fast init key.

One of the big issues with /dev/urandom writes is that *anyone*,
including malicious user space, can force specific bytes to be mixed
in. That's the source of the reluctance to immediate use inputs from
writes into /dev/[u]random until there is a chance for it to be mixed
in with other entropy which is hopefully not under the control of
malicious userspace.

Now, I recognize that things are a bit special in early boot, and if
we have a malicious script running in a systemd unit script, we might
as well go home. But something to consider is whether we want to do
soemthing special if the process writing to /dev/[u]random has
CAP_SYS_ADMIN, or some such.

> There is one caveat to consider, which is what happens if the user
> additionally calls RNDADDTOENTCNT after having written to /dev/urandom,
> expecting to credit that write. That might give way to this pathological
> pattern:

Yeah, no one should ever ver ever be using RNDADDTOENTCNT. It's an
ioctl which requires root privilegs, and if it breaks, you get to keep
both pieces.

> The better interface for userspace is RNDADDENTROPY, which takes the
> input buffer and the entropy credit all at once, so we can make the
> right decision. For the RNDADDENTROPY, we do not take part in fast init
> if entropy is being credited.
>
> And perhaps we might consider attempting to deprecate RNDADDTOENTCNT at
> some point in the future.

That would be a good idea. :-)

- Ted