mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
Kernel: Fix behaviour of PT_TRACEME in ptrace
The behaviour of the PT_TRACEME feature has been broken for some time, this change fixes it. When this ptrace flag is used, the traced process should be paused before exiting execve. We previously were sending the SIGSTOP signal at a stage where interrupts are disabled, and the traced process continued executing normally, without pausing and waiting for the tracer. This change fixes it.
This commit is contained in:
parent
47d7faa998
commit
3b422564f3
2 changed files with 4 additions and 6 deletions
|
@ -1190,10 +1190,6 @@ extern "C" void context_first_init(Thread* from_thread, Thread* to_thread, TrapF
|
||||||
|
|
||||||
Scheduler::enter_current(*from_thread);
|
Scheduler::enter_current(*from_thread);
|
||||||
|
|
||||||
if (to_thread->process().wait_for_tracer_at_next_execve()) {
|
|
||||||
to_thread->send_urgent_signal_to_self(SIGSTOP);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since we got here and don't have Scheduler::context_switch in the
|
// Since we got here and don't have Scheduler::context_switch in the
|
||||||
// call stack (because this is the first time we switched into this
|
// call stack (because this is the first time we switched into this
|
||||||
// context), we need to notify the scheduler so that it can release
|
// context), we need to notify the scheduler so that it can release
|
||||||
|
|
|
@ -269,6 +269,9 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
|
||||||
// and we don't want to deal with faults after this point.
|
// and we don't want to deal with faults after this point.
|
||||||
u32 new_userspace_esp = new_main_thread->make_userspace_stack_for_main_thread(move(arguments), move(environment), move(auxv));
|
u32 new_userspace_esp = new_main_thread->make_userspace_stack_for_main_thread(move(arguments), move(environment), move(auxv));
|
||||||
|
|
||||||
|
if (wait_for_tracer_at_next_execve())
|
||||||
|
Thread::current()->send_urgent_signal_to_self(SIGSTOP);
|
||||||
|
|
||||||
// We enter a critical section here because we don't want to get interrupted between do_exec()
|
// We enter a critical section here because we don't want to get interrupted between do_exec()
|
||||||
// and Processor::assume_context() or the next context switch.
|
// and Processor::assume_context() or the next context switch.
|
||||||
// If we used an InterruptDisabler that sti()'d on exit, we might timer tick'd too soon in exec().
|
// If we used an InterruptDisabler that sti()'d on exit, we might timer tick'd too soon in exec().
|
||||||
|
@ -557,7 +560,7 @@ int Process::sys$execve(Userspace<const Syscall::SC_execve_params*> user_params)
|
||||||
if (params.arguments.length > ARG_MAX || params.environment.length > ARG_MAX)
|
if (params.arguments.length > ARG_MAX || params.environment.length > ARG_MAX)
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
|
|
||||||
if (m_wait_for_tracer_at_next_execve)
|
if (wait_for_tracer_at_next_execve())
|
||||||
Thread::current()->send_urgent_signal_to_self(SIGSTOP);
|
Thread::current()->send_urgent_signal_to_self(SIGSTOP);
|
||||||
|
|
||||||
String path;
|
String path;
|
||||||
|
@ -597,5 +600,4 @@ int Process::sys$execve(Userspace<const Syscall::SC_execve_params*> user_params)
|
||||||
ASSERT(rc < 0); // We should never continue after a successful exec!
|
ASSERT(rc < 0); // We should never continue after a successful exec!
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue