Skip to content

Add MSan support for fibers - #101621

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
azat:msan-fibers
Apr 7, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
azat:msan-fibers

Conversation

@azat

@azat azat commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Add MSan support for fibers

I've looked at github, and there are 0 usage of __msan_start_switch_fiber/__msan_finish_switch_fiber outside of LLVM - https://github.com/search?q=%22__msan_start_switch_fiber%22++-path%3A%22compiler-rt%22+-path%3A%22msan_interface.h%22+-path%3A%22msan%2Fmsan.cpp%22+-path%3A%22msan_interface_internal.h%22+-path%3A%22swapcontext_annotation.cpp%22+&type=code&ref=advsearch

So either it is a problem in other places, or it is not mandatory

Also I've tried to reproduce the issue with simple fibers, w/o any luck, but probably this is what we are hitting here.

Refs: ClickHouse/boost#45
Reverts: #100138
Closes: #101566
Fixes: #101649

Version info

  • Merged into: 26.4.1.599

@azat
azat requested a review from alexey-milovidov April 2, 2026 13:32
@clickhouse-gh

clickhouse-gh Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6714d1f]

Summary: ✅


AI Review

Summary

This PR updates boost::context integration for MemorySanitizer by enabling BOOST_USE_MSAN in ClickHouse CMake wiring, updating the Boost submodule to a commit that adds fiber-switch MSan hooks (__msan_start_switch_fiber / __msan_finish_switch_fiber), and removing manual stack-wide __msan_unpoison in FiberStack. High-level verdict: the change is coherent and correctness-improving for MSan instrumentation, with no high-confidence blockers found in touched code.

Missing context
  • ⚠️ No CI run status or sanitizer job logs were provided in this review context, so runtime validation in CI could not be confirmed here.
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 ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR. labels Apr 2, 2026
@azat

azat commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

So either it is a problem in other places, or it is not mandatory

Though the example from LLVM clearly reproduce a bug, though it has manual assertion - https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/msan/Linux/swapcontext_annotation.cpp

# with __msan* commented out
$ clang -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -fsanitize=memory -o /tmp/test compiler-rt/test/msan/Linux/swapcontext_annotation.cpp
$ /tmp/test
main: swapcontext to fiber
fiber: entering fiber
test: compiler-rt/test/msan/Linux/swapcontext_annotation.cpp:27: void (anonymous namespace)::fiber(): Assertion `previous_stack_bottom != nullptr' failed.
Aborted                    /tmp/test

@azat

azat commented Apr 2, 2026

Copy link
Copy Markdown
Member Author

Though actually I'm not sure that this will fix the problem

@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

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

Full report · Diff report

@azat

azat commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

This is still a good change, but unlikely this will help with MSan, but, let's at least try

@azat
azat marked this pull request as ready for review April 7, 2026 12:10
@alexey-milovidov alexey-milovidov self-assigned this Apr 7, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Thanks, this is much cleaner.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 7, 2026
Merged via the queue into ClickHouse:master with commit f6e93c6 Apr 7, 2026
163 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 7, 2026
@azat

azat commented Apr 8, 2026

Copy link
Copy Markdown
Member Author

It does not make sense to revert it completely, instead, we need to fix something on top, it is not doing anything worse, of course we could revert the __msan_unpoison hunk, but it is still unclear to me why we need it

@alexey-milovidov

Copy link
Copy Markdown
Member

I will try to add it while keeping both changes...

alexey-milovidov added a commit that referenced this pull request Apr 9, 2026
Value-initialize `ret_value` in `dragonbox::compute_nearest` to zero the 4 bytes
of tail padding in `fp_t<double,false,false>`. Without this, the uninitialized
padding shadow propagates through stack slot reuse on fiber stacks and can
contaminate unrelated values — causing MSan to report false "use-of-uninitialized-
value" errors (e.g. in `shared_ptr` refcount decrements).

This was the root cause of STID 4148-3044, which triggered the revert of PR #101621.

The test verifies both the fix (padding is clean after `to_decimal`) and the
underlying mechanism (default-init leaves padding uninitialized at offset 12).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo 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: 4179-5154)

3 participants