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 <kling@serenityos.org>
This commit is contained in:
Brian Gianforcaro 2021-12-29 04:11:51 -08:00 committed by Andreas Kling
parent 54b9a4ec1e
commit 018dc4bb5c
Notes: sideshowbarker 2024-07-17 21:58:20 +09:00
3 changed files with 12 additions and 1 deletions

View file

@ -868,6 +868,7 @@ ErrorOr<void> Process::require_no_promises() const
if (!has_promises()) if (!has_promises())
return {}; return {};
dbgln("Has made a promise"); dbgln("Has made a promise");
Thread::current()->set_promise_violation_pending(true);
return EPROMISEVIOLATION; return EPROMISEVIOLATION;
} }
@ -880,6 +881,7 @@ ErrorOr<void> Process::require_promise(Pledge promise)
return {}; return {};
dbgln("Has not pledged {}", to_string(promise)); 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)); (void)try_set_coredump_property("pledge_violation"sv, to_string(promise));
return EPROMISEVIOLATION; return EPROMISEVIOLATION;
} }

View file

@ -235,8 +235,13 @@ NEVER_INLINE void syscall_handler(TrapFrame* trap)
current_thread->die_if_needed(); current_thread->die_if_needed();
// Crash any processes which have commited a promise violation during syscall handling. // 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); process.crash(SIGABRT, 0);
} else {
VERIFY(!current_thread->is_promise_violation_pending());
}
VERIFY(!g_scheduler_lock.is_locked_by_current_processor()); VERIFY(!g_scheduler_lock.is_locked_by_current_processor());
} }

View file

@ -1241,6 +1241,9 @@ public:
bool is_profiling_suppressed() const { return m_is_profiling_suppressed; } bool is_profiling_suppressed() const { return m_is_profiling_suppressed; }
void set_profiling_suppressed() { m_is_profiling_suppressed = true; } 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(); String backtrace();
private: private:
@ -1390,6 +1393,7 @@ private:
bool m_in_block { false }; bool m_in_block { false };
bool m_is_idle_thread { false }; bool m_is_idle_thread { false };
bool m_is_crashing { false }; bool m_is_crashing { false };
bool m_is_promise_violation_pending { false };
Atomic<bool> m_have_any_unmasked_pending_signals { false }; Atomic<bool> m_have_any_unmasked_pending_signals { false };
Atomic<u32> m_nested_profiler_calls { 0 }; Atomic<u32> m_nested_profiler_calls { 0 };