Repository navigation
AOT: sign return addresses on arm64 Linux - #1068
Conversation
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.
There was a problem hiding this comment.
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
removeCodePtrTagtoauthenticateReturnAddress/returnPCForInspectionin AOTUnwinding.cpp and AOTCallOperations.cpp, including the re-signing ofreturnAddressOfAwaitedCallagainst the handler's stack pointer and the restore of the stub's return word afterthrowException. - The arm64 poll-at-prologue stub now branching to
handleExceptionAtPrologue/throwStackOverflow(true)from inside the register-save region: both targets runemitFunctionEpiloguefirst, so SP is reset from FP before unwinding. - Candidate crashes in
authenticateReturnAddressfor 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.pypass 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.
|
Preview build of 5b6c7a9: |
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.
There was a problem hiding this comment.
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()inJSCPtrTag.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,aotFunctionProloguewith its.ordinaryuntag before re-entry) is consistent on both sides. - Not done here: no build, the image check (
check=VerifyEachStage) ortestaot/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.
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.
There was a problem hiding this comment.
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::putSigningLinkRegisterrewrite: traced the standard frame push/pop (stp fp, lr, [sp, #-16]!/ldp fp, lr, [sp], #16) throughmodifierIsStackPointerOutsideOfto PACIBSP/AUTIBSP, and single and pre/post-indexed stores and loads of lr throughstoreLinkRegister/loadLinkRegister— the modifier (address behind the word) matches what LLInt's PACIBSP uses, so frames mix as claimed. - The removable
LDRB wzr, [x30]probe inAssemblerBuffer::removeIntUnlessPinned: labels,codeSize(),isAligned()anddebugOffset()pin the buffer, andonlyComputesWithoutItexcludes PC-relative and memory instructions from being moved. resignReturnAddressin 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.pyfor the newaot/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.
| 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])] |
There was a problem hiding this comment.
🟡 (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.
#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)_
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.
ARM64Assemblerdoes it where it emits an instruction: what leaves the link register is signed, and what enters it is authenticated. An image takes code fromImageAssembleralone, which cannot be told to stop. offlineasm keeps the same rules forLowLevelInterpreterAOT.asm.The rules, and what is not signed (targets of indirect calls, saved registers), are in
aot/README.md.Other builds
lto-hardened: LLInt prologues andipint_entrysign for themselves, and B3 leaves x17 alone.What was run
FEAT_FPAC, or without pointer authentication: qemu only.Known issue
On main too: on hardened arm64, a generator with a loop cannot resume after its consumer left it.
Generated by Claude Code