Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entropy seed regresses in quality and does not actually init RNG #506

Closed
zx2c4 opened this issue Mar 24, 2022 · 0 comments
Closed

Entropy seed regresses in quality and does not actually init RNG #506

zx2c4 opened this issue Mar 24, 2022 · 0 comments

Comments

@zx2c4
Copy link
Contributor

zx2c4 commented Mar 24, 2022

This report is the analog of https://bugs.gentoo.org/835926.


There are two security problems with OpenRC's RNG initialization shell script.

  1. Writing into /dev/{u}random doesn't actually initialize the RNG. It writes into the entropy pool, but no entropy is credited. It is impossible to actually credit from a shell script.

  2. Reading a seed back immediately after writing into /dev/{u}random will regress in entropy at early boot, because /dev/{u}random doesn't actually start using the written seed until the RNG is initialized. This is bad news bears, as it means if you start with a good seed, you'll immediately get a bad, potentially deterministic, one.

There are two solutions:

a) To fix problem (2) with a shellscript, you can adopt this approach from buildroot: https://git.buildroot.net/buildroot/commit/?id=f0986de551f46e72268857fd817986e9be697cd0 which is also used in systemd: systemd/systemd@da2862e

b) To fix problem (1) and to more robustly address problem (2), you should use my seedrng.c code:
https://git.zx2c4.com/seedrng/about/
https://git.zx2c4.com/seedrng/tree/seedrng.c

Since OpenRC is a rather nimble project, I'd recommend going straight to solution (b) and skipping over the intermediate solution (a).

I'm looking now into bringing seedrng into busybox for use in buildroot. It would also make sense to bring this into openrc. seedrng.c is C that's meant to be copied and pasted into OpenRC somewhere, and I don't mind if it gets reformatted/renamed/re-whatevered. It's meant to be mangled as needed. Maybe it's a thing for libexec; maybe it's a thing for sbin. I'm okay with whatever in that regard. Just off hand, looking closer at openrc, it'd probably make sense to call this openrc-seedrng, akin to openrc-shutdown:

  executable('openrc-shutdown',
    ['openrc-shutdown.c', 'broadcast.c', 'rc-sysvinit.c', rc_misc_c,
                usage_c, rc_wtmp_c, version_h],
    c_args : cc_branding_flags,
    include_directories: [incdir, einfo_incdir, rc_incdir],
    link_with: [libeinfo, librc],
    install: true,
    install_dir: sbindir)

And then you can adjust seedrng.c's printing to use libeinfo.


CC @vapier @williamh

zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
zx2c4 added a commit to zx2c4-forks/openrc that referenced this issue Mar 25, 2022
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 OpenRC and
tweaked as needed: https://git.zx2c4.com/seedrng/about/

This commit imports it into OpenRC and wires up /etc/init.d/urandom to
call it. It shouldn't be called by other things on the system, so it
lives in rc_sbindir.

Closes OpenRC#506.

Signed-off-by: Jason A. Donenfeld <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant