Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z9sf9bs6QUwOV3c-@voyager>
Date: Wed, 19 Mar 2025 20:50:13 +0100
From: Markus Wichmann <nullplan@....net>
To: musl@...ts.openwall.com
Cc: Jorge Almeida <jjalmeida@...il.com>
Subject: Re: getrandom return value

Am Wed, Mar 19, 2025 at 07:05:40PM +0000 schrieb Jorge Almeida:
> The man page for getrandom() says a call like
> getrandom(buf, len, 0) should always return len, as long as len <= 256.
> Clear enough. But then the page says "the careful programmer will check for
> this [return value] anyway!"
> This is certainly confusing. Maybe this means that not all implementations
> should be trusted? Some other reason?
> Anyway, what is the state of affairs in musl? Can I safely discard that
> seemingly strange warning?
>
> Jorge Almeida

I think what they meant to write was that the getrandom syscall has no
contract to always return the requested bytes even for small lengths. It
should, and it'll try to, but it's not guaranteed. The guaranteed
contract is that getrandom() is like read(): If it returns positive, it
has also written as many bytes to the buffer as the return value
indicates.

Musl does nothing special in getrandom(), it just straight up wraps the
syscall, so the behavior you get is exactly what the system call is
doing.

Ciao,
Markus

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.