AArch64 Model
The AArch64 front end, --arch aarch64, is a trace verifier. Its input is a recording of one run of an AArch64 program in the trace/v1 JSON format. It turns the recorded instruction sequence into a bit-vector SPL model of that path, replays the recording against the model's semantics, and then decides, for every place a pattern matches, whether some choice of the declared inputs makes the pattern's constraint hold while following the recorded path.
Input: a trace-v1 recording#
A JSON document with "schema_version": "trace/v1" and "arch": "aarch64" in its metadata. The analyzer also recognises such a document from its content, whatever its extension. The main parts:
metadata—arch,byte_order,abi, an optionalproducer, andsymbolic_inputs: the registers and memory ranges the verifier may choose freely. Everything else keeps its recorded value.initial_state— register values and memory contents at the start.steps— one entry per executed instruction:pc,mnemonic, typedoperand_tokens,op_kind, the observeddelta(registers and memory written, with their values) and, for branches and calls,branch(taken,next_pc,target_pc). A call carries the callee'ssymbol.
An excerpt of crates/sable-frontends/tests/fixtures/trace-aarch64/chain_190_122.json, the running example below:
{
"schema_version": "trace/v1",
"metadata": {
"arch": "aarch64",
"byte_order": "little",
"abi": "aapcs64",
"producer": "hand-written fixture",
"symbolic_inputs": {
"registers": [ "X1" ],
"memory": [ { "addr": "0x4a0088", "width_bytes": 8 } ]
}
},
"initial_state": { … },
"steps": [
{
"index": 1,
"pc": "0x401014",
"mnemonic": "adds",
"operands_text": "w0, w2, #0x40",
"op_kind": "ARITH",
"delta": {
"registers": {
"X0": { "width_bits": 64, "from": "0x0", "to": "0x0" },
"NZCV": { "width_bits": 32, "from": "0x0", "to": "0x60000000" }
},
"memory": []
},
…
},
…
]
}The recorded run: ldr x2, [x1, #8] loads a word, adds w0, w2, #0x40 adds 64 to its low 32 bits (the recording wraps to 0), b.vs falls through, bl malloc allocates with that size, and str x3, [x0, #8] stores into the new block.
1. Translate#
saple translate crates/sable-frontends/tests/fixtures/trace-aarch64/chain_190_122.json \
--arch aarch64 -o chain.splWrote SPL to chain.spl
Wrote sidecar to chain.trace.json
Translated: 1 agents, 1 behaviors, 0 warningsThe model's process follows the recording; the branch that was not taken is unexplored:
agent program() {
attributes { }
process {
B0 =
init_memory() .
// step 0 @ 0x401010: ldr x2, [x1, #8]
ldr_x_imm(X2, X1, 8) .
// step 1 @ 0x401014: adds w0, w2, #0x40
adds_w(X0, X2, 64) .
// step 2 @ 0x401018: b.vs 0x401030
branch V == 1
taken: branch_taken(0x401030) . unexplored
observed fall: branch_fall(0x40101c) . B1 ;
B1 =
// step 3 @ 0x40101c: bl malloc
call_malloc(X0) .
// step 4 @ 0x401020: str x3, [x0, #8]
str_x_imm(X3, X0, 8) .
done ;
}
}The schema declares X0..X30, SP, PC, the flags N, Z, C, V and Memory in compact form, with the recorded initial values; a libc agent holds the shadow attributes that the library calls update (libc.last_alloc_ptr, libc.last_alloc_size, …), and call_malloc havocs the AAPCS64 caller-saved registers through regset caller_saved = { X1..X18, X30, NZCV }.
Library state: libc.<field>#
Library code is not modelled instruction by instruction. The model declares a passive agent libc (its process is Idle = done) whose attributes record what the recognised calls did; transitions, the solver encoding and patterns refer to them by the qualified name libc.<field>. All are BV<64>, initially 0:
| Field | Set by |
|---|---|
libc.last_alloc_ptr, libc.last_alloc_size | call_malloc(size), call_calloc(n, size): the returned pointer and the size (n * size for calloc) |
libc.last_free_ptr, libc.last_free_size | call_free(ptr): the released pointer, and the size of the block when it is the last allocation (0 otherwise). An allocation that returns the freed pointer resets both to 0. |
libc.last_copy_dst, libc.last_copy_src, libc.last_copy_len | call_memcpy, call_memmove, call_memset (src is the fill value), call_strcpy (length unknown, havocked), call_strncpy |
The recognised callees are malloc, calloc, free, memcpy, memmove, memset, strcpy and strncpy. In a pattern constraint, a libc.<field> name that is not a binder denotes the field's value after the last matched action, so a memory pattern can put its signature on the access alone:
pattern cwe_416_load_after_free {
signature {
ldr_x_imm(dst, base, imm) .
done
}
constraints {
libc.last_free_ptr != 0 && base == libc.last_free_ptr
}
severity: CRITICAL ;
}A libc.<field> name is an ordinary field access in SPL (Expressions); the trace front end gives it this meaning.
The sidecar#
With -o model.spl, translate also writes model.trace.json (format trace-aarch64-sidecar/1): the path condition of the recording (the guards of the observed branches), the havoc symbols of library calls with their observed values, the data dependencies between steps and what the replay could verify. saple analyze model.spl reads it from beside the model.
model.trace.json beside model.spl, saple analyze does not run the trace verifier: it reports plain structural matches with no verdicts, and gives no warning.
Checking a recording#
--check replays the trace and prints a summary, the replay mismatches and any breaks in pc continuity; it writes nothing unless -o is given and exits non-zero on a mismatch or a break:
saple translate crates/sable-frontends/tests/fixtures/trace-aarch64/chain_190_122.json --arch aarch64 --checkreplay of 5 steps — verified: 4, mismatch: 0, unknown: 1, unsupported: 0
replay_consistent: true
pc continuity: ok
check: acceptedChoosing the free inputs#
--symbolic-input adds inputs the verifier may choose, on top of the trace's own metadata.symbolic_inputs. Repeat it; each value is X0…X30, SP, NZCV (any case) or mem:0x<addr>:<len> with a decimal length of 1 byte to 1 MiB:
saple translate run.json --arch aarch64 -o run.spl \
--symbolic-input X0 --symbolic-input mem:0x4a0088:8An input that is not declared symbolic keeps its recorded value, so a witness can only change what the recording declares free.
2. Analyze#
The trace pattern library is not loaded automatically: pass it with --pattern-file.
saple analyze chain.spl --pattern-file patterns/aarch64-trace-v0.1.spl 4 finding(s):
1. [STRUCTURAL] HIGH — cwe_190_adds_w_into_malloc: VERIFIED at positions [2, 4]
Pattern: cwe_190_adds_w_into_malloc
Trace: adds_w → call_malloc
Verdict: VERIFIED (solver: sat, chain positions: [1,2,3,4], closure positions: [1,2,3,4])
Witness: X1=0x4a0080, mem[0x4a0088]=0xc0, mem[0x4a0089]=0xff, mem[0x4a008a]=0xff, mem[0x4a008b]=0xff, mem[0x4a008c]=0xc0, mem[0x4a008d]=0xc0, mem[0x4a008e]=0xc0
2. [STRUCTURAL] CRITICAL — cwe_122_store_past_allocation: VERIFIED at positions [5]
Pattern: cwe_122_store_past_allocation
Trace: str_x_imm
Verdict: VERIFIED (solver: sat, chain positions: [1,2,3,4,5], closure positions: [1,2,3,4,5])
Witness: X1=0x4a0080, mem[0x4a0088]=0xc8, mem[0x4a0089]=0xff, mem[0x4a008a]=0xff, mem[0x4a008b]=0xff, mem[0x4a008c]=0xc8, mem[0x4a008d]=0xc8, mem[0x4a008e]=0xc8
3. [STRUCTURAL] LOW — cwe_190_adds_signed_overflow_w: VERIFIED at positions [2]
…
4. [STRUCTURAL] LOW — cwe_190_adds_unsigned_carry_w: VERIFIED at positions [2]
…
Pattern verdicts (9 pattern(s) with a candidate):
cwe_190_adds_w_into_malloc: VERIFIED (1 candidate(s))
cwe_122_store_past_allocation: VERIFIED (1 candidate(s))
cwe_416_load_after_free: REFUTED (1 candidate(s))
cwe_476_load_from_null: REFUTED (1 candidate(s))
cwe_190_adds_signed_overflow_w: VERIFIED (1 candidate(s))
cwe_190_adds_unsigned_carry_w: VERIFIED (1 candidate(s))
cwe_190_overflow_into_store_w: REFUTED (1 candidate(s))
cwe_416_load_in_freed_block: REFUTED (1 candidate(s))
cwe_367_store_after_load_same_address: REFUTED (1 candidate(s))Finding 1: the witness loads the word 0xc0c0c0c0ffffffc0 from 0x4a0088 (little-endian bytes), whose low 32 bits plus 0x40 wrap to 0, the size passed to malloc. Finding 2: the witness makes the wrapped size 8 (0xffffffc8 + 0x40), so the 8-byte store at [x0, #8] starts at the end of the new block. Positions count the model's actions, init_memory() being position 0, so position p is trace step p - 1.
The trace itself can be analyzed directly, without a separate translate step; the sidecar is then built in memory:
saple analyze crates/sable-frontends/tests/fixtures/trace-aarch64/chain_190_122.json \
--pattern-file patterns/aarch64-trace-v0.1.splVerdicts#
Every embedding of a pattern's signature in the recorded sequence is a candidate. The verifier builds a query from the path condition up to the candidate's last matched step (its trigger), pins every memory address, library-call result and load the recording observed, adds the pattern's constraint and asks Z3:
| Verdict | Meaning |
|---|---|
VERIFIED | The trace is replay-consistent, the query is satisfiable, and every step in the candidate's causal chain has verified semantics, replays consistently and has pinned memory accesses: the witness inputs drive the recorded path into the pattern. |
OBSERVED | Either the trace is not replay-consistent — then every candidate is OBSERVED with the reason trace is not replay-consistent, whatever the solver answers — or the query is satisfiable but the evidence is weaker; the reason is given (unverified semantics in the causal chain, unpinned memory access at position p, witness needs unobserved memory at 0x…, unsupported control transfer at position p). |
UNKNOWN | The solver gave no answer (time limit, unsupported constraint, solver error), or the embedding cap was reached. |
REFUTED | Unsatisfiable: no choice of the symbolic inputs makes the pattern hold on this path. Shown only with --report-refuted (findings) and always in the pattern verdicts. |
A pattern's verdict is the strongest of its candidates: VERIFIED, else OBSERVED, else UNKNOWN, else REFUTED. A solver failure never gives REFUTED. An instruction without modelled semantics becomes an over-approximating fallback that leaves what it may write unconstrained; a candidate whose causal chain contains it can be REFUTED, OBSERVED or UNKNOWN, never VERIFIED.
Options of saple analyze for trace models: --report-refuted (also list REFUTED candidates as findings) and --trace-timeout-ms (solver time per query, 10000 by default; 0 gives the solver no time, so every query is UNKNOWN — it does not mean unlimited).
saple analyze exits 0 on a trace model even when a pattern is VERIFIED. Read pattern_verdicts in the JSON report to gate a pipeline.
Limits#
- One recording is one path: the verifier says what inputs drive this path into a pattern; branches the run did not take are
unexplored. - A library call's body is not modelled; its observed results are pinned, and what it may change otherwise is havocked.