10000 systrap: Initialize stub threads in the same way on both x86 and ARM. by copybara-service[bot] · Pull Request #11745 · google/gvisor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

systrap: Initialize stub threads in the same way on both x86 and ARM. #11745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025

Conversation

copybara-service[bot]
Copy link

systrap: Initialize stub threads in the same way on both x86 and ARM.

Initializing threads via a custom Systrap entrypoint (as was done on x86 prior
to this CL) is incompatible with debuggers, because they set the single-step
flag. If a brand new stub thread managed to pick up an already existing context
with this flag set, it would immediately invoke the sighandler upon restoring
RFLAGS, which would corrupt the stack and instruction pointers.

@copybara-service copybara-service bot added the exported Issue was exported automatically label May 19, 2025
@avagin avagin requested a review from Copilot May 20, 2025 20:39
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR unifies stub thread initialization on x86 and ARM by removing the custom entrypoint stub and using a fake TGKILL event to enter the shared sighandler, avoiding RFLAGS single-step corruption under debuggers.

  • Hoist and unify context/FS-base initialization in the AMD64 signal handler, removing __export_start.
  • Remove archSpecificSysmsgThreadInit helpers and inline the TGKILL stop event in Go.
  • Drop manual RIP/RSP assignments in x86 register setup.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/sentry/platform/systrap/sysmsg/sighandler_amd64.c Hoisted declarations, handled THREAD_STATE_INITIALIZING via init_new_thread() and goto init, removed __export_start stub.
pkg/sentry/platform/systrap/subprocess_arm64.go Deleted the ARM helper archSpecificSysmsgThreadInit.
pkg/sentry/platform/systrap/subprocess_amd64.go Removed empty archSpecificSysmsgThreadInit and stub RIP/RSP setup.
pkg/sentry/platform/systrap/subprocess.go Inlined TGKILL fake event before SIGCONT, replaced helper call.
Comments suppressed due to low confidence (3)

pkg/sentry/platform/systrap/subprocess_amd64.go:213

  • Removing the RIP and RSP assignments means the new thread’s instruction pointer and stack aren’t set to the sighandler stub; re-introduce these assignments or ensure an alternative startup address is configured.
regs.PtraceRegs.Rip = uint64(stubSysmsgStart + uintptr(sysmsg.Sighandler_blob_offset____export_start))

pkg/sentry/platform/systrap/subprocess.go:1162

  • [nitpick] The panic message is generic; include context such as the target thread ID to aid debugging (e.g., panic(fmt.Sprintf("tgkill(%d, %d) failed: %v", ...))).
panic(fmt.Sprintf("tkill failed: %v", e))

pkg/sentry/platform/systrap/subprocess.go:1161

  • [nitpick] This new fake TGKILL sequence isn’t covered by existing tests; consider adding an integration or unit test to verify the subprocess enters the sighandler as expected on both architectures.
if e := hostsyscall.RawSyscallErrno(unix.SYS_TGKILL, uintptr(sysThread.thread.tgid), uintptr(sysThread.thread.tid), uintptr(unix.SIGSEGV)); e != 0 {

@@ -331,6 +334,8 @@ void __export_sighandler(int signo, siginfo_t *siginfo, void *_ucontext) {
}

atomic_store(&ctx->fpstate_changed, 0);

init:
Copy link
Preview
Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The label init is very generic and may collide or confuse readers; consider renaming it to something more descriptive like restore_context.

Suggested change
init:
restore_context:

Copilot uses AI. Check for mistakes.

8000
@copybara-service copybara-service bot force-pushed the test/cl760810233 branch 2 times, most recently from 652d78a to 17b4bde Compare May 20, 2025 22:01
Initializing threads via a custom Systrap entrypoint (as was done on x86 prior
to this CL) is incompatible with debuggers, because they set the single-step
flag. If a brand new stub thread managed to pick up an already existing context
with this flag set, it would immediately invoke the sighandler upon restoring
RFLAGS, which would corrupt the stack and instruction pointers.

PiperOrigin-RevId: 761250233
@copybara-service copybara-service bot merged commit 53489c2 into master May 20, 2025
1 check was pending
@copybara-service copybara-service bot deleted the test/cl760810233 branch May 20, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exported Issue was exported automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0