From owner-svn-src-all@FreeBSD.ORG Wed Apr 1 17:40:06 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8DD773CD; Wed, 1 Apr 2015 17:40:06 +0000 (UTC) Received: from mail-wi0-x233.google.com (mail-wi0-x233.google.com [IPv6:2a00:1450:400c:c05::233]) (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 47570EF4; Wed, 1 Apr 2015 17:40:06 +0000 (UTC) Received: by wixo5 with SMTP id o5so34504708wix.1; Wed, 01 Apr 2015 10:40:04 -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=L58POvHaDMfe58kX6F2tfYVn0xMf6/BL+tm5NiYbPec=; b=PGZjD4pTscHuLitmy6mj2C6QFrFrFUaRZFwtUjQJBQdw29Ui4RNuBniCGUe8X02apN Tz3V6zi4y0+YGePIanem5ZGWyQFffTPA+SNJmbd6xgVVPbpwUlg3+zLhlADx4/bqqORz pBZwlUkZXfQiSmek2EQ9x5LN+xEzzdjAk9eDzuGbO1bbpeb6ym9ZWmySQU4Rgbm4poTo 5Vb+roZLZ+TqkAN8jXEIRKId/q+phSct1lPbzqZ2iAhdRT2Pv8x98de0xMHZx5b1vxru BNYE2JPJ5ju2ovDhx6O7cVvs3OtshZB6tJPsNkbV31TT7nqCl3IBle6AwJkTnAc313p7 6Hqw== X-Received: by 10.180.219.102 with SMTP id pn6mr16810985wic.50.1427910004735; Wed, 01 Apr 2015 10:40:04 -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 gd6sm26396511wib.17.2015.04.01.10.40.03 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 01 Apr 2015 10:40:03 -0700 (PDT) Sender: Mateusz Guzik Date: Wed, 1 Apr 2015 19:40:01 +0200 From: Mateusz Guzik To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r280866 - in head/sys: modules/notrandom dev/notrandom dev/null Message-ID: <20150401174000.GA2575@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 17:40:06 -0000 Author: mjg Date: Wed Apr 1 19:38:00 2015 New Revision: 280963 URL: https://svnweb.freebsd.org/changeset/base/280963 Log: Move /dev/notrandom implementation to /dev/null driver. Due to popular demand. While here tweak a comment justifying memset when unloading the module. MFC after: 1 week Modified: head/sys/dev/null/null.c Removed: head/sys/modules/notrandom/Makefile head/sys/dev/notrandom/notrandom.c Modified: head/sys/dev/null/null.c =================================================================== --- sys/dev/null/null.c (revision 280404) +++ sys/dev/null/null.c (working copy) @@ -1,9 +1,10 @@ /*- - * Copyright (c) 2000 Mark R. V. Murray & Jeroen C. van Gelderen - * Copyright (c) 2001-2004 Mark R. V. Murray - * Copyright (c) 2014 Eitan Adler + * Copyright (c) 2015 Mateusz Guzik * All rights reserved. * + * Some dudes which previously held the copyright: + * Marc V. R. Murray, Jeroen C. van Gelderen, Eytan Adrel + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -45,11 +46,14 @@ #include /* For use with destroy_dev(9). */ +static char notrandom_buf[1024]; static struct cdev *full_dev; +static struct cdev *notrandom_dev; static struct cdev *null_dev; static struct cdev *zero_dev; static d_write_t full_write; +static d_read_t notrandom_read; static d_write_t null_write; static d_ioctl_t null_ioctl; static d_ioctl_t zero_ioctl; @@ -63,6 +67,14 @@ .d_name = "full", }; +static struct cdevsw notrandom_cdevsw = { + .d_version = D_VERSION, + .d_read = notrandom_read, + .d_ioctl = zero_ioctl, + .d_name = "notrandom", + .d_flags = D_MMAP_ANON, +}; + static struct cdevsw null_cdevsw = { .d_version = D_VERSION, .d_read = (d_read_t *)nullop, @@ -92,6 +104,23 @@ /* 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 null_write(struct cdev *dev __unused, struct uio *uio, int flags __unused) { uio->uio_resid = 0; @@ -173,9 +202,14 @@ switch(type) { case MOD_LOAD: if (bootverbose) - printf("null: \n"); + printf("null: \n"); full_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &full_cdevsw, 0, NULL, UID_ROOT, GID_WHEEL, 0666, "full"); + 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"); null_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &null_cdevsw, 0, NULL, UID_ROOT, GID_WHEEL, 0666, "null"); zero_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &zero_cdevsw, 0, @@ -185,6 +219,12 @@ case MOD_UNLOAD: destroy_dev(full_dev); destroy_dev(null_dev); + destroy_dev(notrandom_dev); + /* + * Thrash notrandom region so that the content cannot be + * retrieved. Better safe than sorry. + */ + memset(notrandom_buf, 123, sizeof(notrandom_buf)); destroy_dev(zero_dev); break; Removed: head/sys/dev/notrandom/notrandom.c =================================================================== --- head/sys/dev/notrandom/notrandom.c (revision r280962) +++ 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 to be 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); Removed: head/sys/modules/notrandom/Makefile =================================================================== --- head/sys/modules/notrandom/Makefile (revision r280962) +++ head/sys/modules/notrandom/Makefile (working copy) @@ -0,0 +1,8 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../dev/notrandom - -KMOD= notrandom -SRCS= notrandom.c - -.include