Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Apr 2015 14:38:12 +0200
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        Andrew Turner <andrew@fubar.geek.nz>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r280955 - in head/sys: modules/notrandom dev/notrandom
Message-ID:  <20150401123812.GB10926@dft-labs.eu>
In-Reply-To: <20150401133114.16e7d7ba@bender>
References:  <20150401113628.GA16649@dft-labs.eu> <20150401133114.16e7d7ba@bender>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Apr 01, 2015 at 01:31:14PM +0100, Andrew Turner wrote:
> On Wed, 1 Apr 2015 13:36:28 +0200
> Mateusz Guzik <mjg@freebsd.org> wrote:
> 
> > Author: mjg
> > Date: Wed Apr  1 13:37:00 2015
> > New Revision: 280955
> > URL: https://svnweb.freebsd.org/changeset/base/280955
> > 
> > Log:
> >   Add /dev/notrandom
> > 
> >   notrandom provides fast and reliable not random numbers.
> > 
> >   This was added in an effort to increase feature-compatiblity with
> >   Solaris 10.
> > 
> >   See http://www.brendangregg.com/Specials/notrandom.c for Solaris
> >   implementation.
> > 
> >   Reviewed-by: Bruce Schneier (ok, not really)
> >   MFC after:	1 week
> 
> I've been thinking about adding something similar for some time. I do
> have one question, should it accept data for the notrandom number
> generator? It would only need to accept up until the first notrandom
> number. I was thinking something like the following patch (untested).
> 
> Andrew
> 
> diff --git a/sys/dev/notrandom/notrandom.c
> b/sys/dev/notrandom/notrandom.c index c09eaf3..9e5f523 100644
> --- a/sys/dev/notrandom/notrandom.c
> +++ b/sys/dev/notrandom/notrandom.c
> @@ -41,10 +41,12 @@ static struct cdev *notrandom_dev;
>  
>  static d_ioctl_t notrandom_ioctl;
>  static d_read_t notrandom_read;
> +static d_read_t notrandom_write;
>  
>  static struct cdevsw notrandom_cdevsw = {
>         .d_version =    D_VERSION,
>         .d_read =       notrandom_read,
> +       .d_write =      notrandom_write,
>         .d_ioctl =      notrandom_ioctl,
>         .d_name =       "notrandom",
>         .d_flags =      D_MMAP_ANON,
> @@ -91,6 +93,30 @@ notrandom_read(struct cdev *dev __unused, struct uio
> *uio, int flags __unused) 
>  /* ARGSUSED */
>  static int
> +notrandom_write(struct cdev *dev __unused, struct uio *uio, int flags
> __unused)
> +{
> +       size_t pos;
> +       ssize_t len;
> +       int error = 0;
> +       char buf;
> +
> +       pos = 0;
> +       while (uio->uio_resid > 0) {
> +               len = uio->uio_resid;
> +               error = uiomove(&buf, 1, uio);
> +               if (error != 0)
> +                       break;
> +               if (buf != 7)
> +                       return (EIO);
> +               notrandom_buf[pos++] = buf;
> +               pos %= sizeof(notrandom_buf);

I disagree with this part.

It should only write buffers which fit the rest of the buffer, it should
not wrap.

Would you mind fixing the patch, testing it and allowing me later to
commit it without attribution?

Thanks,

> +       }
> +
> +       return (error);
> +}
> +

-- 
Mateusz Guzik <mjguzik gmail.com>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150401123812.GB10926>