Check if ThreadGroup exists before executing JoinProcessGroup.

The caller of JoinProcessGroup (in linux.Setpgid) cannot guarantee that the
ThreadGroup used to make the call is valid before acquiring the TaskSet mutex.
This is essentially the same same fix as in cl/381351069

It is still possible for setpgid to race with a single task exiting (i.e. a task
exits in the middle of a setpgid call), but this will not cause problems since
JoinProcessGroup operates on ThreadGroups. As long as the target ThreadGroup
remains valid throughout the call we are ok.

PiperOrigin-RevId: 479671524
This commit is contained in:
Konstantin Bogomolov
2022-10-07 14:42:23 -07:00
committed by gVisor bot
parent 39ac7df1b7
commit 36ddd3050c
+5
View File
@@ -440,6 +440,11 @@ func (tg *ThreadGroup) JoinProcessGroup(pidns *PIDNamespace, pgid ProcessGroupID
pidns.owner.mu.Lock()
defer pidns.owner.mu.Unlock()
// Check whether the process still exists or not.
if _, ok := pidns.tgids[tg]; !ok {
return linuxerr.ESRCH
}
// Lookup the ProcessGroup.
pg := pidns.processGroups[pgid]
if pg == nil {