diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index 1023608..09c22e3 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -79,6 +79,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -874,7 +875,8 @@ linprocfs_doprocenviron(PFS_FILL_ARGS) static int linprocfs_doprocmaps(PFS_FILL_ARGS) { - vm_map_t map = &p->p_vmspace->vm_map; + struct vmspace *vm; + vm_map_t map; vm_map_entry_t entry, tmp_entry; vm_object_t obj, tobj, lobj; vm_offset_t e_start, e_end; @@ -899,6 +901,10 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) return (EOPNOTSUPP); error = 0; + vm = vmspace_acquire_ref(p); + if (vm == NULL) + return (ESRCH); + map = &vm->vm_map; vm_map_lock_read(map); for (entry = map->header.next; entry != &map->header; entry = entry->next) { @@ -985,6 +991,7 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); return (error); } diff --git a/sys/fs/procfs/procfs_map.c b/sys/fs/procfs/procfs_map.c index d27415b..0d41345 100644 --- a/sys/fs/procfs/procfs_map.c +++ b/sys/fs/procfs/procfs_map.c @@ -53,6 +53,7 @@ #include #include +#include #include #include #include @@ -82,7 +83,8 @@ extern struct sysentvec ia32_freebsd_sysvec; int procfs_doprocmap(PFS_FILL_ARGS) { - vm_map_t map = &p->p_vmspace->vm_map; + struct vmspace *vm; + vm_map_t map; vm_map_entry_t entry, tmp_entry; struct vnode *vp; char *fullpath, *freepath; @@ -109,6 +111,10 @@ procfs_doprocmap(PFS_FILL_ARGS) } #endif + vm = vmspace_acquire_ref(p); + if (vm == NULL) + return (ESRCH); + map = &vm->vm_map; vm_map_lock_read(map); for (entry = map->header.next; entry != &map->header; entry = entry->next) { @@ -235,5 +241,6 @@ procfs_doprocmap(PFS_FILL_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); return (error); } diff --git a/sys/fs/pseudofs/pseudofs_vnops.c b/sys/fs/pseudofs/pseudofs_vnops.c index ef91bfd..a4338ca 100644 --- a/sys/fs/pseudofs/pseudofs_vnops.c +++ b/sys/fs/pseudofs/pseudofs_vnops.c @@ -476,7 +476,7 @@ pfs_read(struct vop_read_args *va) struct uio *uio = va->a_uio; struct proc *proc; struct sbuf *sb = NULL; - int error; + int error, locked; unsigned int buflen, offset, resid; PFS_TRACE(("%s", pn->pn_name)); @@ -502,13 +502,15 @@ pfs_read(struct vop_read_args *va) PROC_UNLOCK(proc); } + vhold(vn); + locked = VOP_ISLOCKED(vn); + VOP_UNLOCK(vn, 0); + if (pn->pn_flags & PFS_RAWRD) { PFS_TRACE(("%lu resid", (unsigned long)uio->uio_resid)); error = pn_fill(curthread, proc, pn, NULL, uio); PFS_TRACE(("%lu resid", (unsigned long)uio->uio_resid)); - if (proc != NULL) - PRELE(proc); - PFS_RETURN (error); + goto ret; } /* beaucoup sanity checks so we don't ask for bogus allocation */ @@ -518,7 +520,8 @@ pfs_read(struct vop_read_args *va) (buflen = offset + resid + 1) < offset || buflen > INT_MAX) { if (proc != NULL) PRELE(proc); - PFS_RETURN (EINVAL); + error = EINVAL; + goto ret; } if (buflen > MAXPHYS + 1) { if (proc != NULL) @@ -528,24 +531,25 @@ pfs_read(struct vop_read_args *va) sb = sbuf_new(sb, NULL, buflen, 0); if (sb == NULL) { - if (proc != NULL) - PRELE(proc); - PFS_RETURN (EIO); + error = EIO; + goto ret; } error = pn_fill(curthread, proc, pn, sb, uio); - if (proc != NULL) - PRELE(proc); - if (error) { sbuf_delete(sb); - PFS_RETURN (error); + goto ret; } sbuf_finish(sb); error = uiomove_frombuf(sbuf_data(sb), sbuf_len(sb), uio); sbuf_delete(sb); +ret: + vn_lock(vn, locked | LK_RETRY); + vdrop(vn); + if (proc != NULL) + PRELE(proc); PFS_RETURN (error); } diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 9f42891..9c6225f 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1357,6 +1357,7 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) struct vnode *vp; struct proc *p; vm_map_t map; + struct vmspace *vm; name = (int *)arg1; if ((p = pfind((pid_t)name[0])) == NULL) @@ -1371,7 +1372,11 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) } _PHOLD(p); PROC_UNLOCK(p); - + vm = vmspace_acquire_ref(p); + if (vm == NULL) { + PRELE(p); + return (ESRCH); + } kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK); map = &p->p_vmspace->vm_map; /* XXXRW: More locking required? */ @@ -1501,6 +1506,7 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); PRELE(p); free(kve, M_TEMP); return (error); @@ -1523,6 +1529,7 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) int error, *name; struct vnode *vp; struct proc *p; + struct vmspace *vm; vm_map_t map; name = (int *)arg1; @@ -1538,10 +1545,14 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) } _PHOLD(p); PROC_UNLOCK(p); - + vm = vmspace_acquire_ref(p); + if (vm == NULL) { + PRELE(p); + return (ESRCH); + } kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK); - map = &p->p_vmspace->vm_map; /* XXXRW: More locking required? */ + map = &vm->vm_map; /* XXXRW: More locking required? */ vm_map_lock_read(map); for (entry = map->header.next; entry != &map->header; entry = entry->next) { @@ -1672,6 +1683,7 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) } } vm_map_unlock_read(map); + vmspace_free(vm); PRELE(p); free(kve, M_TEMP); return (error); diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 348acdf..3089638 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1679,7 +1679,7 @@ p_candebug(struct thread *td, struct proc *p) * should be moved to the caller's of p_candebug(). */ if ((p->p_flag & P_INEXEC) != 0) - return (EAGAIN); + return (EBUSY); return (0); } diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 5d79ca2..3e9878e 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -1416,11 +1417,16 @@ userland_sysctl(struct thread *td, int *name, u_int namelen, void *old, SYSCTL_LOCK(); CURVNET_SET(TD_TO_VNET(curthread)); - do { + for (;;) { req.oldidx = 0; req.newidx = 0; error = sysctl_root(0, name, namelen, &req); - } while (error == EAGAIN); + if (error != EAGAIN) + break; + DROP_GIANT(); + uio_yield(); + PICKUP_GIANT(); + } if (req.lock == REQ_WIRED && req.validlen > 0) vsunlock(req.oldptr, req.validlen);