From 018dc4bb5ca7f67ed5a0acb8d51c9310371a2267 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Wed, 29 Dec 2021 04:11:51 -0800 Subject: [PATCH] Kernel: Add verification promise violations are propagated properly This change adds a thread member variable to track if we have a pending promise violation on a kernel thread. This ensures that all code properly propagates promise violations up to the syscall handler. Suggested-by: Andreas Kling --- Kernel/Process.cpp | 2 ++ Kernel/Syscall.cpp | 7 ++++++- Kernel/Thread.h | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 8496b68a085..3e9c70af938 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -868,6 +868,7 @@ ErrorOr Process::require_no_promises() const if (!has_promises()) return {}; dbgln("Has made a promise"); + Thread::current()->set_promise_violation_pending(true); return EPROMISEVIOLATION; } @@ -880,6 +881,7 @@ ErrorOr Process::require_promise(Pledge promise) return {}; dbgln("Has not pledged {}", to_string(promise)); + Thread::current()->set_promise_violation_pending(true); (void)try_set_coredump_property("pledge_violation"sv, to_string(promise)); return EPROMISEVIOLATION; } diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index ccb7069efdf..763f12df712 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -235,8 +235,13 @@ NEVER_INLINE void syscall_handler(TrapFrame* trap) current_thread->die_if_needed(); // Crash any processes which have commited a promise violation during syscall handling. - if (result.is_error() && result.error().code() == EPROMISEVIOLATION) + if (result.is_error() && result.error().code() == EPROMISEVIOLATION) { + VERIFY(current_thread->is_promise_violation_pending()); + current_thread->set_promise_violation_pending(false); process.crash(SIGABRT, 0); + } else { + VERIFY(!current_thread->is_promise_violation_pending()); + } VERIFY(!g_scheduler_lock.is_locked_by_current_processor()); } diff --git a/Kernel/Thread.h b/Kernel/Thread.h index 131053162bb..479942c7b09 100644 --- a/Kernel/Thread.h +++ b/Kernel/Thread.h @@ -1241,6 +1241,9 @@ public: bool is_profiling_suppressed() const { return m_is_profiling_suppressed; } void set_profiling_suppressed() { m_is_profiling_suppressed = true; } + bool is_promise_violation_pending() const { return m_is_promise_violation_pending; } + void set_promise_violation_pending(bool value) { m_is_promise_violation_pending = value; } + String backtrace(); private: @@ -1390,6 +1393,7 @@ private: bool m_in_block { false }; bool m_is_idle_thread { false }; bool m_is_crashing { false }; + bool m_is_promise_violation_pending { false }; Atomic m_have_any_unmasked_pending_signals { false }; Atomic m_nested_profiler_calls { 0 };