- /dev/mem: only allow access to physical RAM

- /dev/kmem: disallow access to devices

This is designed to protect device registers from being corrupted
accidentally by "innocent" mem/kmem grovellers.
This commit is contained in:
thorpej 1997-03-15 23:30:12 +00:00
parent 6fa9be2e93
commit bbcda6f26b
1 changed files with 19 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mem.c,v 1.14 1997/02/02 07:59:41 thorpej Exp $ */
/* $NetBSD: mem.c,v 1.15 1997/03/15 23:30:12 thorpej Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -56,6 +56,7 @@
#include <vm/vm.h>
extern u_int lowram;
extern char *extiobase;
static caddr_t devzeropage;
/*ARGSUSED*/
@ -116,13 +117,15 @@ mmrw(dev, uio, flags)
/* minor device 0 is physical memory */
case 0:
v = uio->uio_offset;
#ifndef DEBUG
/* allow reads only in RAM (except for DEBUG) */
/*
* Only allow reads in physical RAM.
*/
if (v >= 0xFFFFFFFC || v < lowram) {
error = EFAULT;
goto unlock;
}
#endif
pmap_enter(pmap_kernel(), (vm_offset_t)vmmap,
trunc_page(v), uio->uio_rw == UIO_READ ?
VM_PROT_READ : VM_PROT_WRITE, TRUE);
@ -140,6 +143,17 @@ mmrw(dev, uio, flags)
if (!kernacc((caddr_t)v, c,
uio->uio_rw == UIO_READ ? B_READ : B_WRITE))
return (EFAULT);
/*
* Don't allow reading intio or dio
* device space. This could lead to
* corruption of device registers.
*/
if (ISIIOVA(v) ||
((caddr_t)v >= extiobase &&
(caddr_t)v < (extiobase + (EIOMAPSIZE * NBPG))))
return (EFAULT);
error = uiomove((caddr_t)v, c, uio);
continue;
@ -158,19 +172,11 @@ mmrw(dev, uio, flags)
/*
* On the first call, allocate and zero a page
* of memory for use with /dev/zero.
*
* XXX on the hp300 we already know where there
* is a global zeroed page, the null segment table.
*/
if (devzeropage == NULL) {
#if CLBYTES == NBPG
extern caddr_t Segtabzero;
devzeropage = Segtabzero;
#else
devzeropage = (caddr_t)
malloc(CLBYTES, M_TEMP, M_WAITOK);
bzero(devzeropage, CLBYTES);
#endif
}
c = min(iov->iov_len, CLBYTES);
error = uiomove(devzeropage, c, uio);
@ -210,11 +216,9 @@ mmmmap(dev, off, prot)
*/
if (minor(dev) != 0)
return (-1);
/*
* Allow access only in RAM.
*
* XXX could be extended to allow access to IO space but must
* be very careful.
*/
if ((unsigned)off < lowram || (unsigned)off >= 0xFFFFFFFC)
return (-1);