summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>1998-02-19 22:00:28 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>1998-02-19 22:00:28 +0000
commit9b02cfd2d4749e3301df5950aa0ab1b8ae0631cb (patch)
treee18fe1c774c80786fd05d3fbbca434b393d26408 /sys
parent2ef21da2c9cc72e7e2e80aad72d1db87f8f2438f (diff)
Tighten up the mmapping of char devices even more. Do not allow
MAP_PRIVATE or MAP_COPY of them as it was incorrectly handled anyhow.
Diffstat (limited to 'sys')
-rw-r--r--sys/vm/vm_mmap.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c
index 7d7855d341f..3d6ab555d69 100644
--- a/sys/vm/vm_mmap.c
+++ b/sys/vm/vm_mmap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vm_mmap.c,v 1.11 1998/02/18 23:36:12 deraadt Exp $ */
+/* $OpenBSD: vm_mmap.c,v 1.12 1998/02/19 22:00:27 niklas Exp $ */
/* $NetBSD: vm_mmap.c,v 1.47 1996/03/16 23:15:23 christos Exp $ */
/*
@@ -213,7 +213,13 @@ sys_mmap(p, v, retval)
if (fp->f_type != DTYPE_VNODE)
return (EINVAL);
vp = (struct vnode *)fp->f_data;
- if (vp->v_type != VREG && vp->v_type != VCHR)
+
+ /*
+ * Only files and cdevs are mappable, and cdevs does not
+ * provide private mappings of any kind.
+ */
+ if (vp->v_type != VREG &&
+ (vp->v_type != VCHR || (flags & (MAP_PRIVATE|MAP_COPY))))
return (EINVAL);
/*
* XXX hack to handle use of /dev/zero to map anon
@@ -238,17 +244,16 @@ sys_mmap(p, v, retval)
else if (prot & PROT_READ)
return (EACCES);
- if ((flags & MAP_SHARED) != 0 ||
- ((flags & (MAP_PRIVATE|MAP_SHARED|MAP_COPY)) == MAP_FILE &&
- vp->v_type == VCHR)) {
- if (fp->f_flag & FWRITE)
- maxprot |= VM_PROT_WRITE;
- } else if (flags & MAP_SHARED) {
- if (fp->f_flag & FWRITE)
- maxprot |= VM_PROT_WRITE;
- else if (prot & PROT_WRITE)
- return (EACCES);
- } else
+ /*
+ * If we are sharing potential changes (either via MAP_SHARED
+ * or via the implicit sharing of character device mappings),
+ * and we are trying to get write permission although we
+ * opened it without asking for it, bail out.
+ */
+ if (((flags & MAP_SHARED) != 0 || vp->v_type == VCHR) &&
+ (fp->f_flag & FWRITE) == 0 && (prot & PROT_WRITE) != 0)
+ return (EACCES);
+ else
maxprot |= VM_PROT_WRITE;
handle = (caddr_t)vp;
} else {