From 5f3d16e5b0252bf2a04d66403c3df66b26a33f80 Mon Sep 17 00:00:00 2001 From: Champ-Goblem Date: Mon, 21 Jul 2025 20:36:59 +0100 Subject: [PATCH] sentry: fix panic in TTY `TIOCSPGRP` Fix a nil pointer dereference panic when attempting to call `SetForegroundProcessGroupID` on a TTY that has lost its session leader. Fixes: #11943 Signed-off-by: Champ-Goblem --- pkg/sentry/fsimpl/host/tty.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/sentry/fsimpl/host/tty.go b/pkg/sentry/fsimpl/host/tty.go index ce380b3d54..f58b2174e0 100644 --- a/pkg/sentry/fsimpl/host/tty.go +++ b/pkg/sentry/fsimpl/host/tty.go @@ -164,7 +164,11 @@ func (t *TTYFileDescription) Ioctl(ctx context.Context, io usermem.IO, sysno uin return 0, linuxerr.ENOTTY } - fgpg, err := t.ThreadGroup().ForegroundProcessGroup(t.TTY()) + tg := t.ThreadGroup() + if tg == nil { + return 0, linuxerr.ENOTTY + } + fgpg, err := tg.ForegroundProcessGroup(t.TTY()) if err != nil { return 0, err } @@ -184,7 +188,12 @@ func (t *TTYFileDescription) Ioctl(ctx context.Context, io usermem.IO, sysno uin return 0, err } pgID := kernel.ProcessGroupID(pgIDP) - if err := t.ThreadGroup().SetForegroundProcessGroupID(ctx, t.TTY(), pgID); err != nil { + + tg := t.ThreadGroup() + if tg == nil { + return 0, linuxerr.ENOTTY + } + if err := tg.SetForegroundProcessGroupID(ctx, t.TTY(), pgID); err != nil { return 0, err }