Fix nil-pointer bug in tty.checkChange.

The logic is the same as Linux's __tty_check_change, but we forgot to check the
case that the tty does not have an associated process group.

PiperOrigin-RevId: 693119939
This commit is contained in:
Nicolas Lacasse
2024-11-04 16:01:58 -08:00
committed by gVisor bot
parent c5775dbd0f
commit 892ba3d7f6
2 changed files with 10 additions and 2 deletions
+2 -1
View File
@@ -334,11 +334,12 @@ func (t *TTYFileDescription) checkChange(ctx context.Context, sig linux.Signal)
tg := task.ThreadGroup()
pg := tg.ProcessGroup()
ttyTg := t.tty.ThreadGroup()
// If the session for the task is different than the session for the
// controlling TTY, then the change is allowed. Seems like a bad idea,
// but that's exactly what linux does.
if tg.Session() != t.tty.ThreadGroup().Session() {
if ttyTg == nil || tg.Session() != ttyTg.Session() {
return nil
}
+8 -1
View File
@@ -1667,8 +1667,15 @@ func (l *Loader) signalForegrondProcessGroup(cid string, tgid kernel.ThreadID, s
if tty == nil {
return fmt.Errorf("no TTY attached")
}
pg, _ := tty.ThreadGroup().ForegroundProcessGroup(tty.TTY())
si := &linux.SignalInfo{Signo: signo}
ttyTg := tty.ThreadGroup()
if ttyTg == nil {
// No thread group has been set. Signal the original thread
// group.
log.Warningf("No thread group for container %q and PID %d. Sending signal directly to PID %d.", cid, tgid, tgid)
return l.k.SendExternalSignalThreadGroup(tg, si)
}
pg, _ := ttyTg.ForegroundProcessGroup(tty.TTY())
if pg == nil {
// No foreground process group has been set. Signal the
// original thread group.