diff options
Diffstat (limited to 'sys/kern/kern_prot.c')
-rw-r--r-- | sys/kern/kern_prot.c | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 13c94cd0adb..fa3f48bcb6d 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_prot.c,v 1.34 2008/10/14 18:27:29 guenther Exp $ */ +/* $OpenBSD: kern_prot.c,v 1.35 2008/10/31 17:15:30 deraadt Exp $ */ /* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */ /* @@ -234,10 +234,18 @@ int sys_setsid(struct proc *p, void *v, register_t *retval) { + struct session *nsess; + struct pgrp *npgrp; + + nsess = pool_get(&session_pool, PR_WAITOK); + npgrp = pool_get(&pgrp_pool, PR_WAITOK); + if (p->p_pgid == p->p_pid || pgfind(p->p_pid)) { + pool_put(&pgrp_pool, npgrp); + pool_put(&session_pool, nsess); return (EPERM); } else { - (void)enterpgrp(p, p->p_pid, 1); + (void) enterpgrp(p, p->p_pid, npgrp, nsess); *retval = p->p_pid; return (0); } @@ -265,9 +273,9 @@ sys_setpgid(struct proc *curp, void *v, register_t *retval) syscallarg(int) pgid; } */ *uap = v; struct proc *targp; /* target process */ - struct pgrp *pgrp; /* target pgrp */ + struct pgrp *pgrp, *npgrp; /* target pgrp */ pid_t pid; - int pgid; + int pgid, error; pid = SCARG(uap, pid); pgid = SCARG(uap, pgid); @@ -275,24 +283,40 @@ sys_setpgid(struct proc *curp, void *v, register_t *retval) if (pgid < 0) return (EINVAL); + npgrp = pool_get(&pgrp_pool, PR_WAITOK); + if (pid != 0 && pid != curp->p_pid) { - if ((targp = pfind(pid)) == 0 || !inferior(targp)) - return (ESRCH); - if (targp->p_session != curp->p_session) - return (EPERM); - if (targp->p_flag & P_EXEC) - return (EACCES); + if ((targp = pfind(pid)) == 0 || !inferior(targp)) { + error = ESRCH; + goto out; + } + if (targp->p_session != curp->p_session) { + error = EPERM; + goto out; + } + if (targp->p_flag & P_EXEC) { + error = EACCES; + goto out; + } } else targp = curp; - if (SESS_LEADER(targp)) - return (EPERM); + if (SESS_LEADER(targp)) { + error = EPERM; + goto out; + } if (pgid == 0) pgid = targp->p_pid; else if (pgid != targp->p_pid) if ((pgrp = pgfind(pgid)) == 0 || - pgrp->pg_session != curp->p_session) - return (EPERM); - return (enterpgrp(targp, pgid, 0)); + pgrp->pg_session != curp->p_session) { + error = EPERM; + goto out; + } + return (enterpgrp(targp, pgid, npgrp, NULL)); +out: + if (npgrp) + pool_put(&pgrp_pool, npgrp); + return (error); } /* ARGSUSED */ |