From 83e32788d54b926a1ab9403998d715a45ae861db Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Aug 2020 21:25:44 +0200 Subject: 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. --- Kernel/TTY/TTY.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Kernel/TTY') 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 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)) size = m_input_buffer.size(); @@ -85,6 +90,11 @@ KResultOr TTY::read(FileDescription&, size_t, u8* buffer, size_t size) KResultOr 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; } -- cgit v1.2.3