Skip to content

Commit db6142e

Browse files
ret2libcgvisor-bot
authored andcommitted
usertrap: disable syscall patching when ptraced
Workaround the issue in #12266. FUTURE_COPYBARA_INTEGRATE_REVIEW=#12325 from trail-of-forks:ptrace-issue 3c52fed PiperOrigin-RevId: 840404296
1 parent c0bf129 commit db6142e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ 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(gvisor.dev/issue/11649): for a full fix we'd need to roll back
202+
// existing patched syscalls, in case the traced program was patched
203+
// before being traced (e.g. PTRACE_ATTACH on an already running
204+
// process).
205+
if task.Tracer() != nil {
206+
if s.nextTrap > 0 {
207+
ctx.Warningf("LIKELY ERROR: Attached tracer to process with patched syscalls (traps %d)! Systrap is not fully compatible with ptrace/debuggers, program may die unexpectedly soon!", s.nextTrap)
208+
}
209+
return nil
210+
}
211+
196212
s.mu.Lock()
197213
defer s.mu.Unlock()
198214

0 commit comments

Comments
 (0)