Bug 199711 - can getrandom return EINTR if SA_RESTART is specified on all signal handlers but the entropy buffer is not yet initialized
Summary: can getrandom return EINTR if SA_RESTART is specified on all signal handlers ...
Status: NEW
Alias: None
Product: Documentation
Classification: Unclassified
Component: man-pages (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: documentation_man-pages@kernel-bugs.osdl.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-13 15:01 UTC by Alex Xu (Hello71)
Modified: 2018-05-14 02:56 UTC (History)
1 user (show)

See Also:
Kernel Version:
Tree: Mainline
Regression: No


Attachments
grnd-signal.c (1.88 KB, text/x-csrc)
2018-05-14 02:56 UTC, Alex Xu (Hello71)
Details

Description Alex Xu (Hello71) 2018-05-13 15:01:54 UTC
the getrandom man page says:

       The behavior when a call to getrandom() that is blocked while reading
       from the urandom source is interrupted by a signal handler depends on
       the initialization state of the entropy buffer and on the request
       size, buflen.  If the entropy is not yet initialized, then the call
       fails with the EINTR error.  If the entropy pool has been initialized
       and the request size is large (buflen > 256), the call either
       succeeds, returning a partially filled buffer, or fails with the
       error EINTR.  If the entropy pool has been initialized and the
       request size is small (buflen <= 256), then getrandom() will not fail
       with EINTR.  Instead, it will return all of the bytes that have been
       requested.

this part clearly says that in this circumstance it will return EINTR. however, it also says:

       EINTR  The call was interrupted by a signal handler; see the
              description of how interrupted read(2) calls on "slow" devices
              are handled with and without the SA_RESTART flag in the
              signal(7) man page.

and in signal(7) it says:

       If a blocked call to one of the following interfaces is interrupted
       by a signal handler, then the call is automatically restarted after
       the signal handler returns if the SA_RESTART flag was used; otherwise
       the call fails with the error EINTR:

       * getrandom(2).

this strongly implies that if all signal handlers have SA_RESTART, then getrandom will never return EINTR.

so which is it? (I guess I could test it...)
Comment 1 Alex Xu (Hello71) 2018-05-13 15:03:15 UTC
but either way, the first part should be amended to either say "unless SA_RESTART was specified for the signal handler" or it should say "even if SA_RESTART ..."
Comment 2 Alex Xu (Hello71) 2018-05-14 02:56:21 UTC
Created attachment 275963 [details]
grnd-signal.c

I tested this program and found that getrandom respects SA_RESTART if the pool is not initialized.

Note You need to log in before you can comment on or make changes to this bug.