This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 6b9872c14e7 drivers: Let every user read /dev/random and /dev/urandom.
6b9872c14e7 is described below
commit 6b9872c14e7451b39ccd89569b1bd36efc88a68e
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Oct 30 17:49:18 2026 +0100
drivers: Let every user read /dev/random and /dev/urandom.
8d2b71d127f and 081e4c478af removed the world write permission of
many drivers. They also removed the read permission of the random
devices: virtio-rng registers /dev/random and /dev/urandom with mode
0400, and dev_urandom.c registers /dev/urandom with mode 0600. With
CONFIG_FS_PERMISSION, a process that is not root then cannot get
random data: open() fails with EACCES, so do getrandom() and
arc4random(), and arc4random_buf() uses a hash of clock() instead. A
program that changes to a user that is not root cannot make keys or
nonces that are safe.
The random devices give data that is not secret: each read gives new
data. Every other random number driver of NuttX registers them with
mode 0444. Use 0444 for virtio-rng too, which has no write().
Keep the write permission of dev_urandom.c for root only, with mode
0644. A write replaces the state of the generator with
DEV_URANDOM_XORSHIFT128 and sets the seed with
DEV_URANDOM_CONGRUENTIAL, so any user that can write controls what
other processes read. Root can still write a seed at boot.
The mode has an effect only with CONFIG_FS_PERMISSION. All build
modes and architectures get the same modes.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
drivers/crypto/dev_urandom.c | 2 +-
drivers/virtio/virtio-rng.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/dev_urandom.c b/drivers/crypto/dev_urandom.c
index dd4238db84d..f0004ff836a 100644
--- a/drivers/crypto/dev_urandom.c
+++ b/drivers/crypto/dev_urandom.c
@@ -324,7 +324,7 @@ void devurandom_register(void)
g_prng.state.z = g_prng.state.x << 25;
#endif
- register_driver("/dev/urandom", &g_urand_fops, 0600, NULL);
+ register_driver("/dev/urandom", &g_urand_fops, 0644, NULL);
}
#endif /* CONFIG_DEV_URANDOM && CONFIG_DEV_URANDOM_ARCH */
diff --git a/drivers/virtio/virtio-rng.c b/drivers/virtio/virtio-rng.c
index 77d91478d64..ea9cb1397ae 100644
--- a/drivers/virtio/virtio-rng.c
+++ b/drivers/virtio/virtio-rng.c
@@ -250,7 +250,7 @@ static int virtio_rng_probe(FAR struct virtio_device *vdev)
#endif
}
- ret = register_driver(priv->name, &g_virtio_rng_ops, 0400, priv);
+ ret = register_driver(priv->name, &g_virtio_rng_ops, 0444, priv);
if (ret < 0)
{
vrterr("Register NuttX driver failed, ret=%d\n", ret);
@@ -258,7 +258,7 @@ static int virtio_rng_probe(FAR struct virtio_device *vdev)
}
#ifdef CONFIG_DEV_URANDOM_ARCH
- ret = register_driver(priv->uname, &g_virtio_rng_ops, 0400, priv);
+ ret = register_driver(priv->uname, &g_virtio_rng_ops, 0444, priv);
if (ret < 0)
{
vrterr("Register NuttX driver failed, ret=%d\n", ret);