public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Torvald Riegel <triegel@redhat.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH v3] getrandom system call wrapper [BZ #17252]
Date: Mon, 17 Oct 2016 12:54:00 -0000	[thread overview]
Message-ID: <1476708857.14800.12.camel@localhost.localdomain> (raw)
In-Reply-To: <2997042e-a33a-afbb-79ae-2c04c015dff1@redhat.com>

On Wed, 2016-10-12 at 17:58 +0200, Florian Weimer wrote:
> On 09/12/2016 09:25 AM, Florian Weimer wrote:
> > On 09/09/2016 05:23 PM, Torvald Riegel wrote:
> >> On Fri, 2016-09-09 at 16:28 +0200, Florian Weimer wrote:
> >>> On 09/09/2016 04:21 PM, Torvald Riegel wrote:
> >>>> On Thu, 2016-09-08 at 13:44 +0200, Florian Weimer wrote:
> >>>>> I have made the system call wrapper a cancellation point.  (If we
> >>>>> implement the simpler getentropy interface, it would not be a
> >>>>> cancellation point.)
> >>>>
> >>>> Why did you do that?
> >>>
> >>> I have to, because it can block indefinitely.
> >>
> >> That doesn't mean you have to make the default function a cancellation
> >> point.  There are many POSIX functions which can block indefinitely and
> >> which are not required to be cancellation points (eg, rwlocks only *may*
> >> be cancellation points).
> >>
> >> Can the system call really block indefinitely, or only for a long time
> >> and (ie, will return eventually)?
> >
> > Yes, if the system enters a deadlock condition where the waiting for
> > randomness prevents it from accumulating additional randomness.
> 
> This is what happens here:
> 
>    <https://bugzilla.redhat.com/show_bug.cgi?id=1383060>
> 
> systemd will eventually kill the blocked process and the boot continues, 
> but all network services will be missing.

I don't see how cancellation would be the best solution for this
problem.  It could be considered *a* solution, but for it to work, the
program (or python in this case) needs to
(1) be aware of the blocking behavior, and potential absence of
getrandom initialization
(2) have a fallback plan for when getrandom() fails
(3) run more than a single thread just to run the cancellation
(4) synchronize between the thread that executes getrandom() and the
cancelling thread so that pthread_cancel can cancel only the respective
getrandom() call; for example, the getrandom thread could set/unset a
flag in a critical section, and the cancelling thread needs to check the
flag and cancel in a critical section protected by the same lock.

All solutions have to be aware of (1).

Maybe doing the fallback plan from (2) is the right solution.  This is
what they seem to have done in the BZ you cited.

Having a getrandom call that can time out would be easier for programs
to use than cancellation.  It would still require picking the right
timeout (ie, less than systemd's), but that's somethign the
cancellation-based solution would have to do too.

Cancellation would be more a more flexible means than a timeout if
systemd would announce to the program that it will get killed in 5s or
something like that, and then the program could try to hurry up and
cancel the getrandom call.  But that seems like a complex and rather
rare use case, and thus wouldn't suggest to me that a cancellable
getrandom should be the default.
Instead, using a provided getrandom_cancellable wrapper seems like the
right thing, and trivial compared to all the other complexity the
program has to deal with.

  parent reply	other threads:[~2016-10-17 12:54 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08 11:44 Florian Weimer
2016-09-08 12:46 ` Florian Weimer
2016-09-09  1:54   ` Rical Jasan
2016-09-08 13:01 ` Andreas Schwab
2016-09-08 13:02   ` Florian Weimer
2016-09-08 13:19     ` Andreas Schwab
2016-09-08 13:26       ` Florian Weimer
2016-09-08 13:37         ` Andreas Schwab
2016-09-08 13:49           ` Florian Weimer
2016-09-08 13:54             ` Andreas Schwab
2016-09-08 14:02               ` Florian Weimer
2016-09-08 15:56                 ` Andreas Schwab
2016-09-08 14:19       ` Zack Weinberg
2016-09-08 14:31         ` Florian Weimer
2016-09-08 14:39           ` Zack Weinberg
2016-09-08 14:40             ` Florian Weimer
2016-09-08 15:10               ` Zack Weinberg
2016-09-08 18:28     ` Richard Henderson
2016-09-08 18:32       ` Florian Weimer
2016-09-08 18:35         ` Richard Henderson
2016-09-12 13:48           ` Florian Weimer
2016-10-07 23:00             ` Paul Eggert
2016-10-08 10:33               ` Florian Weimer
2016-10-08 10:49                 ` Andreas Schwab
2016-10-08 12:31                   ` Florian Weimer
2016-09-09 14:21 ` Torvald Riegel
2016-09-09 14:28   ` Florian Weimer
2016-09-09 14:41     ` Zack Weinberg
2016-09-09 15:14       ` Florian Weimer
2016-09-09 15:23     ` Torvald Riegel
2016-09-12  7:26       ` Florian Weimer
2016-09-12  9:40         ` Torvald Riegel
2016-09-12 11:52           ` Florian Weimer
2016-09-23  9:44         ` Torvald Riegel
2016-09-23 11:04           ` Florian Weimer
2016-10-12 15:58         ` Florian Weimer
2016-10-12 16:10           ` Zack Weinberg
2016-10-17 13:02             ` Florian Weimer
2016-10-17 13:07               ` Zack Weinberg
2016-10-17 12:54           ` Torvald Riegel [this message]
2016-10-17 13:01             ` Florian Weimer
2016-10-03 17:51   ` Carlos O'Donell
2016-10-04 12:02     ` Florian Weimer
2016-10-04 12:24       ` Adhemerval Zanella
2016-10-04 16:05     ` Torvald Riegel
2016-10-04 20:31       ` Zack Weinberg
2016-10-05  7:18         ` Florian Weimer
2016-10-05 12:42           ` Zack Weinberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476708857.14800.12.camel@localhost.localdomain \
    --to=triegel@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).