From: "Theodore Ts'o" <tytso@mit.edu>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: short read from /dev/urandom
Date: Fri, 14 Jan 2005 14:10:56 -0500 [thread overview]
Message-ID: <20050114191056.GB17481@thunk.org> (raw)
In-Reply-To: <41E7509E.4030802@redhat.com>
On Thu, Jan 13, 2005 at 08:54:54PM -0800, Ulrich Drepper wrote:
> The /dev/urandom device is advertised as always returning the requested
> number of bytes. Yet, it fails to do this under some situations.
> Compile this
>
> Note the -pg at the end to enable profiling. Running this code fails
> for me after less than a second.
>
> The relevant code in the kernel is this
> (drivers/char/random.c:extract_entropy)
>
> while (nbytes) {
> /*
> * Check if we need to break out or reschedule....
> */
> if ((flags & EXTRACT_ENTROPY_USER) && need_resched()) {
> if (signal_pending(current)) {
> if (ret == 0)
> ret = -ERESTARTSYS;
> break;
> }
>
>
> Here the loop is left prematurely if a signal is pending.
The problem is that the code doesn't have the code to support
restartable system calls, so it only returns ERESTARTSYS if the nuber
bytes generated is zero. What we should do is implement the full
restartable system calls, such that whether or not /dev/urandom
returns a short read is dependent on whether or not SA_RESTART is
passed to the sigaction() system call.
Yeah, /dev/urandom was advertised as "always" returning the requested
number of bytes, but that was always an informal description, not a
formal one --- such as for example documented behavioiur of SA_RESTART
in sigaction(). So I believe the correct approach is to make
/dev/urandom honor the SA_RESTART flag, and then change the
documentation to match. This is a bit of a compromise between "always
returning" and the current "never returning" behaviour.
What do you think? Does gcc -pg calls sigaction with SA_RESTART, to
avoid changing the behaviour of the programs that it is profiling? If
so, it would allow the program to work, while also being much more
consistent. The flip side is that if there are programs that blindly
read from /dev/urandom for reading without checking its return count,
they could still lose, if their program had any signal handlers that
used System V semantics. I'm not aware of any such programs, but they
certainly could exist.
- Ted
next prev parent reply other threads:[~2005-01-14 19:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-14 4:54 short read from /dev/urandom Ulrich Drepper
2005-01-14 5:56 ` David Wagner
2005-01-14 6:54 ` Ulrich Drepper
2005-01-14 19:55 ` David Wagner
2005-01-14 19:10 ` Theodore Ts'o [this message]
2005-01-14 21:04 ` Ulrich Drepper
2005-01-14 23:21 ` Theodore Ts'o
2005-01-15 2:36 ` H. Peter Anvin
2005-01-16 2:51 ` Matt Mackall
2005-01-16 3:18 ` H. Peter Anvin
2005-01-15 2:34 ` H. Peter Anvin
2005-01-19 15:48 ` Pavel Machek
2005-01-16 2:44 ` Matt Mackall
2005-01-16 3:58 ` Ulrich Drepper
2005-01-16 4:58 ` Matt Mackall
2005-01-16 13:23 ` Andries Brouwer
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=20050114191056.GB17481@thunk.org \
--to=tytso@mit.edu \
--cc=drepper@redhat.com \
--cc=linux-kernel@vger.kernel.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