Repository navigation
Fix segfault in UBSan build when calling JIT-compiled sort description - #99539
Merged
Merged
Conversation
UBSan's `-fsanitize=function` reads a type signature at `function_pointer - 8` before every indirect call. JIT-compiled functions lack this prologue, and when the JIT code sits at a page boundary, the pre-call read hits unmapped memory, causing a SIGSEGV. The `callJITFunction` wrapper (with `NO_SANITIZE_UNDEFINED`) already exists and is used for all other JIT function calls, but the two call sites in `SortCursor::greaterAt` and `SimpleSortCursor::greaterAt` were missing it. Also change `callJITFunction` to return `decltype(auto)` instead of `void` so it can be used with non-void JIT functions like `JITSortDescriptionFunc` (returns `int8_t`). https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=041d2e94874b0ca8cc527e2edec4f3e5daf012ee&name_0=PR&name_1=Stateless%20tests%20%28amd_ubsan%2C%20parallel%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [5ffe3e7] Summary: ✅ AI ReviewSummaryThis PR wraps JIT sort comparator calls with ClickHouse Rules
Final Verdict
|
1 task
The `callJITFunction` with `decltype(auto)` return now propagates the `int8_t` return type of `JITSortDescriptionFunc`, which clang-tidy flags as `bugprone-signed-char-misuse` when assigned to `int`. Add NOLINT comments since the sign is meaningful here (comparator returns -1/0/1). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Algunenano
approved these changes
Mar 16, 2026
Algunenano
left a comment
Member
There was a problem hiding this comment.
Looks good. AFAICT with this all places calling JIT functions are covered. I couldn't think of a simple way to cover this with the style check, and building a clang-tidy plugin seems way overkill.
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 71.43% (10/14, 0 noise lines excluded) |
This was referenced Apr 8, 2026
robot-clickhouse-ci-1
added a commit
that referenced
this pull request
Apr 15, 2026
Cherry pick #99539 to 26.3: Fix segfault in UBSan build when calling JIT-compiled sort description
robot-clickhouse
added a commit
that referenced
this pull request
Apr 15, 2026
…-compiled sort description
clickhouse-gh Bot
added a commit
that referenced
this pull request
Apr 15, 2026
Backport #99539 to 26.3: Fix segfault in UBSan build when calling JIT-compiled sort description
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
SortCursor::greaterAtandSimpleSortCursor::greaterAtwith the existingcallJITFunction(NO_SANITIZE_UNDEFINED) wrappercallJITFunctionreturn type fromvoidtodecltype(auto)to support non-void JIT functions likeJITSortDescriptionFuncRoot cause
UBSan's
-fsanitize=functionreads a type signature atfunction_pointer - 8before every indirect call. JIT-compiled functions lack this metadata prologue. When JIT code happens to be allocated at a page boundary, the pre-call read atpointer - 8hits unmapped memory, causing a SIGSEGV.The
callJITFunctionwrapper withNO_SANITIZE_UNDEFINEDalready exists and is used by all other JIT call sites (ExpressionJIT,Aggregator), but the two sort description call sites inSortCursor.hwere calling the JIT function directly without the wrapper.Found via: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=041d2e94874b0ca8cc527e2edec4f3e5daf012ee&name_0=PR&name_1=Stateless%20tests%20%28amd_ubsan%2C%20parallel%29
#96130
The crash occurred in test
02381_join_dup_columns_in_planwith randomized settings (join_algorithm = 'full_sorting_merge',compile_sort_description = 1) at address0x7fbd76affff8(unmapped page boundary).Test plan
Changelog category (leave one):
Changelog entry:
Fix segfault in UBSan builds when JIT-compiled sort description function is allocated at a page boundary.
🤖 Generated with Claude Code
Version info
26.4.1.4426.3.10.9