diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-12-29 01:11:45 -0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-29 18:08:15 +0100 |
commit | 54b9a4ec1e7c08a99508d30d150fa17bfe1ee2dc (patch) | |
tree | 6e8958e82202e3ad0f3ae3fbbf48e8662e735ad2 /Kernel/Syscalls/hostname.cpp | |
parent | c444a3fc9e12eda8f4a391bce48fa78a7b2d2e4b (diff) | |
download | serenity-54b9a4ec1e7c08a99508d30d150fa17bfe1ee2dc.zip |
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.
Diffstat (limited to 'Kernel/Syscalls/hostname.cpp')
-rw-r--r-- | Kernel/Syscalls/hostname.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Kernel/Syscalls/hostname.cpp b/Kernel/Syscalls/hostname.cpp index ee087923fa..1d84189087 100644 --- a/Kernel/Syscalls/hostname.cpp +++ b/Kernel/Syscalls/hostname.cpp @@ -11,7 +11,7 @@ namespace Kernel { ErrorOr<FlatPtr> Process::sys$gethostname(Userspace<char*> buffer, size_t size) { VERIFY_NO_PROCESS_BIG_LOCK(this) - require_promise(Pledge::stdio); + TRY(require_promise(Pledge::stdio)); if (size > NumericLimits<ssize_t>::max()) return EINVAL; return hostname().with_shared([&](const auto& name) -> ErrorOr<FlatPtr> { @@ -25,7 +25,7 @@ ErrorOr<FlatPtr> Process::sys$gethostname(Userspace<char*> buffer, size_t size) ErrorOr<FlatPtr> Process::sys$sethostname(Userspace<const char*> buffer, size_t length) { VERIFY_NO_PROCESS_BIG_LOCK(this) - require_no_promises(); + TRY(require_no_promises()); if (!is_superuser()) return EPERM; |