Skip to content

Report a crash whose own stack capture faults, and recover SIGILL from stack unwinding on AArch64 - #132186

Open
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/unwind-fault-recovery-pac
Open

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/unwind-fault-recovery-pac

Conversation

@groeneai

@groeneai groeneai commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131784

Changelog category (leave one):

  • Improvement

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

A crash whose own stack trace capture faults is now reported in the server log with an empty trace, instead of the server exiting without a report. On AArch64 this includes a failed return address authentication.

Description

Master SQLLogic test lost its server with exit code 132 (SIGILL) and no <Fatal> line on 929e3b414e and e53b32344d (Graviton4, arm_release): 2 of 58 master commits since #131784, 0 of 518 in the 10 days before.

Since #131784, libunwind authenticates every signed return address it reads with autia1716. On cores with FEAT_FPAC (Graviton4), a failed authentication raises SIGILL. Two gaps turn that into a silent death:

  • signalHandler recovers a fault of an asynchronous capture (query profiler, system.stack_trace) only for SIGSEGV (and SIGBUS on Darwin).
  • The deadly and SIGTSTP handlers block the fault signals, so when their own StackTrace(ucontext) walk faults, the kernel kills the process before the record is written. For SIGSEGV this is pre-existing on every architecture.

The change: SIGILL is recovered too on Linux AArch64, and the recoverable signals are unblocked around the capture in signalHandler.

Validation:

  • A new gtest drives the real SIGTSTP handler over a corrupted frame chain. Without the change it is killed by SIGSEGV; with it, the record is reported with an empty trace.
  • Under qemu-user -cpu max (FEAT_FPAC), gdb makes one return address fail authentication. The CI binary and a base cross build die silently (rc 132) on the thread's own return and during a system.stack_trace capture. With the fix, the first logs Received signal Illegal instruction (4); in the second, the capture is dropped and the server runs on until that return, which is then reported.

What raised the first signal is unknown (neither run kept a core or server log); a recurrence is now reported, or survived if it was a capture. Reverting #131784 would also stop these deaths, at the cost of the hardening.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/132186]

groeneai and others added 3 commits November 16, 2026 23:31
…AArch64

With `-mbranch-protection=pac-ret` (ClickHouse#131784) libunwind authenticates every
signed return address it reads with `autia1716`. On cores with FEAT_FPAC
(Graviton4 = Neoverse V2, which runs CI's arm jobs) a failed authentication
raises SIGILL instead of silently corrupting the pointer. Two gaps then turn
one inconsistent frame into a silent death:

- `signalHandler` recovered a fault during `asynchronous_stack_unwinding` only
  for SIGSEGV (and SIGBUS on Darwin), so a SIGILL in the query profiler's or
  `system.stack_trace`'s walk took the fatal path. Recover SIGILL too on Linux
  AArch64, the only platform where return addresses are signed.
- The deadly handler and the SIGTSTP handler block the fault signals in their
  `sa_mask`. When their own `StackTrace(ucontext)` walk faults, the signal is
  blocked, and Linux kills the process at once (`force_sig_fault` resets a
  blocked synchronous signal to SIG_DFL), before the record reaches the signal
  pipe. Unblock the recoverable signals around that capture; the
  `sigsetjmp(..., 1)` in the capture saves the unblocked mask, so both the
  normal and the recovered path fall through to the single restore. The crash
  is then reported with an empty trace instead of vanishing.

Master SQLLogic test on 929e3b4 (Graviton4) lost its server this way:
exit 132, no `<Fatal>` line, the socket gone in under 2 s.

Under qemu-user with FEAT_FPAC (`-cpu max`), the CI arm_release binary dies
with rc 132 and no report both when a thread's own `autiasp` fails and when a
`system.stack_trace` capture meets that frame; with this change the first is
reported (`Received signal Illegal instruction (4)`, `Illegal operand.`) and
the second capture is dropped while the server keeps running.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test only checked that a record was written, which a capture that never
reached the corrupted frame also produces. Decode the record as
`SignalListener::run` does and require an empty trace: `StackTrace(ucontext)`
returns size 0 only from its fault branch. A clean SIGTSTP capture first must
have frames, which also proves the decode reads the right field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the SIGILL sentence from the recovery comment in signalHandler: the definition of unwind_fault_signals already states it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings, then 0 on the delta recheck) plus my own review (nits only).

# Sev Finding Verdict Evidence / action
1 ⚠️ The gtest checked only the record size, so a capture that never faulted passed too AGREE, fixed @ 478d6a5 The test decodes the record as SignalListener::run does: a clean capture must have frames, the faulted one must be empty. With the corruption made a no-op it fails.
2 ⚠️ No discriminating evidence for the AArch64 SIGILL path DISAGREE qemu -cpu max (FEAT_FPAC), base vs fix: base dies silently with rc 132 on both paths; the fix reports Illegal operand. on the thread's own return and survives the system.stack_trace capture (the sleeping thread's length(trace) = 0). CI runs no aarch64 unit tests.
3 💡 A recovered SIGILL report has an empty trace and no address line noted Out of scope here
4 💡 The death test was run in debug and ASan, not TSan/MSan noted The oracle fails closed there: a walk that does not fault fails the test

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-11:20261117-005300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @mstetsyuk, could you review this? The crash and SIGTSTP handlers block the fault signals, so a fault in their own StackTrace(ucontext) walk killed the server before the report was written; the change unblocks the recoverable signals around that capture and also recovers SIGILL from a failed return address authentication (pac-ret, FEAT_FPAC) on Linux AArch64.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. amd64: unit_tests_dbms --gtest_filter='SignalHandlersDeathTest.*' is killed by SIGSEGV on every run without the change. aarch64: under qemu-aarch64 -cpu max (FEAT_FPAC), gdb flips bit 52 of one signed return address in FunctionSleep::execute; every run is deterministic.
b Root cause explained? Since #131784 libunwind authenticates signed return addresses with autia1716, which raises SIGILL on FEAT_FPAC cores. signalHandler recovered only SIGSEGV (and SIGBUS on Darwin) during an asynchronous capture, and the deadly and SIGTSTP handlers block every fault signal, so a fault in their own StackTrace(ucontext) walk is delivered blocked and the kernel kills the process before the record reaches the signal pipe.
c Fix matches root cause? Yes. It closes both gaps in the existing recovery, at the handler that owns the mask: SIGILL joins the recovered set on Linux AArch64, and the recoverable signals are unblocked around the capture only. The unknown first fault on CI is not claimed as fixed.
d Test intent preserved / new tests added? New gtest UnwindFaultInBlockingHandlerIsRecovered (real SIGTSTP handler, corrupted saved frame pointer). It decodes the reported record: a clean capture must have frames, the faulted one must be empty. The SIGILL half is compiled only on Linux AArch64, where CI runs no unit tests, so it is validated under qemu with FEAT_FPAC.
e Both directions demonstrated? gtest: killed by signal 11 before, 20/20 after (debug), and the same under ASan; with the corruption made a no-op it fails (the faulted capture was dropped). qemu -cpu max: the CI binary and a base cross build die with rc 132 and no report, both on the thread's own return and during a system.stack_trace capture; with the change the first is reported (Received signal Illegal instruction (4), Illegal operand.) and the second capture is dropped. -cpu neoverse-v1 (no FPAC) logs a SIGSEGV.
f Fix is general across code paths? Every StackTrace(ucontext) caller is covered: the deadly and SIGTSTP handlers by the unblock, the query profiler and system.stack_trace (which do not mask fault signals) by the recovered set. The TSan profiler path never authenticates and is untouched.
g Fix generalizes across inputs (params/datatypes/wrappers)? Signal x platform matrix: SIGSEGV everywhere, SIGBUS on Darwin as before, SIGILL on Linux AArch64 only; elsewhere a SIGILL during the walk stays fatal. No data types involved.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or protocol change.
i Invariants and contracts preserved? The signal mask is restored on both the normal and the recovered path (one restore after the capture; sigsetjmp(..., 1) saves the unblocked mask). No allocation is added in the handler, and the calls are async-signal-safe. A nested fault fits the alternate stack and siglongjmps before touching anything.

Session id: cron:clickhouse-impl-slot-41:20261116-221800

@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ac234d2]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

Reviewed #132186 at ac234d2c564d26212f87614ea81f4a7fe70a3e94, including the complete diff, surrounding code, and prior discussion. The change temporarily unblocks recoverable unwinder faults in the fatal and SIGTSTP handlers and adds recovery for SIGILL on Linux AArch64. No actionable blockers or majors found.

Empty-trace consumers checked: SignalListener::onFault retains the signal report; StackTrace::toStringEveryLine renders an empty trace; collectCrashLog accepts zero frames; CrashWriter::sendError omits the trace payload; the query profiler drops empty samples; StorageSystemStackTrace emits an empty array. The regression test distinguishes a successful capture from a recovered unwind fault. The author's recorded before/after validation also covers AArch64 authentication faults.

Missing context / blind spots
  • ⚠️ No configured build or test binary is available locally, so tests were not rerun. Relevant build and unit-test jobs were still pending during review; their completed results will close the remaining CI verification gap. AArch64 validation relies on the author's reported QEMU experiments.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). labels Nov 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ac234d2

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra, not from this PR (no ci/ file in the diff): the readiness probe to the CI logs cluster never succeeded, so has_pr_data raised LogClusterNotReady: the endpoint never became ready. The same job errored this way on 42 PRs in the last 24 hours #129675 (mine, open)
PR praktika rollup of the row above #129675 (mine, open)

The other CIDB FAIL row on this head is Config Workflow / Pre Hooks of the run before the can be tested label. Mergeable Check, Review Threads and CH Inc sync are green.

Session id: cron:our-pr-ci-monitor:20261117-043014

@groeneai

Copy link
Copy Markdown
Collaborator Author

Another silent death, and this one kept a core: Stress test (arm_release) on an unrelated PR's run (report, m8g.4xlarge, server log stops with no <Fatal> line). The core matches the job's -dbg package (build id 7f184c4b) and shows what raised the first signal:

  • The thread was compiling an expression (its last log line is ExpressionJIT: Compile expression ...) and was inside OUTLINED_FUNCTION_8, a part of the prologue of llvm::PassManager<Function>::addPass<InstCombinePass> that the machine outliner moved out.
  • The query profiler interrupted it (writeTraceInfo -> StackTrace(ucontext) -> unw_step). At the return address of that call, addPass+12, the CFI row is still the one right after paciasp: CFA = SP, return address signed and in x30. But x30 holds the unsigned return address of the outlined call, so autia1716 in DwarfInstructions::applyRule gets x17 = addPass+12 with no PAC and raises SIGILL (si_code 2).
  • signalHandler does not recover SIGILL, so it captures its own stack, walks back into the same frame and faults again while SIGILL is blocked. The kernel kills the process before anything is logged.

The row is wrong because addPass is LLVM_ATTRIBUTE_MINSIZE, and the AArch64 backend emits only synchronous unwind info for minsize functions (AArch64FunctionInfo::needsAsyncDwarfUnwindInfo). So it is not stack corruption: any profiler sample that lands in such a window on an FEAT_FPAC core can do this. The first fault happens inside an asynchronous capture, so with this change it is recovered and the sample is dropped.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The same chain now kills a master Stateless tests (arm_release, parallel) run: report, Server liveness check failed mid-run, no <Fatal> in the server log.

Its core (build id b3113a4a, matches the job's -dbg package) is identical to the stress core above: SIGILL si_code 2 at autia1716 in applyRule, inside a query profiler sample (writeTraceInfo -> StackTrace(ucontext)) that landed on the first instruction of OUTLINED_FUNCTION_8, with x17 = the unsigned return address addPass<InstCombinePass>+12. signalHandler then faults again in its own capture. The thread was running the INSERT ... SELECT of 03578_parallel_replicas_minicrawl.

On master that makes 4 silent arm deaths since #131784 merged (3 SQLLogic test exit 132, and this one).

This branch has not been deployed

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

Labels

can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant