From nobody@FreeBSD.ORG  Tue Jul 11 23:41:08 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id BE05037BA01; Tue, 11 Jul 2000 23:41:08 -0700 (PDT)
Message-Id: <20000712064108.BE05037BA01@hub.freebsd.org>
Date: Tue, 11 Jul 2000 23:41:08 -0700 (PDT)
From: marka@nominum.com
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: Non-blocking IO not supported on /dev/random
X-Send-Pr-Version: www-1.0

>Number:         19863
>Category:       kern
>Synopsis:       Non-blocking IO not supported on /dev/random
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    markm
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul 11 23:50:03 PDT 2000
>Closed-Date:    Sun Dec 2 01:53:30 PST 2001
>Last-Modified:  Sun Dec 02 01:54:15 PST 2001
>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:
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 

From: Robert Watson <rwatson@FreeBSD.org>
To: freebsd-hackers@FreeBSD.org
Cc: ogud@tislabs.com, marka@nominum.com, markm@FreeBSD.org
Subject: kern/19863: Non-blocking IO not supported on /dev/random
Date: Wed, 26 Jul 2000 11:50:03 -0400 (EDT)

 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
 
 

From: Robert Watson <rwatson@FreeBSD.org>
To: marka@nominum.com
Cc: freebsd-gnats-submit@FreeBSD.org, markm@FreeBSD.org
Subject: Re: kern/19863: Non-blocking IO not supported on /dev/random
Date: Mon, 31 Jul 2000 10:49:18 -0400 (EDT)

 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
 
 

From: Mark Murray <mark@grondar.za>
To: Robert Watson <rwatson@FreeBSD.org>
Cc: marka@nominum.com, freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/19863: Non-blocking IO not supported on /dev/random 
Date: Mon, 31 Jul 2000 19:31:47 +0200

 > 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
 

From: Olafur Gudmundsson <ogud@starpower.net>
To: freebsd-gnats-submit@FreeBSD.org, marka@nominum.com
Cc: ogud@ogud.com, rwatson@freebsd.org
Subject: Re: kern/19863: Non-blocking IO not supported on /dev/random
Date: Sat, 01 Dec 2001 23:41:11 -0500

 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 
State-Changed-By: markm 
State-Changed-When: Sun Dec 2 01:53:30 PST 2001 
State-Changed-Why:  
Olafur Gudmundsson <ogud@starpower.net> reports the problem solved. 

Thanks! 


http://www.FreeBSD.org/cgi/query-pr.cgi?pr=19863 
>Unformatted:
