1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +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

@ -13,7 +13,7 @@ namespace Kernel {
ErrorOr<FlatPtr> Process::sys$getsid(pid_t pid)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
require_promise(Pledge::proc);
TRY(require_promise(Pledge::proc));
if (pid == 0)
return sid().value();
auto process = Process::from_pid(pid);
@ -27,7 +27,7 @@ ErrorOr<FlatPtr> Process::sys$getsid(pid_t pid)
ErrorOr<FlatPtr> Process::sys$setsid()
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
require_promise(Pledge::proc);
TRY(require_promise(Pledge::proc));
InterruptDisabler disabler;
bool found_process_with_same_pgid_as_my_pid = false;
Process::for_each_in_pgrp(pid().value(), [&](auto&) {
@ -48,7 +48,7 @@ ErrorOr<FlatPtr> Process::sys$setsid()
ErrorOr<FlatPtr> Process::sys$getpgid(pid_t pid)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
require_promise(Pledge::proc);
TRY(require_promise(Pledge::proc));
if (pid == 0)
return pgid().value();
auto process = Process::from_pid(pid);
@ -60,7 +60,7 @@ ErrorOr<FlatPtr> Process::sys$getpgid(pid_t pid)
ErrorOr<FlatPtr> Process::sys$getpgrp()
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
require_promise(Pledge::stdio);
TRY(require_promise(Pledge::stdio));
return pgid().value();
}
@ -80,7 +80,7 @@ SessionID Process::get_sid_from_pgid(ProcessGroupID pgid)
ErrorOr<FlatPtr> Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
require_promise(Pledge::proc);
TRY(require_promise(Pledge::proc));
ProcessID pid = specified_pid ? ProcessID(specified_pid) : this->pid();
if (specified_pgid < 0) {
// The value of the pgid argument is less than 0, or is not a value supported by the implementation.