blob: d701cef99d191ee6bba30689cba1c575ea770834 [file] [view]
<!-- Copyright 2026 The Fuchsia Authors
Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
<LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
This file may not be copied, modified, or distributed except according to
those terms. -->
# `anneal-postlink`
Standalone, fail-closed post-link ELF64 auditor (`#![forbid(unsafe_code)]`) for
mixed C/C++/ASM binaries on `x86-64` and `AArch64`.
Given a linked ELF64 binary (`ET_EXEC` or `ET_DYN`), the pre-link relocatable
object files (`.o`), and a JSON manifest of verified symbols, `anneal-postlink`
verifies that linking did not alter verified machine code, redirect targets,
mutate read-only data, alias verified symbols, or violate image hardening
policies.
## CLI Usage
```bash
anneal-postlink \
--linked path/to/linked.elf \
--object unit_a.o --object unit_b.o \
(--manifest manifest.json | --symbol fn_a --symbol fn_b) \
[--json] \
[--require-relro] \
[--require-cet-ibt] [--require-bti] [--require-pac] \
[--max-stack-bytes <N>] \
[--allow-missing-gnu-stack]
```
Short aliases: `-o` (`--object`), `-m` (`--manifest`), `-s` (`--symbol`).
## Manifest Schema (`schema_version = 1`)
```json
{
"schema_version": 1,
"symbols": [
{
"name": "c_entry",
"object": "unit_a.o",
"allow_syscalls": false
}
]
}
```
- `object` (optional): disambiguates which `--object` input owns `name`.
- `allow_syscalls` (optional, default `false`): opts a symbol out of the
forbidden syscall-instruction scan (`syscall`/`sysenter`/`int 0x80` on
`x86-64`; `svc` on `AArch64`).
## Exit Codes
- `0`: Audit passed (`verdict == "PASS"`, zero findings).
- `1`: CLI usage, I/O, manifest JSON syntax error, or top-level ELF
header/section parse error.
- `2`: Audit completed with one or more findings (`verdict == "FAIL"`),
including `MANIFEST_INVALID` (unsupported `schema_version`, empty or
duplicate `symbols`) and malformed `PT_DYNAMIC`, `PT_GNU_PROPERTY`, or
`.stack_sizes` tables.
## Checks & Threat-Model Limits
- **Code byte-fidelity & allowlisted relocations:** Verified `.text` bytes must
match pre-link `.o` bytes everywhere outside allowlisted relocation patch
fields (`R_X86_64_{PC32,PLT32,GOTPCREL,GOTPCRELX,REX_GOTPCRELX}`,
`R_AARCH64_{ADR_PREL_PG_HI21,ADD_ABS_LO12_NC,CALL26,JUMP26}`). LTO bitcode
sections (`SHT_LLVM_LTO`), `R_X86_64_GOTTPOFF` relaxation, `STT_GNU_IFUNC`,
AArch64 veneers/thunks, `.dynsym`/`DT_SYMTAB` address or size drift on
verified symbols, and `--icf`/tail-merge symbol aliasing fail closed.
- **Read-only data & GOT/PLT binding:** `.rodata` references (same-object and
cross-object) are checked for read-only `PT_LOAD` mapping and SHA-256 byte
equality; pre-link relocations targeting verified `.rodata` sections
(`SHT_RELA`, `SHT_REL`, `SHT_RELR`, `SHT_CREL`) and `.dynsym` exports of
`STV_HIDDEN`/`STV_INTERNAL` symbols fail closed. Dynamic `PT_DYNAMIC`
metadata is read from its `PT_LOAD`-mapped virtual address (`Elf64_Rela` and
`Elf64_Relr` only; `DT_REL` and packed Android relocation tags fail closed).
`R_X86_64_JUMP_SLOT` requires eager binding (`BIND_NOW`) and zero addend.
`R_X86_64_GLOB_DAT` is accepted only for truly undefined external
(`SHN_UNDEF`) non-`.rodata` symbols and is rejected fail-closed for all
defined in-image symbols—including `.rodata`, `ET_EXEC`, `DF_1_PIE`,
`DT_SYMBOLIC`/`DF_SYMBOLIC`, `STV_PROTECTED`, and versioned
(`DT_VERSYM`/`DT_VERDEF`/`DT_VERNEED`) definitions (bind in-image GOT slots
locally via `R_X86_64_RELATIVE`/`DT_RELR` or static `ET_EXEC` GOT slots)—as
well as when overlapping `DT_PLTGOT[0..3]` or `DT_TLSDESC_GOT`.
- **Image hardening:** Enforces `W^X` and disjoint `PT_LOAD` mappings at
worst-case architecture page granularity (`4 KiB` on `x86-64`, `64 KiB` on
`AArch64`, and `p_align`) with `p_vaddr == p_offset (mod page)` congruence,
non-executable `PT_GNU_STACK`, optional `PT_GNU_RELRO` (page-rounded downward
and covering `PT_DYNAMIC` and `.got`), strict `PT_GNU_PROPERTY` CET/BTI/PAC
notes, and optional `.stack_sizes` bounds.
- **Limits:** `anneal-postlink` validates linked ELF64 artifacts statically; it
does not prove semantic equivalence of unverified external DSO callees, does
not separately validate relocation-free intra-section references between
symbols in the same input section (relying on linker section rigidity), and
does not prevent host-level runtime memory tampering outside ELF loader
semantics.