Skip to content

Commit cfc5852

Browse files
committed
usertrap: disable syscall patching when ptraced
1 parent 2879878 commit cfc5852

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/sentry/platform/systrap/usertrap/usertrap_amd64.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ func (s *State) PatchSyscall(ctx context.Context, ac *arch.Context64, mm memoryM
193193
return fmt.Errorf("no task found")
194194
}
195195

196+
// Don't patch syscalls when the task is being ptraced (e.g., gdb/lldb debugging).
197+
// Syscall patching causes intermittent segfaults when ptrace is active.
198+
//
199+
// The observed bug: When debugging with gdb, programs randomly segfault at
200+
// garbage addresses (e.g., 0x00007fbcd44c4e48) during startup. The bug is
201+
// intermittent - sometimes the program runs successfully, other times it crashes.
202+
//
203+
// Root cause: Not fully understood. The intermittent nature suggests a
204+
// subtle interaction or timing issue between the patching mechanism
205+
// and ptrace state management.
206+
//
207+
// Skipping patching entirely when ptrace is active avoids whatever the issue is
208+
// and allows normal (unpatched) syscall handling, which works correctly with
209+
// debuggers. Performance cost is acceptable when debugging.
210+
if task.Tracer() != nil {
211+
return nil
212+
}
213+
196214
s.mu.Lock()
197215
defer s.mu.Unlock()
198216

0 commit comments

Comments
 (0)