mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-18 10:35:55 +00:00
In setpgrp(), don't assume a pgrp won't exist if the provided pgid is the same
as the target process' pid, it may exist if the process forked before leaving the pgrp. Thix fixes a panic that happens when calling setpgid to make a process re-enter the pgrp with the same pgid as its pid if the pgrp still exists.
This commit is contained in:
parent
c97325b0c8
commit
a10d5f02c8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=117214
@ -436,24 +436,25 @@ setpgid(struct thread *td, register struct setpgid_args *uap)
|
|||||||
}
|
}
|
||||||
if (uap->pgid == 0)
|
if (uap->pgid == 0)
|
||||||
uap->pgid = targp->p_pid;
|
uap->pgid = targp->p_pid;
|
||||||
if (uap->pgid == targp->p_pid) {
|
if ((pgrp = pgfind(uap->pgid)) == NULL) {
|
||||||
if (targp->p_pgid == uap->pgid)
|
if (uap->pgid == targp->p_pid) {
|
||||||
goto done;
|
error = enterpgrp(targp, uap->pgid, newpgrp,
|
||||||
error = enterpgrp(targp, uap->pgid, newpgrp, NULL);
|
NULL);
|
||||||
if (error == 0)
|
if (error == 0)
|
||||||
newpgrp = NULL;
|
newpgrp = NULL;
|
||||||
} else {
|
} else
|
||||||
if ((pgrp = pgfind(uap->pgid)) == NULL ||
|
|
||||||
pgrp->pg_session != curp->p_session) {
|
|
||||||
if (pgrp != NULL)
|
|
||||||
PGRP_UNLOCK(pgrp);
|
|
||||||
error = EPERM;
|
error = EPERM;
|
||||||
goto done;
|
} else {
|
||||||
}
|
|
||||||
if (pgrp == targp->p_pgrp) {
|
if (pgrp == targp->p_pgrp) {
|
||||||
PGRP_UNLOCK(pgrp);
|
PGRP_UNLOCK(pgrp);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
if (pgrp->pg_id != targp->p_pid &&
|
||||||
|
pgrp->pg_session != curp->p_session) {
|
||||||
|
PGRP_UNLOCK(pgrp);
|
||||||
|
error = EPERM;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
PGRP_UNLOCK(pgrp);
|
PGRP_UNLOCK(pgrp);
|
||||||
error = enterthispgrp(targp, pgrp);
|
error = enterthispgrp(targp, pgrp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user