Submit #2574 ยป 0002-kernel-change-proc_token-by-per-process-token-to-pro.patch
sys/kern/kern_prot.c | ||
---|---|---|
/*
|
||
* Get process group ID; note that POSIX getpgrp takes no parameter
|
||
*
|
||
* MPSAFE XXX pgrp
|
||
* MPSAFE
|
||
*/
|
||
int
|
||
sys_getpgrp(struct getpgrp_args *uap)
|
||
{
|
||
struct proc *p = curproc;
|
||
/*
|
||
* hold p_token to protect p_pgrp, because p_pgrp can be NULL
|
||
* if we race setpgid
|
||
*/
|
||
lwkt_gettoken_shared(&p->p_token);
|
||
uap->sysmsg_result = p->p_pgrp->pg_id;
|
||
lwkt_reltoken(&p->p_token);
|
||
return (0);
|
||
}
|
||
... | ... | |
if (pt == NULL)
|
||
error = ESRCH;
|
||
}
|
||
/* XXX MPSAFE on pgrp? */
|
||
if (error == 0)
|
||
if (error == 0) {
|
||
lwkt_gettoken_shared(&pt->p_token);
|
||
uap->sysmsg_result = pt->p_pgrp->pg_id;
|
||
lwkt_reltoken(&pt->p_token);
|
||
}
|
||
if (pt)
|
||
PRELE(pt);
|
||
return (error);
|
||
... | ... | |
uid_t uid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
/*
|
||
... | ... | |
}
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
uid_t euid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
euid = uap->euid;
|
||
if (euid != cr->cr_ruid && /* allow seteuid(getuid()) */
|
||
... | ... | |
change_euid(euid);
|
||
setsugid();
|
||
}
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (0);
|
||
}
|
||
... | ... | |
gid_t gid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
/*
|
||
... | ... | |
}
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
gid_t egid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
egid = uap->egid;
|
||
if (egid != cr->cr_rgid && /* allow setegid(getgid()) */
|
||
... | ... | |
}
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
u_int ngrp;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
if ((error = priv_check_cred(cr, PRIV_CRED_SETGROUPS, 0)))
|
||
... | ... | |
setsugid();
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
uid_t ruid, euid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
ruid = uap->ruid;
|
||
... | ... | |
}
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
gid_t rgid, egid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
rgid = uap->rgid;
|
||
... | ... | |
}
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
uid_t ruid, euid, suid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
ruid = uap->ruid;
|
||
... | ... | |
}
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
gid_t rgid, egid, sgid;
|
||
int error;
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken(&p->p_token);
|
||
cr = p->p_ucred;
|
||
rgid = uap->rgid;
|
||
egid = uap->egid;
|
||
... | ... | |
}
|
||
error = 0;
|
||
done:
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
struct proc *p = curproc;
|
||
struct ucred *cr;
|
||
int error1 = 0, error2 = 0, error3 = 0;
|
||
|
||
lwkt_gettoken_shared(&p->p_token);
|
||
cr = crhold(p->p_ucred);
|
||
lwkt_reltoken(&p->p_token);
|
||
lwkt_gettoken(&proc_token);
|
||
cr = p->p_ucred;
|
||
if (uap->ruid)
|
||
error1 = copyout((caddr_t)&cr->cr_ruid,
|
||
(caddr_t)uap->ruid, sizeof(cr->cr_ruid));
|
||
... | ... | |
if (uap->suid)
|
||
error3 = copyout((caddr_t)&cr->cr_svuid,
|
||
(caddr_t)uap->suid, sizeof(cr->cr_svuid));
|
||
lwkt_reltoken(&proc_token);
|
||
crfree(cr);
|
||
return error1 ? error1 : (error2 ? error2 : error3);
|
||
}
|
||
... | ... | |
sys_getresgid(struct getresgid_args *uap)
|
||
{
|
||
struct ucred *cr;
|
||
struct proc *p = curproc;
|
||
int error1 = 0, error2 = 0, error3 = 0;
|
||
cr = curthread->td_ucred;
|
||
lwkt_gettoken_shared(&p->p_token);
|
||
cr = p->p_ucred;
|
||
crhold(cr);
|
||
lwkt_reltoken(&p->p_token);
|
||
if (uap->rgid)
|
||
error1 = copyout(&cr->cr_rgid, uap->rgid,
|
||
sizeof(cr->cr_rgid));
|
||
... | ... | |
if (uap->sgid)
|
||
error3 = copyout(&cr->cr_svgid, uap->sgid,
|
||
sizeof(cr->cr_svgid));
|
||
crfree(cr);
|
||
return error1 ? error1 : (error2 ? error2 : error3);
|
||
}
|
||
... | ... | |
if (uap->namelen > MAXLOGNAME) /* namelen is unsigned */
|
||
uap->namelen = MAXLOGNAME;
|
||
bzero(buf, sizeof(buf));
|
||
lwkt_gettoken(&proc_token);
|
||
lwkt_gettoken_shared(&p->p_token);
|
||
bcopy(p->p_pgrp->pg_session->s_login, buf, uap->namelen);
|
||
lwkt_reltoken(&proc_token);
|
||
lwkt_reltoken(&p->p_token);
|
||
error = copyout(buf, uap->namebuf, uap->namelen);
|
||
return (error);
|
||
... | ... | |
int
|
||
sys_setlogin(struct setlogin_args *uap)
|
||
{
|
||
struct thread *td = curthread;
|
||
struct proc *p;
|
||
struct proc *p = curproc;
|
||
struct ucred *cred;
|
||
char buf[MAXLOGNAME];
|
||
int error;
|
||
cred = td->td_ucred;
|
||
p = td->td_proc;
|
||
lwkt_gettoken(&p->p_token);
|
||
cred = p->p_ucred;
|
||
if ((error = priv_check_cred(cred, PRIV_PROC_SETLOGIN, 0)))
|
||
return (error);
|
||
goto done;
|
||
bzero(buf, sizeof(buf));
|
||
error = copyinstr(uap->namebuf, buf, sizeof(buf), NULL);
|
||
if (error == ENAMETOOLONG)
|
||
error = EINVAL;
|
||
if (error == 0) {
|
||
lwkt_gettoken(&proc_token);
|
||
memcpy(p->p_pgrp->pg_session->s_login, buf, sizeof(buf));
|
||
lwkt_reltoken(&proc_token);
|
||
}
|
||
done:
|
||
lwkt_reltoken(&p->p_token);
|
||
return (error);
|
||
}
|
||
... | ... | |
*
|
||
* The per-uid process count for this process is transfered from
|
||
* the old uid to the new uid.
|
||
*
|
||
* Requires curproc->p_token to be held.
|
||
*/
|
||
struct ucred *
|
||
change_ruid(uid_t ruid)
|