From a6b5065d94fa9a5eae6495c8e3fd97e38c0a45ee Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 30 Jan 2022 14:17:46 +0100 Subject: [PATCH] Kernel: Simplify x86 IOPL sanity check Move this architecture-specific sanity check (IOPL must be 0) out of Scheduler and into the x86 enter_thread_context(). Also do this for every thread and not just userspace ones. --- Kernel/Arch/x86/common/Processor.cpp | 6 ++++-- Kernel/Scheduler.cpp | 8 -------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index ab2875aa6c..5bbc8901f1 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -1312,6 +1312,10 @@ extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread) auto& from_regs = from_thread->regs(); auto& to_regs = to_thread->regs(); + // NOTE: IOPL should never be non-zero in any situation, so let's panic immediately + // instead of carrying on with elevated I/O privileges. + VERIFY(get_iopl_from_eflags(to_regs.flags()) == 0); + if (has_fxsr) asm volatile("fxsave %0" : "=m"(from_thread->fpu_state())); @@ -1358,8 +1362,6 @@ extern "C" void enter_thread_context(Thread* from_thread, Thread* to_thread) asm volatile("fxrstor %0" ::"m"(to_thread->fpu_state())); else asm volatile("frstor %0" ::"m"(to_thread->fpu_state())); - - // TODO: ioperm? } extern "C" FlatPtr do_init_context(Thread* thread, u32 flags) diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp index 35d3aca36c..9a27203e9a 100644 --- a/Kernel/Scheduler.cpp +++ b/Kernel/Scheduler.cpp @@ -310,14 +310,6 @@ bool Scheduler::context_switch(Thread* thread) enter_current(*from_thread); VERIFY(thread == Thread::current()); - if (thread->process().is_user_process() && thread->previous_mode() != Thread::PreviousMode::KernelMode && thread->current_trap()) { - auto& regs = thread->get_register_dump_from_stack(); - auto iopl = get_iopl_from_eflags(regs.flags()); - if (iopl != 0) { - PANIC("Switched to thread {} with non-zero IOPL={}", Thread::current()->tid().value(), iopl); - } - } - return true; }