From f971396c6515fc71d3cc8cdfbf60845c1d1e9e03 Mon Sep 17 00:00:00 2001 From: gystemd Date: Tue, 10 Aug 2021 13:06:51 +0200 Subject: fix missing SIGTTOU signal in SetForegroundProcessGroup --- pkg/sentry/kernel/thread_group.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pkg/sentry/kernel/thread_group.go') diff --git a/pkg/sentry/kernel/thread_group.go b/pkg/sentry/kernel/thread_group.go index 2eda15303..6d865b814 100644 --- a/pkg/sentry/kernel/thread_group.go +++ b/pkg/sentry/kernel/thread_group.go @@ -489,11 +489,6 @@ func (tg *ThreadGroup) SetForegroundProcessGroup(tty *TTY, pgid ProcessGroupID) tg.signalHandlers.mu.Lock() defer tg.signalHandlers.mu.Unlock() - // TODO(gvisor.dev/issue/6148): "If tcsetpgrp() is called by a member of a - // background process group in its session, and the calling process is not - // blocking or ignoring SIGTTOU, a SIGTTOU signal is sent to all members of - // this background process group." - // tty must be the controlling terminal. if tg.tty != tty { return -1, linuxerr.ENOTTY @@ -516,6 +511,11 @@ func (tg *ThreadGroup) SetForegroundProcessGroup(tty *TTY, pgid ProcessGroupID) return -1, linuxerr.EPERM } + //if the calling process is a member of a background group, a SIGTTOU signal is sent to all members of this background process group. + if tg.processGroup.session.foreground.id != tg.processGroup.id { + tg.processGroup.SendSignal(&linux.SignalInfo{Signo: int32(linux.SIGTTOU)}) + } + tg.processGroup.session.foreground.id = pgid return 0, nil } -- cgit v1.2.3 From 7c5ab794f140dda031ba015d79892a79dd523d50 Mon Sep 17 00:00:00 2001 From: gystemd Date: Mon, 16 Aug 2021 16:33:57 +0200 Subject: fix sending of SIGTTOU signal in SetForegroundProcessGroup Changed sendSignal to sendSignalLocked because tg.pidns.owner.mu and tg.signalHandlers.mu are already locked in SetForegroundProcess Added a control to verify whether the calling process is ignoring SIGTTOU before sending the signal --- pkg/sentry/kernel/thread_group.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'pkg/sentry/kernel/thread_group.go') diff --git a/pkg/sentry/kernel/thread_group.go b/pkg/sentry/kernel/thread_group.go index 6d865b814..c16b9eb37 100644 --- a/pkg/sentry/kernel/thread_group.go +++ b/pkg/sentry/kernel/thread_group.go @@ -511,9 +511,11 @@ func (tg *ThreadGroup) SetForegroundProcessGroup(tty *TTY, pgid ProcessGroupID) return -1, linuxerr.EPERM } - //if the calling process is a member of a background group, a SIGTTOU signal is sent to all members of this background process group. - if tg.processGroup.session.foreground.id != tg.processGroup.id { - tg.processGroup.SendSignal(&linux.SignalInfo{Signo: int32(linux.SIGTTOU)}) + sa:= tg.signalHandlers.actions[linux.SIGTTOU] + //if the calling process is a member of a background group, a SIGTTOU + //signal is sent to all members of this background process group. + if tg.processGroup.id != tg.processGroup.session.foreground.id && sa.Handler!=linux.SIG_IGN{ + tg.leader.sendSignalLocked(SignalInfoPriv(linux.SIGTTOU),true) } tg.processGroup.session.foreground.id = pgid -- cgit v1.2.3 From 482de52b60d9ac0bc40f264c82c8eb094401a119 Mon Sep 17 00:00:00 2001 From: gystemd Date: Tue, 17 Aug 2021 22:57:39 +0200 Subject: Added a SIGTTOU block check in SetForegroundProcessGroup --- pkg/sentry/kernel/thread_group.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pkg/sentry/kernel/thread_group.go') diff --git a/pkg/sentry/kernel/thread_group.go b/pkg/sentry/kernel/thread_group.go index c16b9eb37..0f741602d 100644 --- a/pkg/sentry/kernel/thread_group.go +++ b/pkg/sentry/kernel/thread_group.go @@ -511,10 +511,13 @@ func (tg *ThreadGroup) SetForegroundProcessGroup(tty *TTY, pgid ProcessGroupID) return -1, linuxerr.EPERM } - sa:= tg.signalHandlers.actions[linux.SIGTTOU] - //if the calling process is a member of a background group, a SIGTTOU - //signal is sent to all members of this background process group. - if tg.processGroup.id != tg.processGroup.session.foreground.id && sa.Handler!=linux.SIG_IGN{ + signalAction:= tg.signalHandlers.actions[linux.SIGTTOU] + // If the calling process is a member of a background group, a SIGTTOU + // signal is sent to all members of this background process group. + // We need also need to check whether it is ignoring or blocking SIGTTOU. + ignored:= signalAction.Handler == linux.SIG_IGN + blocked:= tg.leader.signalMask == linux.SignalSetOf(linux.SIGTTOU) + if tg.processGroup.id != tg.processGroup.session.foreground.id && !ignored && !blocked{ tg.leader.sendSignalLocked(SignalInfoPriv(linux.SIGTTOU),true) } -- cgit v1.2.3