ubusd_id: use GRND_INSECURE to avoid blocking boot on getrandom()#24
Merged
Merged
Conversation
Commit 4ca0b14 ("ubusd_id: use getrandom(2) unconditionally on Linux") switched ID allocation from non-blocking /dev/urandom reads to getrandom(buf, len, 0). With flags == 0, getrandom() blocks until the kernel CRNG is fully seeded. ubusd's first ID allocation runs inside procd's "ubus" stage, and procd does not advance past that stage until ubusd is up. urngd, which seeds the entropy pool quickly, is only started by procd after the "ubus" stage. On boards whose CRNG seeds slowly (e.g. Rockchip RK3328: NanoPi R2S / R2S Plus / R4S, Orange Pi R1 Plus LTS) nothing seeds the pool while ubusd waits, so boot stalls for minutes until slow timer/interrupt entropy fills it. ubus IDs only need to be hard to guess, not cryptographically strong, and were sourced from non-blocking /dev/urandom for years. Use GRND_INSECURE, which returns bytes immediately without waiting for the CRNG, restoring the previous early-boot behaviour while keeping the benefits of getrandom() (no file descriptor, works before /dev/urandom exists). Define GRND_INSECURE for libc headers predating Linux 5.6. Fixes: openwrt#21 Assisted-by: Claude:claude-opus-4-8 Link: openwrt#24 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
257d0e9 to
24864e7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commit 4ca0b14 ("ubusd_id: use getrandom(2) unconditionally on Linux") switched ID allocation from non-blocking /dev/urandom reads to getrandom(buf, len, 0). With flags == 0, getrandom() blocks until the kernel CRNG is fully seeded.
ubusd's first ID allocation runs inside procd's "ubus" stage, and procd does not advance past that stage until ubusd is up. urngd, which seeds the entropy pool quickly, is only started by procd after the "ubus" stage. On boards whose CRNG seeds slowly (e.g. Rockchip RK3328: NanoPi R2S / R2S Plus / R4S, Orange Pi R1 Plus LTS) nothing seeds the pool while ubusd waits, so boot stalls for minutes until slow timer/interrupt entropy fills it.
ubus IDs only need to be hard to guess, not cryptographically strong, and were sourced from non-blocking /dev/urandom for years. Use GRND_INSECURE, which returns bytes immediately without waiting for the CRNG, restoring the previous early-boot behaviour while keeping the benefits of getrandom() (no file descriptor, works before /dev/urandom exists). Define GRND_INSECURE for libc headers predating Linux 5.6.
Fixes: #21
Assisted-by: Claude:claude-opus-4-8