Unpoison fiber stack before each resume to fix ASan false positives#100281
Merged
alexey-milovidov merged 1 commit intomasterfrom Mar 21, 2026
Merged
Unpoison fiber stack before each resume to fix ASan false positives#100281alexey-milovidov merged 1 commit intomasterfrom
alexey-milovidov merged 1 commit intomasterfrom
Conversation
ASan's use-after-scope detection poisons real stack memory when local variables go out of scope. On fiber stacks managed by `makecontext`/`swapcontext`, this poisoning persists across context switches (yield/resume), causing false positives when the same stack addresses are reused by new frames in subsequent fiber resumes - notably during exception unwinding in `_Unwind_Resume`. The fix: call `ASAN_UNPOISON_MEMORY_REGION` on the entire fiber stack before each `Fiber::resume`, clearing any stale scope poisoning. This is complementary to the `__sanitizer_start_switch_fiber` / `__sanitizer_finish_switch_fiber` annotations in boost::context, which only manage the fake stack (for use-after-return), not real stack poisoning (for use-after-scope). See google/sanitizers#189 Example: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100041&sha=e3d5fc0647f84f316414376a48aa9ffbf8565b07&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [1f870bb] Summary: ✅ AI ReviewSummaryThis PR addresses ASan false positives on fiber stacks by unpoisoning the allocated fiber stack before each ClickHouse Rules
Final Verdict
|
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 100.00% (15/15, 0 noise lines excluded) |
azat
reviewed
Mar 21, 2026
Comment on lines
+50
to
+51
| void * stack_base = nullptr; | ||
| size_t stack_allocation_size = 0; |
Member
There was a problem hiding this comment.
Interesting why it does not trigger that the variable is not used warning
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.
ASan's
use-after-scopedetection poisons real stack memory when local variables go out of scope. On fiber stacks managed bymakecontext/swapcontext, this poisoning persists across context switches (yield/resume), causing false positives when the same stack addresses are reused by new frames in subsequent fiber resumes — notably during exception unwinding in_Unwind_Resume.The fix: call
ASAN_UNPOISON_MEMORY_REGIONon the entire fiber stack before eachFiber::resume, clearing any stale scope poisoning. This is complementary to the__sanitizer_start_switch_fiber/__sanitizer_finish_switch_fiberannotations in boost::context, which only manage the fake stack (for use-after-return), not real stack poisoning (for use-after-scope).See google/sanitizers#189
Example failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100041&sha=e3d5fc0647f84f316414376a48aa9ffbf8565b07&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes