Repository navigation
Fix UBSan SIGSEGV when calling JIT-compiled functions - #98671
Merged
Merged
Conversation
UBSan's `-fsanitize=function` check reads a type signature at `function_pointer - 8` before every indirect call. JIT-compiled functions don't have this prologue, and when JIT code is allocated at the start of a page by `posix_memalign`, the read accesses unmapped memory, causing a SIGSEGV. Add `callJITFunction` wrapper marked `NO_SANITIZE_UNDEFINED` and use it at all JIT indirect call sites in `ExpressionJIT` and `Aggregator`. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
|
Workflow [PR], commit [fc2ef95] Summary: ❌
|
1 task
alexey-milovidov
force-pushed
the
fix-cnf-jit-crash-test
branch
from
March 4, 2026 02:05
8ba8e22 to
fc2ef95
Compare
opensource-fork-sync Bot
pushed a commit
to cla7aye15I4nd/opensource-ClickHouse__ClickHouse
that referenced
this pull request
Oct 29, 2026
In UBSan builds `-fsanitize=function` reads a type signature at `callee - 8` before every indirect call. JIT-compiled code has no such prologue, so when the page right before the JIT code is unmapped the read faults in the caller, at the call line. ClickHouse#98671 and ClickHouse#99539 fixed this for the expression, aggregate and sort description JIT with `callJITFunction` (`NO_SANITIZE_UNDEFINED`); the regexp JIT, added later, calls `matcher.func` directly in `match`, `extract`, `extractAll` and `replaceRegexpOne/All`. This is the SIGSEGV at `MatchImpl.h:183` reported in ClickHouse#127747: for a `LowCardinality` argument the function runs over the dictionary, so even the 0-row PREWHERE header evaluation calls the JIT matcher. Whether the read faults depends on the memory layout around the JIT code pages, so the query alone does not reproduce it. `callJITFunction` lives in `compileFunction.h`, which needs `USE_EMBEDDED_COMPILER` and LLVM headers, while the regexp callers compile without them. Move it unchanged to a dependency-free `Interpreters/JIT/callJITFunction.h`, include it from `compileFunction.h` and `CompileRegexp.h`, and route the four calls through it. Verified on a `-DSANITIZE=undefined` build: before the change each of the eight regexp objects has a `cmpl $0xc105cafe,-0x8(%reg)` at the call line; after it there is none, the indirect call remains, and each object's total count of such checks drops by exactly the number of call sites. Release builds are unaffected. Closes ClickHouse#127747 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Summary
-fsanitize=functioncheck reads a type signature atfunction_pointer - 8before every indirect call. JIT-compiled functions don't have this prologue, and when JIT code is allocated at the start of a page byposix_memalign, the read accesses unmapped memory, causing a SIGSEGV.callJITFunctionwrapper markedNO_SANITIZE_UNDEFINEDincompileFunction.hand use it at all JIT indirect call sites inExpressionJITandAggregator.Closes #98580
Test plan
AST fuzzer (amd_ubsan)job that was hittingExpressionJIT.cpp:94should no longer segfaultChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
🤖 Generated with Claude Code
Version info
26.3.1.362