Skip to content

[AUTOMATED] feat(p7): securitycheck — strip rustc bounds/overflow panic branches - #325

Merged
mahaloz merged 1 commit into
mainfrom
feat/rust-securitycheck
Aug 22, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/rust-securitycheck

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Ports SEFCOM Oxidizer's SecurityCheckRemover
(angr/rust/optimization_passes/security_check_remover.py, whose work lives in the
CFAMixin::match_call / CFGTransformationMixin::remove_block mixins it composes) as
the kuna option securitycheck (P7 edge-virtualization, default ON, DIV-82).

rustc emits a check in front of every slice index, every string slice and every
non-constant / or %. Each lowers to a conditional branch to a small block that loads
the panic Location, calls one of seven helpers declared -> ! in libcore, and diverges.
Ghidra has no notion of them, so kuna rendered the guard and the call verbatim in front of
every array access — roughly doubling the CFG of ordinary Rust code.

// option securitycheck off                     // default (on)
void app::transpose(...) {                      void app::transpose(...) {
  ...                                             ...
  do {                                            do {
    if (a1 <= v1)                                   *(char *)(a2 + v3) = *(char *)(a0 + v1);
      panic_bounds_check(); // no-return            v3 += a4;
    if (a3 <= v3)                                   v1 += 1;
      panic_bounds_check(); // no-return            v5 -= 1;
    *(char *)(a2 + v3) = *(char *)(a0 + v1);      } while (v5);
    ...                                           ...

How

Two parts under the one option.

  1. The divergence fact (ArchFlowEnv::query_call_no_return, infra/decompile_drive.rs)
    — a call to one of the seven is reported no-return from its NAME. The same hook, the
    same shape and the same one-list discipline as the already-default-on
    noreturn_externmatch. Needed because kuna's address-keyed no-return discovery only
    proves divergence for the helper bodies it can walk, and the ones it misses leave a
    returning panic block that part 2 correctly declines to touch. Without it roughly
    half the checks survive.
  2. The edge removal (p7_regions/kuna_securitycheck.rs, ActionRemoveSecurityCheck)
    — Funcdata::remove_branch + remove_unreachable_blocks, the same primitive pair,
    the same sub-stage and the same destructive/transform contract as DIV-14's
    stackguard, scheduled immediately after it in fullloop's returnsplit group.

Safety envelope. The arm is removed only when it is a basic block that diverges
(size_out() == 0 — so nothing downstream, and in particular no return, depends on it)
and contains exactly one call, whose callee is one of the seven. A second call rejects
it. Either branch polarity is accepted; the arm is identified by what it contains, never
by the branch sense. A block also reachable another way is never orphaned —
remove_unreachable_blocks collects it only when no predecessor remains.

Name matching. On the path PREFIX before the first < (so
slice_start_index_len_fail<usize> matches), with a legacy ::h<16 hex> trimmed, and
accepting a whole-::-component suffix down to the bare leaf — which is a shape kuna's
ELF symbol path really produces. core::str::slice_error_fail_rt is a different leaf and
never matches.

Why default-ON with no compiler-detection channel. All seven names exist nowhere but
Rust, so on a C binary both halves are structurally inert. No loader→engine compiler
channel is built (none exists).

Measured

Witness: a rustc -O -C relocation-model=static binary (551 functions, slice/str/div
work).

off on
emitted panic-helper calls 24 7 (17 removed)
emitted lines 41,788 41,689 (-99)
if ( guards 4,396 4,370 (-26)
gotos 1,390 1,385 (-5)
functions hitting the 10 s watchdog 9 8

9 functions change; every one indexes a slice. One function that previously hit the
per-function watchdog (std::backtrace_rs::symbolize::gimli::Context::new) now completes.

Zero collateral on C. Whole-binary decompile-all --json over
tests/bug-repro/{faillog,grep,sort,libselinux.so.1} and tests/fixtures/fid/prog
(2,688 functions) is byte-identical on/off — 0 differing code fields.

Speed (interleaved, min-of-N): C grep whole-binary 14.240 s -> 14.190 s (-0.35%,
N=5), C sort 7.960 s -> 7.990 s (+0.38%, N=5), the Rust witness whole-binary
131.34 s -> 132.29 s (+0.72%, N=3 — and the ON side decompiles one MORE function, the
watchdog rescue above), per-function app::transpose / app::ratios +0.00% (N=5). All
well inside the +5% budget.

One visible second-order effect: a length argument whose only reader was the removed
compare becomes genuinely unused, so parameter recovery may trim it from the signature —
the same trade stackguard makes with the canary slot, and the reason the option exists.
Documented in the option's use_when, the module doc, the spec and the DIV row.

Known limit (reported, not fixed here)

The trigger needs a recovered callee name. In a default (PIE, dynamically linked) Rust
binary the helper is reached through a .got slot whose R_X86_64_RELATIVE relocation
kuna never applies, so the call is an unnamed CALLIND and the pass is a measured no-op
there (0 changes on private/FakeCrypt, all 263 of whose panic call sites are
GOT-indirect). Closing that is an ELF sibling of the peimportcall pass — a separate
feature.

Gates

  • make test — 675/675, PARITY OK
  • make test-stages — 496/496, PARITY OK (baseline re-recorded for the new stage file)
  • make rust-test — green (317 test binaries, 0 failures)
  • make check-spec — green, --strict green
  • kuna catalog --check — catalog OK

tests/stages/oxidizer-securitycheck.xml is the two-pass testcase (off = the guard and
the panic_bounds_check call; on = neither, with the guarded load untouched).

Catalog counts written

settables 111 → 112; surfaces 102 → 103; tiers (core, transform, analysis)
(24, 48, 39) → (24, 49, 39); catalog JSON },\n 110 → 111; bytecompat fixture
111 → 112 (x3); kuna-catalog.xml source_decompiler="angr" 31 → 32,
change_kind="opt-in-tool" 14 → 15; stage corpus file count 209 → 210; universal
action-tree leaves 272 → 273.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WUuE4zdiEqZFWLL2YEUk9

…ic branches

Ports SEFCOM Oxidizer's SecurityCheckRemover (angr
angr/rust/optimization_passes/security_check_remover.py, whose work lives in the
CFAMixin::match_call / CFGTransformationMixin::remove_block mixins it composes) as
`option securitycheck` (P7 edge-virtualization, default ON, DIV-82).

rustc emits a check in front of every slice index, every string slice and every
non-constant `/` or `%`; each lowers to a conditional branch to a small diverging
block that calls one of seven `-> !` helpers in libcore. Ghidra has no notion of
them, so kuna rendered the guard and the call verbatim in front of every array
access.

Two parts under one option:

1. The divergence fact (ArchFlowEnv::query_call_no_return) reports a call to one of
   the seven no-return from its NAME -- the same hook, shape and one-list discipline
   as the default-on noreturn_externmatch. kuna's address-keyed no-return discovery
   only proves divergence for the helper bodies it can walk, and the ones it misses
   leave a *returning* panic block that part 2 correctly declines to touch.
2. p7_regions/kuna_securitycheck.rs (ActionRemoveSecurityCheck) severs the CBRANCH
   edge to a diverging basic block whose single call is one of the seven, with
   Funcdata::remove_branch + remove_unreachable_blocks -- the same primitive pair,
   sub-stage and destructive/transform contract as DIV-14's stackguard, scheduled
   immediately after it in fullloop's returnsplit group.

The match is on the path PREFIX before the first `<` (so
slice_start_index_len_fail<usize> matches), with a legacy ::h<16 hex> trimmed, and
accepts a whole-`::`-component suffix down to the bare leaf; slice_error_fail_rt is
a different leaf and never matches. All seven names exist nowhere but Rust, so both
halves are structurally inert on a C binary -- which is what lets it default ON with
no compiler-detection channel from the loader (none exists, and this builds none).

Measured on a rustc -O binary (551 functions): 17 of 24 emitted panic-helper calls
removed, -99 emitted lines, -26 `if (` guards, -5 gotos, and one function that
previously hit the 10 s per-function watchdog now completes. Zero collateral on C:
whole-binary decompile-all over tests/bug-repro/{faillog,grep,sort,libselinux.so.1}
and tests/fixtures/fid/prog (2,688 functions) is byte-identical on/off. Speed
(interleaved, min-of-N): grep -0.35%, sort +0.38%, the Rust witness +0.72%.

Gates: make test 675/675 PARITY OK; make test-stages 496/496 PARITY OK (baseline
re-recorded for the new stage file); make rust-test green; make check-spec green
(--strict green); kuna catalog --check OK.

Known limit, reported not fixed: the trigger needs a recovered callee name, and in a
default (PIE, dynamically linked) Rust binary the helper is reached through a .got
slot whose R_X86_64_RELATIVE relocation kuna never applies, so the call is an
unnamed CALLIND and the pass is a measured no-op there. Closing that is an ELF
sibling of the peimportcall pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016WUuE4zdiEqZFWLL2YEUk9
@mahaloz
mahaloz force-pushed the feat/rust-securitycheck branch from 11913b5 to 6c0723b Compare August 22, 2026 04:47
@mahaloz
mahaloz merged commit df227e8 into main Aug 22, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/rust-securitycheck branch August 22, 2026 04:51
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