mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:57:34 +00:00
Kernel: Wrap much of sys$execve() in a block scope
Since we don't return normally from this function, let's make it a little extra difficult to accidentally leak something by leaving it on the stack in this function.
This commit is contained in:
parent
0e72b04e7d
commit
0e08763483
1 changed files with 38 additions and 33 deletions
|
@ -838,8 +838,14 @@ ErrorOr<FlatPtr> Process::sys$execve(Userspace<const Syscall::SC_execve_params*>
|
||||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this);
|
||||||
TRY(require_promise(Pledge::exec));
|
TRY(require_promise(Pledge::exec));
|
||||||
|
|
||||||
|
Thread* new_main_thread = nullptr;
|
||||||
|
u32 prev_flags = 0;
|
||||||
|
|
||||||
// NOTE: Be extremely careful with allocating any kernel memory in this function.
|
// NOTE: Be extremely careful with allocating any kernel memory in this function.
|
||||||
// On success, the kernel stack will be lost.
|
// On success, the kernel stack will be lost.
|
||||||
|
// The explicit block scope below is specifically placed to minimize the number
|
||||||
|
// of stack locals in this function.
|
||||||
|
{
|
||||||
auto params = TRY(copy_typed_from_user(user_params));
|
auto params = TRY(copy_typed_from_user(user_params));
|
||||||
|
|
||||||
if (params.arguments.length > ARG_MAX || params.environment.length > ARG_MAX)
|
if (params.arguments.length > ARG_MAX || params.environment.length > ARG_MAX)
|
||||||
|
@ -870,9 +876,8 @@ ErrorOr<FlatPtr> Process::sys$execve(Userspace<const Syscall::SC_execve_params*>
|
||||||
NonnullOwnPtrVector<KString> environment;
|
NonnullOwnPtrVector<KString> environment;
|
||||||
TRY(copy_user_strings(params.environment, environment));
|
TRY(copy_user_strings(params.environment, environment));
|
||||||
|
|
||||||
Thread* new_main_thread = nullptr;
|
|
||||||
u32 prev_flags = 0;
|
|
||||||
TRY(exec(move(path), move(arguments), move(environment), new_main_thread, prev_flags));
|
TRY(exec(move(path), move(arguments), move(environment), new_main_thread, prev_flags));
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: If we're here, the exec has succeeded and we've got a new executable image!
|
// NOTE: If we're here, the exec has succeeded and we've got a new executable image!
|
||||||
// We will not return normally from this function. Instead, the next time we
|
// We will not return normally from this function. Instead, the next time we
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue