| Summary: | Non-blocking IO not supported on /dev/random | ||
|---|---|---|---|
| Product: | Base System | Reporter: | marka <marka> |
| Component: | kern | Assignee: | Mark Murray <markm> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
Responsible Changed From-To: freebsd-bugs->markm Mark Murray has recently re-implemented the random device in the development branch of FreeBSD. This makes him the closest thing we have to a maintainer, although that may just mean you'll have to wait for the new devices to be merged back onto the stable branch. By the way, are you sure /dev/urandom doesn't do what you want? Hi there,
This was brought to my attention by a co-worker, and is a legitimate
complaint about our device handling for {/dev/null, /dev/random,
/dev/urandom, /dev/zero, ...}. Apparently it is not possible to set the
device to support non-blocking file I/O, which seems silly as the
semantics of the device should permit it. In order for these devices to
be used properly from threaded programs based on a select() loop,
non-blocking mode is required.
Unfortunately, we didn't give the best answer to the initial bug report:
Synopsis: Non-blocking IO not supported on /dev/random
Responsible-Changed-From-To: freebsd-bugs->markm
Responsible-Changed-By: sheldonh
Responsible-Changed-When: Wed Jul 12 01:33:02 PDT 2000
Responsible-Changed-Why:
Mark Murray has recently re-implemented the random device in
the development branch of FreeBSD. This makes him the closest
thing we have to a maintainer, although that may just mean
you'll have to wait for the new devices to be merged back onto the
stable branch.
By the way, are you sure /dev/urandom doesn't do what you want?
http://www.freebsd.org/cgi/query-pr.cgi?pr=19863
/dev/urandom also does not allow the setting of non-blocking mode.
This is probably something that needs to be fixed; it's a pity we didn't
catch this before 4.1-RELEASE. I looked through the code some, and noted
that /dev/{useful_virtual_stuff} don't implement ioctl(), specifically,
support for async I/O, which apparently is required to enable non-blocking
I/O (fo_ioctl()).
Note that I believe it is insufficient for us to simply provide
non-blocking semantics for the device, we actually have to support the
flag also for application compatibility. Apparently /dev/random *does*
behave correctly on other platforms (Linux, NetBSD, ...) Given that
/dev/random is frequently used by security programs, providing correct and
consistent semantics is important.
This has been demonstrated both in the old /dev/random in 4.x, as well as
the revised 5.x devices.
Robert N M Watson
robert@fledge.watson.org http://www.watson.org/~robert/
PGP key fingerprint: AF B5 5F FF A6 4A 79 37 ED 5F 55 E9 58 04 6A B1
TIS Labs at Network Associates, Safeport Network Services
---------- Forwarded message ----------
Date: Tue, 11 Jul 2000 23:41:08 -0700 (PDT)
From: marka@nominum.com
To: freebsd-gnats-submit@FreeBSD.org
Subject: kern/19863: Non-blocking IO not supported on /dev/random
>Number: 19863
>Category: kern
>Synopsis: Non-blocking IO not supported on /dev/random
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Jul 11 23:50:03 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Mark Andrews
>Release: 4.0-stable
>Organization:
Nominum
>Environment:
FreeBSD drugs.dv.isc.org 4.0-STABLE FreeBSD 4.0-STABLE #1: Sat Jul 1 00:10:47 EST 2000 root@drugs.dv.isc.org:/usr/src/sys/compile/DRUGS i386
>Description:
It is not possible to set /dev/random into non-blocking mode using
fcntl. This make it impossible to use /dev/random in a application
that requires IO not to block.
>How-To-Repeat:
#include <fcntl.h>
#include <stdio.h>
int
main(int argc, char **argv) {
int fd;
int flags;
if ((fd = open("/dev/random", O_RDONLY, 0)) == -1) {
perror("open");
exit(1);
}
if ((flags = fcntl(fd, F_GETFL, 0)) == -1) {
perror("fcntl: F_GETFL");
exit(1);
}
flags |= O_NONBLOCK;
if (fcntl(fd, F_SETFL, flags) == -1) {
perror("fcntl: F_SETFL");
exit(1);
}
close(fd);
exit(0);
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Mark, Just a heads up so that you know that your report hasn't completely disappeared into void, this is being worked on by Mark Murray. Not sure if he currently has an ETA at this point, but it is my hope that the fix will be in FreeBSD 4.2 come November, and preferably in the -STABLE branch before then. On Tue, 11 Jul 2000 marka@nominum.com wrote: > > >Number: 19863 > >Category: kern > >Synopsis: Non-blocking IO not supported on /dev/random > >Confidential: no > >Severity: non-critical > >Priority: medium > >Responsible: freebsd-bugs > >State: open > >Quarter: > >Keywords: > >Date-Required: > >Class: sw-bug > >Submitter-Id: current-users > >Arrival-Date: Tue Jul 11 23:50:03 PDT 2000 > >Closed-Date: > >Last-Modified: > >Originator: Mark Andrews > >Release: 4.0-stable > >Organization: > Nominum > >Environment: > FreeBSD drugs.dv.isc.org 4.0-STABLE FreeBSD 4.0-STABLE #1: Sat Jul 1 00:10:47 EST 2000 root@drugs.dv.isc.org:/usr/src/sys/compile/DRUGS i386 > > >Description: > It is not possible to set /dev/random into non-blocking mode using > fcntl. This make it impossible to use /dev/random in a application > that requires IO not to block. > >How-To-Repeat: > #include <fcntl.h> > #include <stdio.h> > int > main(int argc, char **argv) { > int fd; > int flags; > > if ((fd = open("/dev/random", O_RDONLY, 0)) == -1) { > perror("open"); > exit(1); > } > if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { > perror("fcntl: F_GETFL"); > exit(1); > } > flags |= O_NONBLOCK; > if (fcntl(fd, F_SETFL, flags) == -1) { > perror("fcntl: F_SETFL"); > exit(1); > } > close(fd); > exit(0); > } > > >Fix: > > > >Release-Note: > >Audit-Trail: > >Unformatted: > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-bugs" in the body of the message > Robert N M Watson robert@fledge.watson.org http://www.watson.org/~robert/ PGP key fingerprint: AF B5 5F FF A6 4A 79 37 ED 5F 55 E9 58 04 6A B1 TIS Labs at Network Associates, Safeport Network Services > Just a heads up so that you know that your report hasn't completely > disappeared into void, this is being worked on by Mark Murray. Not sure > if he currently has an ETA at this point, but it is my hope that the fix > will be in FreeBSD 4.2 come November, and preferably in the -STABLE branch > before then. Actually, I'm hoping for a 4.1-STABLE fix by the end of the week, and CURRENT a bit later than that. > On Tue, 11 Jul 2000 marka@nominum.com wrote: > > > > > >Number: 19863 > > >Category: kern > > >Synopsis: Non-blocking IO not supported on /dev/random > > >Confidential: no > > >Severity: non-critical > > >Priority: medium > > >Responsible: freebsd-bugs > > >State: open > > >Quarter: > > >Keywords: > > >Date-Required: > > >Class: sw-bug > > >Submitter-Id: current-users > > >Arrival-Date: Tue Jul 11 23:50:03 PDT 2000 > > >Closed-Date: > > >Last-Modified: > > >Originator: Mark Andrews > > >Release: 4.0-stable > > >Organization: > > Nominum > > >Environment: > > FreeBSD drugs.dv.isc.org 4.0-STABLE FreeBSD 4.0-STABLE #1: Sat Jul 1 00:10 :47 EST 2000 root@drugs.dv.isc.org:/usr/src/sys/compile/DRUGS i386 > > > > >Description: > > It is not possible to set /dev/random into non-blocking mode using > > fcntl. This make it impossible to use /dev/random in a application > > that requires IO not to block. > > >How-To-Repeat: > > #include <fcntl.h> > > #include <stdio.h> > > int > > main(int argc, char **argv) { > > int fd; > > int flags; > > > > if ((fd = open("/dev/random", O_RDONLY, 0)) == -1) { > > perror("open"); > > exit(1); > > } > > if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { > > perror("fcntl: F_GETFL"); > > exit(1); > > } > > flags |= O_NONBLOCK; > > if (fcntl(fd, F_SETFL, flags) == -1) { > > perror("fcntl: F_SETFL"); > > exit(1); > > } > > close(fd); > > exit(0); > > } > > > > >Fix: > > > > > > >Release-Note: > > >Audit-Trail: > > >Unformatted: > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > > with "unsubscribe freebsd-bugs" in the body of the message > > > > > Robert N M Watson > > robert@fledge.watson.org http://www.watson.org/~robert/ > PGP key fingerprint: AF B5 5F FF A6 4A 79 37 ED 5F 55 E9 58 04 6A B1 > TIS Labs at Network Associates, Safeport Network Services > > -- Mark Murray Join the anti-SPAM movement: http://www.cauce.org This PR can be closed
My 4.3-REL. system does not show this error anymore, for any of /dev/{[u]random, null, zero)
State Changed From-To: open->closed Olafur Gudmundsson <ogud@starpower.net> reports the problem solved. Thanks! |
It is not possible to set /dev/random into non-blocking mode using fcntl. This make it impossible to use /dev/random in a application that requires IO not to block. How-To-Repeat: #include <fcntl.h> #include <stdio.h> int main(int argc, char **argv) { int fd; int flags; if ((fd = open("/dev/random", O_RDONLY, 0)) == -1) { perror("open"); exit(1); } if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { perror("fcntl: F_GETFL"); exit(1); } flags |= O_NONBLOCK; if (fcntl(fd, F_SETFL, flags) == -1) { perror("fcntl: F_SETFL"); exit(1); } close(fd); exit(0); }