From a14132db566b083c26658ccbf0a1ba8885fc5c27 Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Tue, 9 May 2023 06:18:33 +0000 Subject: [PATCH] 15635 /proc/pid xregs file panics cross-thread Reviewed by: Andy Fiddaman Reviewed by: Dan McDonald Reviewed by: Alex Wilson Reviewed by: Bill Sommerfeld Approved by: Patrick Mooney --- usr/src/man/man5/proc.5 | 3 ++- usr/src/uts/common/fs/proc/prvnops.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/usr/src/man/man5/proc.5 b/usr/src/man/man5/proc.5 index b58e28f1c2..85cc1dcba1 100644 --- a/usr/src/man/man5/proc.5 +++ b/usr/src/man/man5/proc.5 @@ -19,7 +19,7 @@ .\" fields enclosed by brackets "[]" replaced with your own identifying .\" information: Portions Copyright [yyyy] [name of copyright owner] .\" -.Dd May 17, 2020 +.Dd May 8, 2023 .Dt PROC 5 .Os .Sh NAME @@ -1830,6 +1830,7 @@ If the lwp is not stopped, all register values are undefined. See also the .Sx PCSXREG control operation, below. +Reading this data currently requires that the process be stopped. .Ss asrs This file exists only for 64-bit SPARC V9 processes. It contains an diff --git a/usr/src/uts/common/fs/proc/prvnops.c b/usr/src/uts/common/fs/proc/prvnops.c index 786f346663..adabbcd80d 100644 --- a/usr/src/uts/common/fs/proc/prvnops.c +++ b/usr/src/uts/common/fs/proc/prvnops.c @@ -1693,6 +1693,21 @@ pr_read_xregs(prnode_t *pnp, uio_t *uiop, cred_t *cr) prunlock(pnp); return (0); } + + /* + * To read the extended register set we require that the thread be + * stopped as this state is only valid in the kernel when it is. An + * exception made if the target thread and the current thread are one + * and the same. We won't stop you from doing something... weird. + */ + thread_lock(t); + if (t != curthread && !ISTOPPED(t) && !VSTOPPED(t) && !DSTOPPED(t)) { + thread_unlock(t); + prunlock(pnp); + return (EBUSY); + } + thread_unlock(t); + mutex_exit(&p->p_lock); xreg = kmem_zalloc(size, KM_SLEEP); mutex_enter(&p->p_lock); -- 2.11.4.GIT