Repository navigation
aarch64: sign the return address saved in jmp_buf - #7
Merged
Merged
Conversation
`setjmp` and `sigsetjmp` store `x30` in the `jmp_buf`, and `longjmp` and the second return of `sigsetjmp` branch through what they load back, so a `jmp_buf` reachable by an overflow is a return address in memory exactly like a spilled one. ClickHouse builds with `-mbranch-protection=pac-ret`, which signs the compiler-generated spills but says nothing about raw `.s` inputs, so these stayed unsigned. Sign `x30` with `paciasp` before storing it and authenticate it with `autiasp` after loading it back. The modifier is `sp`, which is the same at both ends: `longjmp` restores the `sp` that `setjmp` saved before it authenticates, and `sigsetjmp` resumes with its own `sp` whether control comes back from `setjmp` or from `longjmp`. Both instructions are in the hint space, so cores without `FEAT_PAuth` execute them as no-ops. Checked on Neoverse V2: round trips through `setjmp`/`longjmp` and `sigsetjmp` work, the saved slot carries a signature in the upper bits, and flipping one bit of it makes `longjmp` fault. Related: ClickHouse/ClickHouse#119685 Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Oct 5, 2026
Under `USE_MUSL` the `aarch64` asm sources from `contrib/musl` are raw `.s` inputs, which `-mbranch-protection` does not instrument. The only return address among them that lives in memory is `x30` in a `jmp_buf`, written by `setjmp` and `sigsetjmp` and branched through by `longjmp`; bump musl to sign it with `paciasp` and authenticate it with `autiasp`, both with `sp` as the modifier, which `longjmp` restores before authenticating. `dlsym.s` and `clone.s` save `x30` only as a value or a function pointer, so they need nothing. ClickHouse/musl#7 Addresses review: #119685 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…untime Companion to __pthread_current_tsd_range. The sanitizer runtime resets the shadow of a starting thread's stack and static TLS block only; musl carves the stack, the TLS image and the tsd array out of one mapping with internal __mmap/__munmap/__unmapself calls the runtime never sees, so a mapping recycled for a new thread keeps the previous thread's shadow for everything else. On TLS_ABOVE_TP targets (aarch64) struct pthread sits just below the thread pointer, outside the static TLS block, and TSan reported its errno_val as a data race between an exited tokio blocking-pool thread and its replacement. `__pthread_current_thread_range` lets GetTls cover the descriptor, as ThreadDescriptorSize() does on glibc. (cherry picked from commit b147430)
alexey-milovidov
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Oct 24, 2026
Resolve the `contrib/musl` conflict: master moved the submodule to `7ad08176` (`sanitizer-thread-range`) while this branch points at `34664698` (`pac-ret-setjmp`). The two touch disjoint files, so they are merged in `ClickHouse/musl` as `ca24ff58` on the `pac-ret-setjmp` branch (ClickHouse/musl#7), and the gitlink points there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Oct 26, 2026
Related: #119685 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
thevar1able
added a commit
to ClickHouse/ClickHouse
that referenced
this pull request
Nov 3, 2026
It now contains the per-arch rseq signature fix merged in ClickHouse/musl#8. It also brings ClickHouse/musl#7, which signs the return address that the aarch64 `setjmp` stores, using hint-space instructions that are no-ops on cores without `FEAT_PAuth`. 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.
setjmpandsigsetjmpstorex30in thejmp_buf, andlongjmpbranches through it, so ajmp_bufreachable by an overflow is a return address in memory, like a spilled one.-mbranch-protection=pac-ret(ClickHouse/ClickHouse#119685) signs compiler-generated spills but not raw.sinputs.This signs
x30withpaciaspbefore storing it and authenticates it withautiaspafter loading it back. The modifier issp, which is the same at both ends. Both instructions are hint-space no-ops on cores withoutFEAT_PAuth.The other
aarch64asm sources do not spill a return address:dlsym.spassesx30as a value,clone.ssaves a function pointer, and the rest never touchx30.I checked this on Neoverse V2: round trips work, and corrupting the saved slot makes
longjmpfault.Related: ClickHouse/ClickHouse#119685
🤖 Generated with Claude Code