Skip to content

Fix UBSan SIGSEGV when calling JIT-compiled functions - #98671

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-cnf-jit-crash-test
Mar 4, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-cnf-jit-crash-test

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 3, 2026 •

Copy link
Copy Markdown
Member

Summary

  • 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 in compileFunction.h and use it at all JIT indirect call sites in ExpressionJIT and Aggregator.

Closes #98580

Test plan

  • UBSan build compiles successfully
  • CI passes — the AST fuzzer (amd_ubsan) job that was hitting ExpressionJIT.cpp:94 should no longer segfault

Changelog category (leave one):

  • CI Fix or Improvement

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

...

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.362

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]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fc2ef95]

Summary: ❌

job_name test_name status info comment
Install packages (amd_release) failure
Install server rpm failure cidb
Install keeper rpm failure cidb
Install packages (arm_release) failure
Install server rpm failure cidb
Install keeper rpm failure cidb
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-1bfa) FAIL cidb, issue
Finish Workflow failure
python3 ./ci/jobs/scripts/workflow_hooks/pr_body_check.py failure

@alexey-milovidov
alexey-milovidov force-pushed the fix-cnf-jit-crash-test branch from 8ba8e22 to fc2ef95 Compare March 4, 2026 02:05
@alexey-milovidov
alexey-milovidov merged commit 9e15232 into master Mar 4, 2026
283 of 290 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-cnf-jit-crash-test branch March 4, 2026 05:08
@alexey-milovidov alexey-milovidov self-assigned this Mar 4, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 4, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice finding

@Algunenano Algunenano added the post-approved Approved, but after the PR is merged. label Mar 23, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-approved Approved, but after the PR is merged. pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segmentation fault (STID: 3702-5bce)

3 participants