NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/59117: arc4random has some failure modes it shouldn't



>Number:         59117
>Category:       lib
>Synopsis:       arc4random has some failure modes it shouldn't
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 02 13:55:00 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The Arc4BSD Forkation
>Environment:
>Description:
arc4random can fail (and abort, because it has no return value indicator) for the following reasons:

1. sysctl kern.arandom fails
2. crypto self-test fails
3. pthread_atfork fails
4. thr_keycreate fails

Cases (1) and (2) are reasonable: if we have no entropy, or if the software is buggy, we can't do anything.

Cases (3) and (4) are not really reasonable:

(a) We should have a variant of pthread_atfork where the caller provides storage so it can't fail.  This is also useful for libpthread's pthread_tsd_init which runs in a constructor before malloc is safe to call.
(b) If thr_keycreate fails we can always just fall back to using global state.
>How-To-Repeat:
make pthread_atfork or thr_keycreate fail and try to use arc4random
>Fix:
Yes, please!



Home | Main Index | Thread Index | Old Index