Skip to content

Commit 62cb91e

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

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

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

196+
// Skip syscall patching when the task is being ptraced, because
197+
// single-stepping and other debugger features are incompatible with
198+
// the "syshandler" routine used to handle patched syscalls (see
199+
// syshandler_amd64.S). This incompatibility can result in inconsistent
200+
// process states and failures (e.g. SIGSEGV).
201+
// TODO: for a full fix we'd need to roll back existing patched
202+
// syscalls, in case the traced program was patched before being
203+
// traced (e.g. PTRACE_ATTACH on an already running process).
204+
if task.Tracer() != nil {
205+
return nil
206+
}
207+
196208
s.mu.Lock()
197209
defer s.mu.Unlock()
198210

0 commit comments

Comments
 (0)