From owner-svn-src-all@FreeBSD.ORG Wed Apr 1 11:36:33 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DC33035B; Wed, 1 Apr 2015 11:36:33 +0000 (UTC) Received: from mail-wi0-x22c.google.com (mail-wi0-x22c.google.com [IPv6:2a00:1450:400c:c05::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6765FE52; Wed, 1 Apr 2015 11:36:33 +0000 (UTC) Received: by wibgn9 with SMTP id gn9so62582460wib.1; Wed, 01 Apr 2015 04:36:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=Wp/Ev+D7D1jFtNA8Z/23vT4c/Z9O/LihUgzppswvM5Y=; b=Fv+2t/l+geCZ+WDYiyEZpF3MU9fBbQEQV/enteDyktpJwjrkgS97RbHgk0aJx5PyHM WHUeNs64RlEkKWDK2jiBAkcVZPJUr974mbQWt6whU2xLEODv8mlTlcBcx1yQqUnDC6mf ThJO/4zs6u6ow7D/MZSgQlRZ/bLPAEcVqM66BHVhBLMEbeLlwjbrWThhsFD4B04r0fcW TymWa3HDxdD5L8iypH/taZGWx0qdd2bLc3R3mbx3BqWIwNFk+ROQ6jtBzjcPj2Qx0WMp XXz8UD5Jt2E2bWBKMRvRgXRRyj0r7Al7C5O5ORKh6r8RoFubUQOsoGWQvtSABYj2yDEJ 7XNw== X-Received: by 10.194.120.132 with SMTP id lc4mr84698746wjb.92.1427888191827; Wed, 01 Apr 2015 04:36:31 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id q10sm2270002wjr.41.2015.04.01.04.36.30 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 01 Apr 2015 04:36:30 -0700 (PDT) Sender: Mateusz Guzik Date: Wed, 1 Apr 2015 13:36:28 +0200 From: Mateusz Guzik To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r280955 - in head/sys: modules/notrandom dev/notrandom Message-ID: <20150401113628.GA16649@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Apr 2015 11:36:34 -0000 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 Added: head/sys/modules/notrandom/Makefile head/sys/dev/notrandom/notrandom.c Added: sys/dev/notrandom/notrandom.c =================================================================== --- head/sys/dev/notrandom/notrandom.c (revision 0) +++ head/sys/dev/notrandom/notrandom.c (working copy) @@ -0,0 +1,126 @@ +/*- + * Copyright (c) 2015 Mateusz Guzik + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct cdev *notrandom_dev; + +static d_ioctl_t notrandom_ioctl; +static d_read_t notrandom_read; + +static struct cdevsw notrandom_cdevsw = { + .d_version = D_VERSION, + .d_read = notrandom_read, + .d_ioctl = notrandom_ioctl, + .d_name = "notrandom", + .d_flags = D_MMAP_ANON, +}; + +static char notrandom_buf[1024]; + +static int +notrandom_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t data __unused, + int flags __unused, struct thread *td) +{ + int error = 0; + + switch (cmd) { + case FIONBIO: + break; + case FIOASYNC: + if (*(int *)data != 0) + error = EINVAL; + break; + default: + error = ENOIOCTL; + } + return (error); +} + + +/* ARGSUSED */ +static int +notrandom_read(struct cdev *dev __unused, struct uio *uio, int flags __unused) +{ + ssize_t len; + int error = 0; + + while (uio->uio_resid > 0 && error == 0) { + len = uio->uio_resid; + if (len > sizeof(notrandom_buf)) + len = sizeof(notrandom_buf); + error = uiomove(notrandom_buf, len, uio); + } + + return (error); +} + +/* ARGSUSED */ +static int +notrandom_modevent(module_t mod __unused, int type, void *data __unused) +{ + int error = 0; + + switch(type) { + case MOD_LOAD: + memset(notrandom_buf, 7, sizeof(notrandom_buf)); + notrandom_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, + ¬random_cdevsw, 0, NULL, UID_ROOT, GID_WHEEL, 0666, + "notrandom"); + break; + + case MOD_UNLOAD: + destroy_dev(notrandom_dev); + /* + * Trash notrandom region so that the content cannot be + * retrieved. Better safe than sorry. + */ + memset(notrandom_buf, 123, sizeof(notrandom_buf)); + break; + + case MOD_SHUTDOWN: + break; + + default: + error = EOPNOTSUPP; + } + + return (error); +} + +DEV_MODULE(notrandom, notrandom_modevent, NULL); +MODULE_VERSION(notrandom, 1); Property changes on: head/sys/dev/notrandom/notrandom.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: sys/modules/notrandom/Makefile =================================================================== --- head/sys/modules/notrandom/Makefile (revision 0) +++ head/sys/modules/notrandom/Makefile (working copy) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../dev/notrandom + +KMOD= notrandom +SRCS= notrandom.c + +.include Property changes on: head/sys/modules/notrandom/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property