From 23a8e1b78063c0276d987e835434700267b9c8f8 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 3 Jul 2025 19:59:45 -0400 Subject: kernel: Ensure mutually exclusive console access If multiple processes try to write to the console, a race condition of sorts may occur. Similarly, if multiple processes try to read from the console and contend with the console input buffer. One process may steal keys from the other. Prevent this by implementing a mutex within the console descriptor. Each time a process reads or writes the console, it attaches itself. Any other processes attempting to read or write the console while another is attached will be yielded to the scheduler until the resource is free. Signed-off-by: Ian Moffett --- sys/kern/kern_sched.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sys/kern/kern_sched.c') diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index ec5592e..774ba71 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -221,6 +222,7 @@ sched_switch(struct trapframe *tf) ci = this_cpu(); td = ci->curtd; + cons_detach(); if (td != NULL) { if (td->pid == 0) -- cgit v1.2.3