Repository navigation
fix(profiling): don't disable an alt stack replaced after we installed it - #19026
Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 8 commits intoJul 14, 2026
Conversation
Explain why ThreadAltStack adopts a pre-existing alternate signal stack instead of replacing it: the application, CPython's faulthandler, or libdatadog's crashtracker (which by default creates and owns a larger alt stack) may have installed it, and the destructor must never disable or free an alt stack this object did not allocate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a native gtest for ThreadAltStack: an adopted (pre-existing) alternate signal stack must not be disabled on thread-local cleanup, while a stack this helper allocated is disabled and freed. The adopted-stack case fails without the owns_mapping guard, so it locks in this PR's behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Circular import analysis
|
Codeowners resolved as |
Contributor
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 5984ad6 | Docs | Datadog PR Page | Give us feedback! |
…d it ThreadAltStack's destructor disabled whatever alternate signal stack was installed on the thread whenever it owned a mapping, without checking that the installed stack was still the one it installed. If another component (for example libdatadog crashtracker) replaced the thread's alt stack after we installed ours, teardown would strip that replacement, degrading the other owner's fault handling. Only disable the alt stack when it is still ours (cur.ss_sp == mem); free our own mapping regardless. Adds a regression test (DestructorDoesNotDisableReplacedAltStack) that fails without this guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
taegyunkim
force-pushed
the
taegyunkim/prof-14213-safe-copy-altstack-teardown-guard
branch
from
July 13, 2026 21:03
58623e5 to
a536d62
Compare
taegyunkim
marked this pull request as ready for review
July 14, 2026 14:22
taegyunkim
requested review from
florentinl and
vlad-scherbich
and removed request for
a team
July 14, 2026 14:22
Contributor
|
Taking a look 👀 |
gyuheon0h
approved these changes
Jul 14, 2026
gh-worker-dd-mergequeue-cf854d Bot
pushed a commit
that referenced
this pull request
Jul 14, 2026
## Description The profiling safe-copy helper uses a per-thread alternate signal stack for its `SIGSEGV` and `SIGBUS` handlers. When an alternate stack was already installed by the application, CPython's faulthandler, or crashtracker, `ThreadAltStack` reused it but still disabled it during thread-local teardown. That could leave the original owner without its alternate stack and weaken its fault handling. Track whether `ThreadAltStack` allocated the mapping itself. Teardown now disables and unmaps only profiler-owned stacks, while adopted stacks remain installed for their original owner. The installation failure path also unmaps a profiler allocation when `sigaltstack()` fails. A release note documents the fault-handling fix. ## Testing - Passed locally: `ddtrace/internal/datadog/profiling/build_standalone.sh -- RelWithDebInfo stack_test` - 4/4 native CTests passed - verifies that an adopted alternate stack remains installed after `ThreadAltStack` teardown - verifies that a profiler-owned alternate stack is disabled during teardown - `scripts/lint cformat` ## Risks Low. The change narrows teardown to resources owned by the profiler and does not alter public APIs or configuration. Profiler-owned alternate stacks retain their existing cleanup behavior. ## Additional Notes Stacked out from the CPU timer profiler work, #18724, to keep this native safety fix independently reviewable. Follow-up PR #19026 handles the complementary case where another component replaces a profiler-owned alternate stack after the profiler installs it. [PROF-14213](https://datadoghq.atlassian.net/browse/PROF-14213) [PROF-14213]: https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
Base automatically changed from
taegyunkim/prof-14213-safe-copy-altstack-ownership
to
main
July 14, 2026 16:10
gh-worker-dd-mergequeue-cf854d
Bot
deleted the
taegyunkim/prof-14213-safe-copy-altstack-teardown-guard
branch
July 14, 2026 18:59
vlad-scherbich
pushed a commit
that referenced
this pull request
Jul 14, 2026
## Description The profiling safe-copy helper uses a per-thread alternate signal stack for its `SIGSEGV` and `SIGBUS` handlers. When an alternate stack was already installed by the application, CPython's faulthandler, or crashtracker, `ThreadAltStack` reused it but still disabled it during thread-local teardown. That could leave the original owner without its alternate stack and weaken its fault handling. Track whether `ThreadAltStack` allocated the mapping itself. Teardown now disables and unmaps only profiler-owned stacks, while adopted stacks remain installed for their original owner. The installation failure path also unmaps a profiler allocation when `sigaltstack()` fails. A release note documents the fault-handling fix. ## Testing - Passed locally: `ddtrace/internal/datadog/profiling/build_standalone.sh -- RelWithDebInfo stack_test` - 4/4 native CTests passed - verifies that an adopted alternate stack remains installed after `ThreadAltStack` teardown - verifies that a profiler-owned alternate stack is disabled during teardown - `scripts/lint cformat` ## Risks Low. The change narrows teardown to resources owned by the profiler and does not alter public APIs or configuration. Profiler-owned alternate stacks retain their existing cleanup behavior. ## Additional Notes Stacked out from the CPU timer profiler work, #18724, to keep this native safety fix independently reviewable. Follow-up PR #19026 handles the complementary case where another component replaces a profiler-owned alternate stack after the profiler installs it. [PROF-14213](https://datadoghq.atlassian.net/browse/PROF-14213) [PROF-14213]: https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
Collaborator
|
Nice catch 💯 |
vlad-scherbich
pushed a commit
that referenced
this pull request
Jul 15, 2026
## Description The profiling safe-copy helper uses a per-thread alternate signal stack for its `SIGSEGV` and `SIGBUS` handlers. When an alternate stack was already installed by the application, CPython's faulthandler, or crashtracker, `ThreadAltStack` reused it but still disabled it during thread-local teardown. That could leave the original owner without its alternate stack and weaken its fault handling. Track whether `ThreadAltStack` allocated the mapping itself. Teardown now disables and unmaps only profiler-owned stacks, while adopted stacks remain installed for their original owner. The installation failure path also unmaps a profiler allocation when `sigaltstack()` fails. A release note documents the fault-handling fix. ## Testing - Passed locally: `ddtrace/internal/datadog/profiling/build_standalone.sh -- RelWithDebInfo stack_test` - 4/4 native CTests passed - verifies that an adopted alternate stack remains installed after `ThreadAltStack` teardown - verifies that a profiler-owned alternate stack is disabled during teardown - `scripts/lint cformat` ## Risks Low. The change narrows teardown to resources owned by the profiler and does not alter public APIs or configuration. Profiler-owned alternate stacks retain their existing cleanup behavior. ## Additional Notes Stacked out from the CPU timer profiler work, #18724, to keep this native safety fix independently reviewable. Follow-up PR #19026 handles the complementary case where another component replaces a profiler-owned alternate stack after the profiler installs it. [PROF-14213](https://datadoghq.atlassian.net/browse/PROF-14213) [PROF-14213]: https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
vlad-scherbich
pushed a commit
that referenced
this pull request
Jul 15, 2026
…d it (#19026) ## Description Follow-up to #19018. `ThreadAltStack`'s destructor disabled whatever alternate signal stack was installed on the thread whenever it owned a mapping, without checking that the installed stack was still the one it installed. If another component (for example libdatadog crashtracker) replaced the thread's alt stack after installation, teardown would strip that replacement and weaken the other owner's fault handling. The destructor now disables the alt stack only when it is still ours (`cur.ss_sp == mem`) and frees our own mapping regardless. ## Testing - Native gtest `ThreadAltStackOwnership.DestructorDoesNotDisableReplacedAltStack`, which fails without this guard (verified via `build_standalone.sh -- RelWithDebInfo stack_test`). ## Risks Low. Narrows destructor cleanup to the alternate signal stack the profiler still owns. ## Additional Notes Stacked on #19018 — base branch `taegyunkim/prof-14213-safe-copy-altstack-ownership`. [PROF-14213](https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiY2NiZjFmMTg3MjZiNDBlOGFmMDFjYTBlOTBhZGZhNzIiLCJwIjoiaiJ9) [PROF-14213]: https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #19018.
ThreadAltStack's destructor disabled whatever alternate signal stack was installed on the thread whenever it owned a mapping, without checking that the installed stack was still the one it installed. If another component (for example libdatadog crashtracker) replaced the thread's alt stack after installation, teardown would strip that replacement and weaken the other owner's fault handling. The destructor now disables the alt stack only when it is still ours (cur.ss_sp == mem) and frees our own mapping regardless.Testing
ThreadAltStackOwnership.DestructorDoesNotDisableReplacedAltStack, which fails without this guard (verified viabuild_standalone.sh -- RelWithDebInfo stack_test).Risks
Low. Narrows destructor cleanup to the alternate signal stack the profiler still owns.
Additional Notes
Stacked on #19018 — base branch
taegyunkim/prof-14213-safe-copy-altstack-ownership.PROF-14213