Skip to content

Commit

Permalink
Fix nil-pointer bug in tty.checkChange.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nlacasse authored and gvisor-bot committed Nov 5, 2024
1 parent c5775db commit 892ba3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/sentry/fsimpl/host/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion runsc/boot/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 892ba3d

Please sign in to comment.