casaroli opened a new pull request, #20984: URL: https://github.com/apache/nuttx/pull/20984
## Summary The virtio rng driver registered `/dev/urandom` whenever `CONFIG_DEV_URANDOM` was set. With another `/dev/urandom` algorithm (xorshift128, congruential or the entropy pool), `drivers/crypto/dev_urandom.c` registers `/dev/urandom` first. The probe then failed with `EEXIST` and freed its private data, but `/dev/random`, registered just before, still pointed to it. The first read of `/dev/random` used the freed data. This PR registers `/dev/urandom` (and provides the weak `devurandom_register()`) only with `CONFIG_DEV_URANDOM_ARCH`, the option that says that the architecture provides `/dev/urandom`. The arch RNG drivers use the same condition. Otherwise the driver registers only `/dev/random`. When the second registration fails, the probe unregisters `/dev/random` before it frees the private data, and `virtio_rng_remove()` unregisters both names. ## Impact `CONFIG_DRIVERS_VIRTIO_RNG` selects `ARCH_HAVE_RNG`, so `CONFIG_DEV_URANDOM_ARCH` is the default: these configurations do not change (`/dev/random` and `/dev/urandom` both come from virtio-rng). With another `/dev/urandom` algorithm, `/dev/random` now comes from virtio-rng and `/dev/urandom` from the chosen algorithm, instead of a failed probe and a crash. Flat, protected and kernel builds use the same code. ## Testing qemu-armv8a:knsh under QEMU with HVF and `-device virtio-rng-device`, with `CONFIG_DRIVERS_VIRTIO_RNG`, `CONFIG_DEV_RANDOM`, `CONFIG_DEV_URANDOM`, `CONFIG_DEV_URANDOM_XORSHIFT128` and the virtio error log. Test program `rngdev.c`: it opens `/dev/random` and `/dev/urandom` and reads two different blocks of 16 bytes from each. | | master | this PR | |---|---|---| | boot log | `virtio_rng_probe: Register NuttX driver failed, ret=-17` | no error | | `rngdev` | kernel panic (assertion in `arm64_fatal.c`) at the read of `/dev/random` | PASS | With the default `CONFIG_DEV_URANDOM_ARCH`, `rngdev` passes with this PR (both devices from virtio-rng, no error in the boot log). ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh with the xorshift128 options. Build, each OK: qemu-armv8a:knsh and qemu-armv8a:nsh with the options above (kernel and flat, arm64), qemu-armv8a:netnsh (flat, arm64, the default `CONFIG_DEV_URANDOM_ARCH`), rv-virt:netnsh64 (flat, rv64) and rv-virt:knetnsh64 (kernel, rv64) with `CONFIG_DEV_URANDOM_XORSHIFT128`. rv-virt:pnsh64 (protected) with virtio does not link: libmetal needs `up_addrenv_pa_to_va()` and `up_addrenv_va_to_pa()` there, also without this change. `tools/checkpatch.sh -c -u -m -g` passes. No documentation change: the documentation does not describe which driver registers `/dev/urandom`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
