@@ -138,8 +138,7 @@ void CompleteSyscall(pid_t pid, int signo) {
138
138
} // namespace
139
139
140
140
PtraceMonitor::PtraceMonitor (Executor* executor, Policy* policy, Notify* notify)
141
- : MonitorBase(executor, policy, notify),
142
- wait_for_execve_ (executor->enable_sandboxing_pre_execve_) {
141
+ : MonitorBase(executor, policy, notify) {
143
142
if (executor_->limits ()->wall_time_limit () != absl::ZeroDuration ()) {
144
143
auto deadline = absl::Now () + executor_->limits ()->wall_time_limit ();
145
144
deadline_millis_.store (absl::ToUnixMillis (deadline),
@@ -151,13 +150,6 @@ PtraceMonitor::PtraceMonitor(Executor* executor, Policy* policy, Notify* notify)
151
150
absl::GetFlag (FLAGS_sandbox2_monitor_ptrace_use_deadline_manager);
152
151
}
153
152
154
- bool PtraceMonitor::IsActivelyMonitoring () {
155
- // If we're still waiting for execve(), then we allow all syscalls.
156
- return !wait_for_execve_;
157
- }
158
-
159
- void PtraceMonitor::SetActivelyMonitoring () { wait_for_execve_ = false ; }
160
-
161
153
void PtraceMonitor::SetAdditionalResultInfo (std::unique_ptr<Regs> regs) {
162
154
pid_t pid = regs->pid ();
163
155
result_.SetRegs (std::move (regs));
@@ -346,7 +338,7 @@ void PtraceMonitor::Run() {
346
338
// all remaining processes (if there are any) because of the
347
339
// PTRACE_O_EXITKILL ptrace() flag.
348
340
if (ret == process_.main_pid ) {
349
- if (IsActivelyMonitoring ()) {
341
+ if (! wait_for_execveat ()) {
350
342
SetExitStatusCode (Result::OK, WEXITSTATUS (status));
351
343
} else {
352
344
SetExitStatusCode (Result::SETUP_ERROR, Result::FAILED_MONITOR);
@@ -632,7 +624,7 @@ bool PtraceMonitor::InitPtraceAttach() {
632
624
633
625
void PtraceMonitor::ActionProcessSyscall (Regs* regs, const Syscall& syscall) {
634
626
// If the sandboxing is not enabled yet, allow the first __NR_execveat.
635
- if (syscall .nr () == __NR_execveat && ! IsActivelyMonitoring ()) {
627
+ if (syscall .nr () == __NR_execveat && wait_for_execveat ()) {
636
628
VLOG (1 ) << " [PERMITTED/BEFORE_EXECVEAT]: " << " SYSCALL ::: PID: "
637
629
<< regs->pid () << " , PROG: '" << util::GetProgName (regs->pid ())
638
630
<< " ' : " << syscall .GetDescription ();
@@ -783,10 +775,10 @@ void PtraceMonitor::EventPtraceNewProcess(pid_t pid, int event_msg) {
783
775
}
784
776
785
777
void PtraceMonitor::EventPtraceExec (pid_t pid, int event_msg) {
786
- if (! IsActivelyMonitoring ()) {
778
+ if (wait_for_execveat ()) {
787
779
VLOG (1 ) << " PTRACE_EVENT_EXEC seen from PID: " << event_msg
788
780
<< " . SANDBOX ENABLED!" ;
789
- SetActivelyMonitoring ( );
781
+ set_wait_for_execveat ( false );
790
782
} else {
791
783
// ptrace doesn't issue syscall-exit-stops for successful execve/execveat
792
784
// system calls. Check if the monitor wanted to inspect the syscall's return
0 commit comments