diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-04 21:25:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-04 21:25:44 +0200 |
commit | 83e32788d54b926a1ab9403998d715a45ae861db (patch) | |
tree | 6b48fce988dc6a2b24bd11a1b034d8c1ae54a0b0 /Kernel/TTY | |
parent | 771751258ea17524c582de6ca8b4ca3e3d02808a (diff) | |
download | serenity-83e32788d54b926a1ab9403998d715a45ae861db.zip |
Kernel: Send SIGTTIN and SIGTTOU signals on background TTY read/write
A process that is not in the foreground process group of a TTY should
not be allowed to read/write that TTY. Instead, we now send either a
SIGTTIN (on read) or SIGTTOU (on write) signal to the process, and fail
the I/O syscall with EINTR.
Fixes #205.
Diffstat (limited to 'Kernel/TTY')
-rw-r--r-- | Kernel/TTY/TTY.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index d40c461087..65c4c247c6 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -54,6 +54,11 @@ void TTY::set_default_termios() KResultOr<size_t> TTY::read(FileDescription&, size_t, u8* buffer, size_t size) { + if (Process::current()->pgid() != pgid()) { + Process::current()->send_signal(SIGTTIN, nullptr); + return KResult(-EINTR); + } + if (m_input_buffer.size() < static_cast<size_t>(size)) size = m_input_buffer.size(); @@ -85,6 +90,11 @@ KResultOr<size_t> TTY::read(FileDescription&, size_t, u8* buffer, size_t size) KResultOr<size_t> TTY::write(FileDescription&, size_t, const u8* buffer, size_t size) { + if (Process::current()->pgid() != pgid()) { + Process::current()->send_signal(SIGTTOU, nullptr); + return KResult(-EINTR); + } + on_tty_write(buffer, size); return size; } |