Skip to content

AOT: sign return addresses on arm64 Linux - #1068

Merged
dylan-conway merged 7 commits into
mainfrom
claude/aot-sign-return-addresses
Nov 17, 2026
Merged

dylan-conway merged 7 commits into
mainfrom
claude/aot-sign-return-addresses

Conversation

@dylan-conway

@dylan-conway dylan-conway commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Ahead-of-time compiled programs now sign their return addresses (pac-ret) where ENABLE(RETURN_ADDRESS_SIGNING) is set, which hardened arm64 Linux builds now are by default. That flag with the compiler was an #error.

No generator of code signs by hand. ARM64Assembler does it where it emits an instruction: what leaves the link register is signed, and what enters it is authenticated. An image takes code from ImageAssembler alone, which cannot be told to stop. offlineasm keeps the same rules for LowLevelInterpreterAOT.asm.

  • Frame records hold the word that LLInt and the JITs save, so frames mix. Code without a frame pays nothing.
  • Resume addresses of generators and async functions are signed. The unwinder authenticates what selects a handler.
  • All instructions are hints, so ARMv8.0 still runs the image.

The rules, and what is not signed (targets of indirect calls, saved registers), are in aot/README.md.

Other builds

  • arm64 lto-hardened: LLInt prologues and ipint_entry sign for themselves, and B3 leaves x17 alone.
  • arm64 without signing: 70 of 367 families of stubs change, mostly in where they push the link register.
  • x64: 559 images differ in the stamp alone.

What was run

  • With pointer authentication: 5,021 AOT tests and the stress tests pass. In [do not merge] Test a hardened arm64 build that signs return addresses bun#49116, 22,716 programs behave as without signing, and an overwritten return address ends the program.
  • Without FEAT_FPAC, or without pointer authentication: qemu only.
  • Cost: TypeScript transpiles 1 to 2% slower, 307 small benchmarks 2.3% on average, recursion 6%, a throw through 16 frames 28%. Executables grow by 1.2%.

Known issue

On main too: on hardened arm64, a generator with a loop cannot resume after its consumer left it.


Generated by Claude Code

Compiled programs now work with ENABLE(RETURN_ADDRESS_SIGNING), and the
hardened arm64 lane that has the compiler is built with it.

- Functions and stubs sign the link register to save it and authenticate it
  as they load it. The saved word is the one LLInt and the JITs save.
- The address where a generator or an async function resumes is signed.
- The unwinder authenticates the addresses by which it looks for a handler.
- A check follows the linked code of an image and fails the build where a
  rule of aot/README.md, "Signed return addresses", is broken.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed this PR and did not find any bugs, but at 106 files and ~2,500 added lines in the AOT compiler, stubs, unwinder and LLInt, all on a control-flow-integrity surface (return-address signing), a human look is still worthwhile.

What was reviewed:

  • The unwinder's switch from removeCodePtrTag to authenticateReturnAddress/returnPCForInspection in AOTUnwinding.cpp and AOTCallOperations.cpp, including the re-signing of returnAddressOfAwaitedCall against the handler's stack pointer and the restore of the stub's return word after throwException.
  • The arm64 poll-at-prologue stub now branching to handleExceptionAtPrologue/throwStackOverflow(true) from inside the register-save region: both targets run emitFunctionEpilogue first, so SP is reset from FP before unwinding.
  • Candidate crashes in authenticateReturnAddress for frames entered via StackVisitor with no callee frame, and for HostCall frame records holding a raw address, were investigated and ruled out.
  • Not run here: the build-time check-signed-return-addresses.py pass and the qemu arm64 test runs the description cites; those results are the author's claims.
Extended reasoning...

The change makes AOT-compiled functions, stubs, and coroutine resume addresses sign their return addresses under ENABLE(RETURN_ADDRESS_SIGNING), removes the #error that blocked that configuration, enables it in the arm64 hardened lanes in lanes.mjs, and threads authentication through the unwinder, frame iterator, stack trace and LLInt prologues. It touches a security-sensitive surface: pointer-authentication-based control-flow integrity and exception unwinding, where a wrong key or modifier turns into a process abort or a bypass. The bug hunt ran dry with no findings and six candidate issues were ruled out, but the size (106 files), the machine-code emission for two architectures, and the fact that correctness depends on hardware behaviour that cannot be verified by reading decided defer over approve.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Preview build of 5b6c7a9: autobuild-preview-pr-1068-5b6c7a9a

It took any register that is stored beside the frame pointer for a return
address, and refused valid programs at the `stp x28, x29` of a stub that
saves every register. It now looks at the word behind the frame pointer.

It also finds a link register that is saved or authenticated after its
signature was stripped, and hints for the other key or for no modifier.
The code that is generated does not change.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed the updated PR (through 1e82f75) and did not find any bugs; because it introduces pac-ret signing across the AOT compiler, stubs, unwinder and LLInt, a human look at the signing rules would still be worthwhile.

What was reviewed:

  • The new frame-record matcher in AOTReturnAddressCheck.cpp: the stp/stnp (all four 64-bit forms), stp x, y, [fp], str/stur x, [fp, #8] masks were checked against the A64 encodings, and the hint filter admits only PACIB/AUTIB-SP and -1716 plus XPACLRI (the test's list 8, 12, 24-26, 28-30 matches).
  • resignReturnAddress() in JSCPtrTag.h: strip/authenticate/compare/re-sign stays in one asm block with x16/x17/x30 pinned and earlyclobbered, so the bare address never spills.
  • The move of signing from the entry thunks into the LLInt/IPInt prologues (LLIntThunks.cpp, LLIntEntrypoint.cpp, prologue, ipint_entry, aotFunctionPrologue with its .ordinary untag before re-entry) is consistent on both sides.
  • Not done here: no build, the image check (check=VerifyEachStage) or testaot/JSC tests were run; the arm64 results are the author's.
Extended reasoning...

The change spans 106 files and about 2,600 added lines, adding return-address signing (pac-ret via PACIBSP/AUTIBSP hints) to AOT-compiled functions and stubs, generator resume addresses, the unwinder, LLInt and IPInt prologues, with a static checker over linked machine code and native tests for it. It touches a control-flow-integrity surface, so a wrong rule would silently weaken the hardening or crash at authentication. The multi-agent hunt ran dry without findings and my own reading of the latest commit (the matcher encodings, the hint filter, the inline asm and the prologue relocation) found them consistent, but the size, the security-sensitive surface and the fact that the test runs were the author's under qemu and not reproducible here decide against approving outright.

This review covers commit 1e82f75, which is no longer the latest commit on this pull request; later commits are not covered by it.

The check of linked code now runs for every image of an engine that signs,
not only where it is asked for.

- It goes through code that no known entry leads to, and refuses
  instructions that it does not know.
- It refuses the address of a label that goes to memory without a
  signature, and a jump to what came off the stack.
- What it says of a stub does not depend on the program that calls it.
- The word of a resume address and the code of a handler are out of reach
  of code that does not go through the functions that sign and
  authenticate, on every platform.
- A hardened build for arm64 Linux signs unless it is told not to, and does
  not compile without -mbranch-protection=pac-ret.
- The tests of a lane that signs fail on a runner without pointer
  authentication.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

Each generator of code signed the return address by hand, and a check of the
finished image failed the build where one forgot. Now the ARM64 assembler does
it at the one place where it emits an instruction: what leaves the link
register is signed, and what enters it is authenticated. An image takes code
from ImageAssembler alone, which cannot be told to stop. The check is gone.

- offlineasm keeps the same rules for all of LowLevelInterpreterAOT.asm.
- removeCodePtrTag() and StubWords::isReturnAddress() take a signature off.
- CMake adds -mbranch-protection=pac-ret where return addresses are signed.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed the latest push (the assembler-level redesign) and found no bugs, but because this changes how every return address in JIT, LLInt and AOT code is signed and authenticated, a human look is still worthwhile.

What was reviewed:

  • The new ARM64Assembler::putSigningLinkRegister rewrite: traced the standard frame push/pop (stp fp, lr, [sp, #-16]! / ldp fp, lr, [sp], #16) through modifierIsStackPointerOutsideOf to PACIBSP/AUTIBSP, and single and pre/post-indexed stores and loads of lr through storeLinkRegister/loadLinkRegister — the modifier (address behind the word) matches what LLInt's PACIBSP uses, so frames mix as claimed.
  • The removable LDRB wzr, [x30] probe in AssemblerBuffer::removeIntUnlessPinned: labels, codeSize(), isAligned() and debugOffset() pin the buffer, and onlyComputesWithoutIt excludes PC-relative and memory instructions from being moved.
  • resignReturnAddress in JSCPtrTag.h: XPACLRI-then-compare catches a failed AUTIB on cores without FPAC; the x16/x17 early-clobber constraints keep the new modifier out of those registers.
  • Not done here: Tools/Scripts/aot/check-unified-sources.py for the new aot/ sources, and none of the PR's test or instruction-count claims could be run in this review.
Extended reasoning...

The change (118 files, ~3,100 lines added) makes the ARM64 assembler sign the link register on every instruction that saves it and authenticate it on every load, with a hand-written decoder of the A64 encoding space (ARM64LinkRegisterUse.h), a removable probe instruction that is compacted out of the assembler buffer, new PAC inline assembly for re-signing return addresses, and corresponding changes across AOT unwinding, stack walking, LLInt offlineasm, Air frame emission, CI lanes and CLAUDE.md. This is control-flow-integrity code: a mistake silently weakens pac-ret or crashes on authentication, and it cannot be validated by reading alone. The exit reason was dry_streak and the one candidate issue was ruled out, but the size, the security surface and the fact that the latest commit replaced the previous design (deleting the 1,000-line post-link check) decided defer over approve.

The labels that note where an operation begins kept the load that follows an
authentication, so a build with a map had other code than one without. A note
now takes a place that pins nothing and makes its label when the code is
written.

- The load is left out only where the jump to the address comes next.
- A WebAssembly function returns without it too.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment on lines +1090 to +1091
unless mnemonic =~ /\A(?:ld|st)(?:[ut]?r|n?p)\z/i and isIt.any? and offsetBefore and step and not (isLoad and address =~ linkRegister)
return [sign, instruction, *(mnemonic =~ /\Ast(?:[ut]?r[bh]?|n?p)\z/i ? [strip] : [authenticate, validate])]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 (optional) On pointer-authentication hardware, any LLInt-AOT instruction that loads through the link register would read from a signed (invalid) address and fault, where the C++ assembler handles it correctly. arm64.rb:1090-1091 emits PACIBSP in front of a load whose base is x30, such as ldr x30, [x30, #8] or ld1 {v0.2d}, [x30], x9, so the load uses the signed pointer. Fix: treat lr used only as an address (not copied out) the way ARM64LinkRegisterUse.h useBy() does, emitting no sign before the instruction and only AUTIBSP plus the load after it, and correct the expectations in Tools/Scripts/aot/test-offlineasm-signing.rb:19-20 that currently assert the signing. No instruction in LowLevelInterpreterAOT.asm does this today, so the divergence is latent.

Why this was flagged

The trigger is an instruction between beginSigningLinkRegister and endSigningLinkRegister (LowLevelInterpreter.asm:2321-2324) that loads with x30 as the base register, run on an arm64 CPU with pointer authentication. At arm64.rb:1090 the not (isLoad and address =~ linkRegister) clause makes such a load fall into the generic branch at arm64.rb:1091, which returns ["hint #27", instruction, "hint #31", "ldrb wzr, [x30]"]: PACIBSP writes a signature into x30 before the load executes, so the load's base address is the signed value and the access faults. ARM64LinkRegisterUse.h useBy() returns Use{false, true} for a load into or through lr, and ARM64AssemblerSignedLinkRegister.cpp:62-66 therefore emits no PACIBSP for it. Tools/Scripts/aot/test-offlineasm-signing.rb:19-20 lists "ldr x30, [x30, #8]" and "ld1 {v0.2d}, [x30], x9" under the [SIGN, text, AUTHENTICATE, LOAD] expectation, so the self-test passes with the wrong output. On the base branch LowLevelInterpreterAOT.asm is not rewritten at all, so no such fault can occur. Today no line of LowLevelInterpreterAOT.asm names lr or x30, so this is a latent divergence.

Verification: nit — latent: the rewriter really does sign x30 before a load that uses x30 as its address base, but no instruction in the signed region as merged produces such a load, so nothing crashes today. Traced for ldr x30, [x30, #8] in Source/JavaScriptCore/offlineasm/arm64.rb: at line 1090 the clause not (isLoad and address =~ linkRegister) is false, so line 1091 returns PACIBSP, the load, AUTIBSP, ldrb wzr, [x30].

…mage

- offlineasm left an instruction alone that names no register but the link
  register unless it was one of four. It now has to be arithmetic.
- offlineasm no longer signs in front of a load through the link register,
  which would have made the load fault.
- WebAssembly code for an image asks for neither the map of origins nor the
  disassembler. Nothing read them, and their labels kept a load.

The interpreter that offlineasm generates is the same as before.
@dylan-conway
dylan-conway merged commit a8d825d into main Nov 17, 2026
87 checks passed
dylan-conway added a commit to oven-sh/bun that referenced this pull request Nov 17, 2026
#49226)

### What does this PR do?

Updates WebKit to `a8d825d8`, where compiled programs can sign their
return addresses on arm64 Linux (oven-sh/WebKit#1068), and makes crash
reports read such addresses.

- `caller_of_compiled_frame()` took the saved return address as it was,
so a report lost every caller of a compiled function. This line is the
fix; the walk over frame pointers already took the signature off.
- The address that faulted loses its signature. Without `FEAT_FPAC` a
failed authentication ends in a jump to such an address.
- Every register loses it, not only x30. A signed address in another one
was printed in full.

Also in the update:

- oven-sh/WebKit#1069, whose Bun side is #49145. That changes
the same line to an older commit: keep `a8d825d8`.
- `--hardened=on` on arm64 Linux, which CI does not build, now stops at
an `#error` in `JSCPtrTag.cpp` unless it is given
`-mbranch-protection=pac-ret` or `-DENABLE_RETURN_ADDRESS_SIGNING=0`.
Compiler flags are not part of this change, nor is the unwind table of
`--aot-symbols`.

### How did you verify your code works?

`run-crash-handler.test.ts` has a compiled program that sets signature
bits on its saved return addresses and faults. It runs on arm64 Linux
with pointer authentication alone, so CI is its first run. On x64, with
a mask in place of the instruction, an earlier form of the program
listed 10 frames with the fix and 1 without.

---
_Generated by [Claude Code](https://claude.ai/code)_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant