Skip to content

Unpoison fiber stack after context switch on AArch64 to fix MSan false positives - #102305

Closed
alexey-milovidov wants to merge 4 commits into
masterfrom
fix-msan-textlog-format-string-v2
Closed

alexey-milovidov wants to merge 4 commits into
masterfrom
fix-msan-textlog-format-string-v2

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

On AArch64, LLVM loses MSan shadow for struct-padding bytes in return values (llvm/llvm-project#54476). On heap-allocated fiber stacks the dirty shadow accumulates across context switches and propagates via stack-slot reuse, triggering false positives in unrelated code.

The one-time __msan_unpoison at fiber allocation (in FiberStack::allocate) is insufficient because BOOST_USE_MSAN (added in #102158) now properly preserves shadow across context switches — including the dirty padding shadow. This caused a spike from ~1-5 failures/day to 81 failures on April 9 for STID 1478-2063.

Fix by calling __msan_unpoison on the whole fiber stack after every __msan_finish_switch_fiber on AArch64 in fiber_ucontext.hpp. This clears accumulated dirty padding without affecting the main thread stack.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97744&sha=aa7dccac1cbacd8009ec368bdbf6045ff7bc3c29&name_0=PR&name_1=Stress%20test%20%28arm_msan%29

Fixes: #102241

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

…e positives

On AArch64, LLVM loses MSan shadow for struct-padding bytes in return values
(llvm/llvm-project#54476). On heap-allocated fiber stacks the dirty shadow
accumulates across context switches and propagates via stack-slot reuse,
triggering false positives in unrelated code (e.g. STID 1478-2063 in
`system.text_log`).

The one-time `__msan_unpoison` at fiber allocation is insufficient because
`BOOST_USE_MSAN` (added in #102158) now properly preserves shadow across
context switches — including the dirty padding shadow.

Fix by calling `__msan_unpoison` on the whole fiber stack after every
`__msan_finish_switch_fiber` on AArch64. This clears accumulated dirty
padding without affecting the main thread stack.

Fixes: #102241
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97744&sha=aa7dccac1cbacd8009ec368bdbf6045ff7bc3c29&name_0=PR&name_1=Stress%20test%20%28arm_msan%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3169f58]

Summary: ✅


AI Review

Summary

This PR updates contrib/boost to a commit that fixes AArch64 MSan false positives by adding __msan_unpoison in Boost fiber context-switch paths, and updates comments in src/Common/FiberStack.cpp to document the behavior. I did not find correctness, safety, performance, compatibility, or rollout issues in the final PR state. The previously reported unpublished submodule SHA issue is no longer present in the final gitlink.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci submodule changed At least one submodule changed in this PR. labels Apr 9, 2026
Comment thread contrib/boost Outdated
@@ -1 +1 @@
Subproject commit 8519680cb3ccd2246e4e5564b22492d288a53f4b
Subproject commit 2bbd74abb858eabc9d1ddc8de9b8cd7046085fd1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ This submodule pointer currently cannot be fetched from https://github.com/ClickHouse/boost.

I verified with both GitHub API and local submodule update:

  • gh api repos/ClickHouse/boost/commits/2bbd74abb858eabc9d1ddc8de9b8cd7046085fd1 returns No commit found.
  • git submodule update --init contrib/boost fails with not our ref for this SHA.

This is a merge blocker because fresh checkouts cannot initialize contrib/boost. Please push this commit to ClickHouse/boost (or update the gitlink to a published SHA).

alexey-milovidov and others added 3 commits April 10, 2026 08:30
Point to ClickHouse/boost#46 which adds __msan_unpoison after every
fiber context switch on AArch64, fixing MSan false positives caused by
struct-padding shadow accumulation on fiber stacks (STID 1478-2063).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The previous commit added `__msan_unpoison` calls to fiber_ucontext.hpp
for AArch64 but did not declare the function in `externc.hpp`, causing
the arm_msan build to fail with "use of undeclared identifier".

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102305&sha=e87e73c4a31aa85a462c7f8bc22f319b6ce3d58a&name_0=PR&name_1=Build%20%28arm_msan%29

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 100.00% (2/2) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Obsolete after #102344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MemorySanitizer: use-of-uninitialized-value (STID: 1478-2063)

1 participant