Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_prot.c
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "opt_inet.h" | #include "opt_inet.h" | ||||
#include "opt_inet6.h" | #include "opt_inet6.h" | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/acct.h> | #include <sys/acct.h> | ||||
#include <sys/filedesc.h> | |||||
#include <sys/kdb.h> | #include <sys/kdb.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/loginclass.h> | #include <sys/loginclass.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/refcount.h> | #include <sys/refcount.h> | ||||
#include <sys/sx.h> | #include <sys/sx.h> | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | kern_getppid(struct thread *td) | ||||
int ppid; | int ppid; | ||||
PROC_LOCK(p); | PROC_LOCK(p); | ||||
if (!(p->p_flag & P_TRACED)) { | if (!(p->p_flag & P_TRACED)) { | ||||
ppid = p->p_pptr->p_pid; | ppid = p->p_pptr->p_pid; | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
} else { | } else { | ||||
PROC_UNLOCK(p); | PROC_UNLOCK(p); | ||||
sx_slock(&proctree_lock); | sx_slock(&V_proctree_lock); | ||||
pp = proc_realparent(p); | pp = proc_realparent(p); | ||||
ppid = pp->p_pid; | ppid = pp->p_pid; | ||||
sx_sunlock(&proctree_lock); | sx_sunlock(&V_proctree_lock); | ||||
} | } | ||||
return (ppid); | return (ppid); | ||||
} | } | ||||
/* | /* | ||||
* Get process group ID; note that POSIX getpgrp takes no parameter. | * Get process group ID; note that POSIX getpgrp takes no parameter. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | sys_setsid(struct thread *td, struct setsid_args *uap) | ||||
struct session *newsess; | struct session *newsess; | ||||
error = 0; | error = 0; | ||||
pgrp = NULL; | pgrp = NULL; | ||||
newpgrp = malloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO); | newpgrp = malloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO); | ||||
newsess = malloc(sizeof(struct session), M_SESSION, M_WAITOK | M_ZERO); | newsess = malloc(sizeof(struct session), M_SESSION, M_WAITOK | M_ZERO); | ||||
sx_xlock(&proctree_lock); | sx_xlock(&V_proctree_lock); | ||||
if (p->p_pgid == p->p_pid || (pgrp = pgfind(p->p_pid)) != NULL) { | if (p->p_pgid == p->p_pid || (pgrp = pgfind(p->p_pid)) != NULL) { | ||||
if (pgrp != NULL) | if (pgrp != NULL) | ||||
PGRP_UNLOCK(pgrp); | PGRP_UNLOCK(pgrp); | ||||
error = EPERM; | error = EPERM; | ||||
} else { | } else { | ||||
(void)enterpgrp(p, p->p_pid, newpgrp, newsess); | (void)enterpgrp(p, p->p_pid, newpgrp, newsess); | ||||
td->td_retval[0] = p->p_pid; | td->td_retval[0] = p->p_pid; | ||||
newpgrp = NULL; | newpgrp = NULL; | ||||
newsess = NULL; | newsess = NULL; | ||||
} | } | ||||
sx_xunlock(&proctree_lock); | sx_xunlock(&V_proctree_lock); | ||||
if (newpgrp != NULL) | if (newpgrp != NULL) | ||||
free(newpgrp, M_PGRP); | free(newpgrp, M_PGRP); | ||||
if (newsess != NULL) | if (newsess != NULL) | ||||
free(newsess, M_SESSION); | free(newsess, M_SESSION); | ||||
return (error); | return (error); | ||||
} | } | ||||
Show All 29 Lines | sys_setpgid(struct thread *td, struct setpgid_args *uap) | ||||
if (uap->pgid < 0) | if (uap->pgid < 0) | ||||
return (EINVAL); | return (EINVAL); | ||||
error = 0; | error = 0; | ||||
newpgrp = malloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO); | newpgrp = malloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO); | ||||
sx_xlock(&proctree_lock); | sx_xlock(&V_proctree_lock); | ||||
if (uap->pid != 0 && uap->pid != curp->p_pid) { | if (uap->pid != 0 && uap->pid != curp->p_pid) { | ||||
if ((targp = pfind(uap->pid)) == NULL) { | if ((targp = pfind(uap->pid)) == NULL) { | ||||
error = ESRCH; | error = ESRCH; | ||||
goto done; | goto done; | ||||
} | } | ||||
if (!inferior(targp)) { | if (!inferior(targp)) { | ||||
PROC_UNLOCK(targp); | PROC_UNLOCK(targp); | ||||
error = ESRCH; | error = ESRCH; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (pgrp->pg_id != targp->p_pid && | ||||
PGRP_UNLOCK(pgrp); | PGRP_UNLOCK(pgrp); | ||||
error = EPERM; | error = EPERM; | ||||
goto done; | goto done; | ||||
} | } | ||||
PGRP_UNLOCK(pgrp); | PGRP_UNLOCK(pgrp); | ||||
error = enterthispgrp(targp, pgrp); | error = enterthispgrp(targp, pgrp); | ||||
} | } | ||||
done: | done: | ||||
sx_xunlock(&proctree_lock); | sx_xunlock(&V_proctree_lock); | ||||
KASSERT((error == 0) || (newpgrp != NULL), | KASSERT((error == 0) || (newpgrp != NULL), | ||||
("setpgid failed and newpgrp is NULL")); | ("setpgid failed and newpgrp is NULL")); | ||||
if (newpgrp != NULL) | if (newpgrp != NULL) | ||||
free(newpgrp, M_PGRP); | free(newpgrp, M_PGRP); | ||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 1,264 Lines • ▼ Show 20 Lines | #endif | ||||
if (credentialchanged) { | if (credentialchanged) { | ||||
error = priv_check(td, PRIV_DEBUG_SUGID); | error = priv_check(td, PRIV_DEBUG_SUGID); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
} | } | ||||
/* Can't trace init when securelevel > 0. */ | /* Can't trace init when securelevel > 0. */ | ||||
if (p == initproc) { | if (p == V_initproc) { | ||||
error = securelevel_gt(td->td_ucred, 0); | error = securelevel_gt(td->td_ucred, 0); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* Can't trace a process that's currently exec'ing. | * Can't trace a process that's currently exec'ing. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Free a cred structure. Throws away space when ref count gets to 0. | * Free a cred structure. Throws away space when ref count gets to 0. | ||||
*/ | */ | ||||
void | void | ||||
crfree(struct ucred *cr) | crfree(struct ucred *cr) | ||||
{ | { | ||||
KASSERT(cr->cr_ref > 0, ("bad ucred refcount: %d", cr->cr_ref)); | KASSERT(cr->cr_ref > 0, ("%s: bad ucred %p refcount: %d", | ||||
KASSERT(cr->cr_ref != 0xdeadc0de, ("dangling reference to ucred")); | __func__, cr, cr->cr_ref)); | ||||
KASSERT(cr->cr_ref != 0xdeadc0de, | |||||
("%s: dangling reference to ucred %p", __func__, cr)); | |||||
if (refcount_release(&cr->cr_ref)) { | if (refcount_release(&cr->cr_ref)) { | ||||
/* | /* | ||||
* Some callers of crget(), such as nfs_statfs(), | * Some callers of crget(), such as nfs_statfs(), | ||||
* allocate a temporary credential, but don't | * allocate a temporary credential, but don't | ||||
* allocate a uidinfo structure. | * allocate a uidinfo structure. | ||||
*/ | */ | ||||
if (cr->cr_uidinfo != NULL) | if (cr->cr_uidinfo != NULL) | ||||
uifree(cr->cr_uidinfo); | uifree(cr->cr_uidinfo); | ||||
▲ Show 20 Lines • Show All 387 Lines • Show Last 20 Lines |