From 892ba3d7f6524e5abe25a2724d95b0efb3765765 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Mon, 4 Nov 2024 15:58:09 -0800 Subject: [PATCH] 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 --- pkg/sentry/fsimpl/host/tty.go | 3 ++- runsc/boot/loader.go | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/sentry/fsimpl/host/tty.go b/pkg/sentry/fsimpl/host/tty.go index 73ba03ab9..282266c8b 100644 --- a/pkg/sentry/fsimpl/host/tty.go +++ b/pkg/sentry/fsimpl/host/tty.go @@ -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 } diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go index 5ba8f3ff2..f2fe33d23 100644 --- a/runsc/boot/loader.go +++ b/runsc/boot/loader.go @@ -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.