Proxy access to terminal

Status: Done

Rather than giving the sandboxed process the file descriptor for the user's terminal device, pola-run should give the sandboxed process a private file descriptor, and proxy access.

Motivations:

This will initially only be implemented in the Python version of pola-run. pola-shell and the C pola-run will be removed from the Debian package since they are vulnerable; they may be fixed in a later release.

See TerminalAccess for a general discussion of tty devices.

Stage 1

Grant the sandboxed process pipe FDs or socket FDs.

Note that, as a side effect, this will cause programs that check whether they are running under a terminal (such as readline in bash) to behave differently.

Tasks

There is a potential race condition: When the sandboxed process exits, we must check for any remaining data buffered on the pipe/socket, otherwise the process's output could be cut short. This is necessary because pipes are asynchronous and not synchronised with the results of wait(). NB. Ideally we need to know the size of the pipe's in-kernel buffer to do this properly.

Questions

Should terminal access be revoked when the child process exits? (Note that it may have forked further processes that continue running in the background.)

There are three issues here:

Does it matter if the server process continues to forward terminal access after the job has gone into the background? Since it is no longer the current job on the terminal, it will not be able to read from the FD, but since it does select() and not read() on the FD it should not get stopped by a SIGTTIN signal. (The sandboxed process will block if it tries to read from the proxy FD but it also will not be stopped by SIGTTIN.)

How should EOF be handled? Pressing Ctrl-D at the terminal gives the appearance of end-of-file to the reading process (read() returns an empty string), yet the process can still read from the terminal after that (including reading further EOFs!). With sockets and pipes, an end-of-file condition is final, and can only be signalled by closing the FD of the other end.

Not being implemented

Conditional proxying

If stdout and stderr are the same tty file descriptor (the common case), we must replace them with the same proxy FD, to ensure synchronised output.

For any of stdin, stdout and stderr that are file FDs or pipe FDs, we should not proxy access. What should happen with FDs for unusual devices?

If stdin, stdout or stderr refer to two different tty FDs, this would be an unusual case. What should happen? The kernel might not allow a process to write to an FD of a tty other than its controlling tty.

Stage 2

The second stage would be to present the terminal to the sandboxed program as a tty device. i.e. Create a private pty device. Switch the user's tty to raw mode. See ssh for how this can be done. Note that window size information should be copied across.

Story9 (last edited 2007-05-13 18:29:33 by MarkSeaborn)