diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2019-02-14 15:46:25 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-02-14 15:47:31 -0800 |
commit | 0a41ea72c1f70916bdbb68d9fdfa6c438e28b5b2 (patch) | |
tree | ce2fdd6bb92036481ea2a44fb091b355b9bfae77 /pkg/sentry/control | |
parent | d60ce17a21a28ab32607b195ae42692442322ff8 (diff) |
Don't allow writing or reading to TTY unless process group is in foreground.
If a background process tries to read from a TTY, linux sends it a SIGTTIN
unless the signal is blocked or ignored, or the process group is an orphan, in
which case the syscall returns EIO.
See drivers/tty/n_tty.c:n_tty_read()=>job_control().
If a background process tries to write a TTY, set the termios, or set the
foreground process group, linux then sends a SIGTTOU. If the signal is ignored
or blocked, linux allows the write. If the process group is an orphan, the
syscall returns EIO.
See drivers/tty/tty_io.c:tty_check_change().
PiperOrigin-RevId: 234044367
Change-Id: I009461352ac4f3f11c5d42c43ac36bb0caa580f9
Diffstat (limited to 'pkg/sentry/control')
-rw-r--r-- | pkg/sentry/control/proc.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/pkg/sentry/control/proc.go b/pkg/sentry/control/proc.go index 923399fb2..e848def14 100644 --- a/pkg/sentry/control/proc.go +++ b/pkg/sentry/control/proc.go @@ -222,10 +222,18 @@ func (proc *Proc) execAsync(args *ExecArgs) (*kernel.ThreadGroup, kernel.ThreadI return nil, 0, nil, err } - if ttyFile == nil { - return tg, tid, nil, nil + var ttyFileOps *host.TTYFileOperations + if ttyFile != nil { + // Set the foreground process group on the TTY before starting + // the process. + ttyFileOps = ttyFile.FileOperations.(*host.TTYFileOperations) + ttyFileOps.InitForegroundProcessGroup(tg.ProcessGroup()) } - return tg, tid, ttyFile.FileOperations.(*host.TTYFileOperations), nil + + // Start the newly created process. + proc.Kernel.StartProcess(tg) + + return tg, tid, ttyFileOps, nil } // PsArgs is the set of arguments to ps. |