1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 20:05:07 +00:00

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<void> so we enforce that
the errors are always propagated by the caller.
This commit is contained in:
Brian Gianforcaro 2021-12-29 01:11:45 -08:00 committed by Andreas Kling
parent c444a3fc9e
commit 54b9a4ec1e
66 changed files with 156 additions and 148 deletions

View file

@ -12,7 +12,7 @@ namespace Kernel {
ErrorOr<FlatPtr> Process::sys$get_dir_entries(int fd, Userspace<void*> user_buffer, size_t user_size)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
require_promise(Pledge::stdio);
TRY(require_promise(Pledge::stdio));
if (user_size > NumericLimits<ssize_t>::max())
return EINVAL;
auto description = TRY(fds().open_file_description(fd));