[PATCH] stdlib: Consolidate getentropy and adapt to POSIX 2024 semantics

Cristian Rodríguez cristian@rodriguez.im
Sat Mar 22 13:05:39 GMT 2025


On Fri, Mar 21, 2025 at 4:34 PM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
> POSIX.1-2024 added getentropy with some slight different semantics:
>
>   1. Buffer larger than 256 (GETENTROPY_MAX) should return EINVAL
>      insted of EIO.
>
>   2. There is no defined error is no entropy could be obtained.
>      It means that the function should not fail.
>
> Although both requirements would require new symbol version, the
> implementation was initially provides for compatibility with BSD,
> and both FreeBSD and OpenBSD already adapt their implementation
> to POSIX 2024.  So I think it is not worth a compatibily symbol.
>
> This patch does not add GETENTROPY_MAX on limits.h, since glibc
> still does not have a preprocessor handling for POSIX 2024.
>
> The consolidation uses __getrandom_nocancel, which might uses
> the vDSO implementation if supported.
>
> Checked on x86_64-linux-gnu.
>

(My comments here only apply to the linux version)

Are we sure all this error handling is actually necessary or correct?
 I know the manual pages are outdated and do not reflect the state of
things post Jason massive RNG rework..
But at least the previous implementation promised on reads <= 256 not
to short read, always return at least that amount of bytes, so in
theory returning 0 or EINTR is/was not possible with 0 flags.
in fact the code nowadays appears to react to signals every PAGE_SIZE read..
The BSDs where this function originates from, promise to always return
up to 256 bytes if the buffer is valid..


More information about the Libc-alpha mailing list