Date: Sun, 28 Jun 2026 00:30:05 +0000 From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: e856c10a4d6d - stable/14 - kern_proc.c: ensure stability of the vmspace for sysctl kern.proc.vmmap Message-ID: <6a406b0d.3e2a8.555961d9@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=e856c10a4d6dfe30a730246b2050d9dd438085db commit e856c10a4d6dfe30a730246b2050d9dd438085db Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2026-06-14 23:49:20 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2026-06-28 00:28:58 +0000 kern_proc.c: ensure stability of the vmspace for sysctl kern.proc.vmmap (cherry picked from commit 5fe6e08d2db56b530f0df2903ef24cfabab7b8ea) --- sys/kern/kern_proc.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 3ad9e157d622..6c010490f43b 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -2420,6 +2420,7 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) int error, *name; struct vnode *vp; struct proc *p; + struct thread *td; vm_map_t map; struct vmspace *vm; @@ -2428,11 +2429,12 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) return (EINVAL); name = (int *)arg1; + td = curthread; error = pget((pid_t)name[0], PGET_WANTREAD, &p); if (error != 0) return (error); - vm = vmspace_acquire_ref(p); - if (vm == NULL) { + error = proc_vmspace_ref(td, p, PRVM_CHECK_DEBUG, &vm); + if (error != 0) { PRELE(p); return (ESRCH); } @@ -2544,7 +2546,7 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) } } vm_map_unlock_read(map); - vmspace_free(vm); + proc_vmspace_unref(td, p, PRVM_CHECK_DEBUG, vm); PRELE(p); free(kve, M_TEMP); return (error); @@ -2635,6 +2637,7 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) struct vmspace *vm; struct cdev *cdev; struct cdevsw *csw; + struct thread *td; vm_offset_t addr; unsigned int last_timestamp; int error, ref; @@ -2646,10 +2649,11 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) _PHOLD(p); PROC_UNLOCK(p); - vm = vmspace_acquire_ref(p); - if (vm == NULL) { + td = curthread; + error = proc_vmspace_ref(td, p, PRVM_CHECK_DEBUG, &vm); + if (error != 0) { PRELE(p); - return (ESRCH); + return (error); } kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK | M_ZERO); @@ -2764,7 +2768,7 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) if (vp != NULL) { vn_fullpath(vp, &fullpath, &freepath); kve->kve_vn_type = vntype_to_kinfo(vp->v_type); - cred = curthread->td_ucred; + cred = td->td_ucred; vn_lock(vp, LK_SHARED | LK_RETRY); if (VOP_GETATTR(vp, &va, cred) == 0) { kve->kve_vn_fileid = va.va_fileid; @@ -2820,7 +2824,7 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) } } vm_map_unlock_read(map); - vmspace_free(vm); + proc_vmspace_unref(td, p, PRVM_CHECK_DEBUG, vm); PRELE(p); free(kve, M_TEMP); return (error);home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a406b0d.3e2a8.555961d9>
