Skip to content

Commit c9cb883

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: 840814557
1 parent 9d75d56 commit c9cb883

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-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

test/runner/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,10 @@ func isWarning(line string) bool {
723723
// Caused by properties of the host that runsc doesn't necessarily control.
724724
case strings.Contains(line, "Host limit is lower than recommended"):
725725

726+
// TODO(gvisor.dev/issue/11649): Systrap needs to roll back created
727+
// patches for traced procs.
728+
case strings.Contains(line, "LIKELY ERROR: Attached tracer to process with patched syscalls"):
729+
726730
case *save:
727731
// Ignore these warnings for S/R tests as we try to delete the sandbox
728732
// after the sandbox has exited and before attempting to restore it.

0 commit comments

Comments
 (0)