diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 2001-05-07 22:16:36 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 2001-05-07 22:16:36 +0000 |
commit | 22f48925353e2e2e985a7eefd4a3d59d7dadde16 (patch) | |
tree | 515ec7a80cf8f9ffaeb3cb471b6e1d2d6adff6e9 | |
parent | c62055b4d0abeee6d1d28d73cc3adfe58e68a0e8 (diff) |
Check for failure now that uvm_vslock can return one. Before this, there was
a risk that we could crash when doing physio/sysctl when the system was
completly out of RAM and swap.
-rw-r--r-- | sys/kern/kern_physio.c | 13 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 9 |
2 files changed, 17 insertions, 5 deletions
diff --git a/sys/kern/kern_physio.c b/sys/kern/kern_physio.c index 6aa0b547718..58c5b7a4eb9 100644 --- a/sys/kern/kern_physio.c +++ b/sys/kern/kern_physio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_physio.c,v 1.9 2000/11/09 16:46:52 art Exp $ */ +/* $OpenBSD: kern_physio.c,v 1.10 2001/05/07 22:16:35 art Exp $ */ /* $NetBSD: kern_physio.c,v 1.28 1997/05/19 10:43:28 pk Exp $ */ /*- @@ -101,6 +101,7 @@ physio(strategy, bp, dev, flags, minphys, uio) if (uio->uio_segflg == UIO_USERSPACE) for (i = 0; i < uio->uio_iovcnt; i++) #if defined(UVM) /* XXXCDC: map not locked, rethink */ + /* XXX - obsolete now that vslock can error? */ if (!uvm_useracc(uio->uio_iov[i].iov_base, uio->uio_iov[i].iov_len, (flags == B_READ) ? B_WRITE : B_READ)) @@ -184,8 +185,13 @@ physio(strategy, bp, dev, flags, minphys, uio) */ PHOLD(p); #if defined(UVM) - uvm_vslock(p, bp->b_data, todo, (flags & B_READ) ? - VM_PROT_READ | VM_PROT_WRITE : VM_PROT_READ); + if (uvm_vslock(p, bp->b_data, todo, (flags & B_READ) ? + VM_PROT_READ | VM_PROT_WRITE : VM_PROT_READ) != + KERN_SUCCESS) { + bp->b_flags |= B_ERROR; + bp->b_error = EFAULT; + goto after_unlock; + } #else vslock(bp->b_data, todo); #endif @@ -221,6 +227,7 @@ physio(strategy, bp, dev, flags, minphys, uio) vunmapbuf(bp, todo); #if defined(UVM) uvm_vsunlock(p, bp->b_data, todo); +after_unlock: #else vsunlock(bp->b_data, todo); #endif diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 387d39f0184..9ee8ca8ba93 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.41 2001/04/06 23:41:02 art Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.42 2001/05/07 22:16:35 art Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -164,6 +164,7 @@ sys___sysctl(p, v, retval) return (error); if (SCARG(uap, old) != NULL) { #if defined(UVM) + /* XXX - obsolete now that vslock returns an error? */ if (!uvm_useracc(SCARG(uap, old), oldlen, B_WRITE)) #else if (!useracc(SCARG(uap, old), oldlen, B_WRITE)) @@ -173,7 +174,11 @@ sys___sysctl(p, v, retval) return (error); if (dolock) #if defined(UVM) - uvm_vslock(p, SCARG(uap, old), oldlen, VM_PROT_NONE); + if (uvm_vslock(p, SCARG(uap, old), oldlen, + VM_PROT_READ|VM_PROT_WRITE) != KERN_SUCCESS) { + lockmgr(&sysctl_lock, LK_RELEASE, NULL, p); + return EFAULT; + } #else vslock(SCARG(uap, old), oldlen); #endif |