diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index c64c94743a0c..d3c4234594bd 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -356,7 +356,7 @@ getumask(void) * security.bsd.unprivileged_proc_debug is set to 0. */ len = sizeof(smask); - if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, getpid() }, + if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, 0 }, 4, &smask, &len, NULL, 0) == 0) return (smask); diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 53c08f1b8aa2..01a2f0e59ddb 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -2770,18 +2770,25 @@ sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS) struct proc *p; int error; u_short fd_cmask; + pid_t pid; if (namelen != 1) return (EINVAL); - error = pget((pid_t)name[0], PGET_WANTREAD, &p); + pid = (pid_t)name[0]; + p = curproc; + if (pid == p->p_pid || pid == 0) { + fd_cmask = p->p_fd->fd_cmask; + goto out; + } + + error = pget(pid, PGET_WANTREAD, &p); if (error != 0) return (error); - FILEDESC_SLOCK(p->p_fd); fd_cmask = p->p_fd->fd_cmask; - FILEDESC_SUNLOCK(p->p_fd); PRELE(p); +out: error = SYSCTL_OUT(req, &fd_cmask, sizeof(fd_cmask)); return (error); }