From 54b9a4ec1e7c08a99508d30d150fa17bfe1ee2dc Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Wed, 29 Dec 2021 01:11:45 -0800 Subject: Kernel: Handle promise violations in the syscall handler Previously we would crash the process immediately when a promise violation was found during a syscall. This is error prone, as we don't unwind the stack. This means that in certain cases we can leak resources, like an OwnPtr / RefPtr tracked on the stack. Or even leak a lock acquired in a ScopeLockLocker. To remedy this situation we move the promise violation handling to the syscall handler, right before we return to user space. This allows the code to follow the normal unwind path, and grantees there is no longer any cleanup that needs to occur. The Process::require_promise() and Process::require_no_promises() functions were modified to return ErrorOr so we enforce that the errors are always propagated by the caller. --- Kernel/Syscalls/unlink.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Kernel/Syscalls/unlink.cpp') diff --git a/Kernel/Syscalls/unlink.cpp b/Kernel/Syscalls/unlink.cpp index bc4d016ffd..98526ed9f9 100644 --- a/Kernel/Syscalls/unlink.cpp +++ b/Kernel/Syscalls/unlink.cpp @@ -13,7 +13,7 @@ namespace Kernel { ErrorOr Process::sys$unlink(Userspace user_path, size_t path_length) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) - require_promise(Pledge::cpath); + TRY(require_promise(Pledge::cpath)); auto path = TRY(get_syscall_path_argument(user_path, path_length)); TRY(VirtualFileSystem::the().unlink(path->view(), current_directory())); return 0; -- cgit v1.2.3