diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 35f13b9..7b94408 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1808,6 +1808,54 @@ sysctl_kern_proc_auxv(SYSCTL_HANDLER_ARGS) } /* + * This sysctl allows a process to retrieve ps_strings of another process. + */ +static int +sysctl_kern_proc_ps_strings(SYSCTL_HANDLER_ARGS) +{ + int *name = (int*) arg1; + u_int namelen = arg2; + struct proc *p; + struct ps_strings pss; + size_t size; + int error; + + if (namelen != 1) + return (EINVAL); + + p = pfind((pid_t)name[0]); + if (p == NULL) + return (ESRCH); + if (p->p_flag & P_WEXIT) { + PROC_UNLOCK(p); + return (ESRCH); + } + if ((error = p_cansee(curthread, p)) != 0) { + PROC_UNLOCK(p); + return (error); + } + if ((p->p_flag & P_SYSTEM) != 0) { + PROC_UNLOCK(p); + return (0); + } + _PHOLD(p); + PROC_UNLOCK(p); +#ifdef COMPAT_FREEBSD32 + if (SV_PROC_FLAG(p, SV_ILP32) != 0) + size = sizeof(struct freebsd32_ps_strings); + else +#endif + size = sizeof(pss); + error = proc_read_mem(curthread, p, + (vm_offset_t)(p->p_sysent->sv_psstrings), &pss, size); + PRELE(p); + if (error != 0) + return (error); + error = SYSCTL_OUT(req, &pss, size); + return (error); +} + +/* * This sysctl allows a process to retrieve the path of the executable for * itself or another process. */ @@ -2477,6 +2525,10 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC_AUXV, auxv, CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_auxv, "Process ELF auxiliary vector"); +static SYSCTL_NODE(_kern_proc, KERN_PROC_PS_STRINGS, ps_strings, + CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, + sysctl_kern_proc_ps_strings, "Process ps_strings"); + static SYSCTL_NODE(_kern_proc, KERN_PROC_PATHNAME, pathname, CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc_pathname, "Process executable path"); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index db08a3a..6528be2 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -562,6 +562,7 @@ SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a; unsigned long long *b; ); #define KERN_PROC_ENV 35 /* get environment */ #define KERN_PROC_AUXV 36 /* get ELF auxiliary vector */ #define KERN_PROC_RLIMIT 37 /* process resource limits */ +#define KERN_PROC_PS_STRINGS 38 /* get ps_strings */ /* * KERN_IPC identifiers