Repository navigation
[AUTOMATED] fix(analysis): clamp a symbol's declared extent before narrowing it, so one hostile st_size stops costing the whole analysis commit (DIV-91) - #342
Merged
Conversation
…so one hostile st_size stops costing the whole analysis commit (DIV-91)
[AUTOMATED]
`st_size` is a 64-bit ELF field that no header check validates, so it is
attacker-controlled data. Arm 4a of `commit_analysis_output` narrowed it with
`(*size).max(1) as int4` -- clamping AFTER the truncating cast, which inspects
the wrong number. Two classes fell through:
* low 32 bits zero (0x1_0000_0000) truncates to 0, which `add_symbol_internal`
rejects. Because the commit mutates the architecture arm by arm and
propagates the first error, that one symbol abandoned every LATER arm
(prototypes, context paints, tracked registers, call-fixups, DWARF locals
and line comments) with arms 0-4 already applied in place -- and both stashes
are `mem::take`n by then, so a second `read symbols` commits nothing.
`kuna functions` exited 1 with no output.
* low 32 bits with the sign bit set (0xffff_fff0) truncates to a NEGATIVE
int4, which `TypeFactory::get_base` handed to `typecache[s as usize]` -- an
out-of-bounds index, so this was a process abort at exit 101, not an error.
The issue as filed claims this case loads clean; it does not.
Clamp into `1 ..= int4::MAX` before the cast at the one live site, apply the
same shape to the DWARF twin at arm 1a (already bounded upstream, noted in the
arm comment), and add a lower bound at both type-factory cache lookups so a
negative size is an ordinary KunaError rather than an abort. `get_base` refuses
a negative rather than falling through to `Datatype::new`, because `find_add`
then computes an alignment from `size as uint4` and overflows for s == -1.
The clamp saturates, so a 0x1_0000_0004 symbol goes from a silently-wrong
4-byte extent to a ~2 GiB one that shadows unnamed addresses above it. Measured
and stated rather than designed away: a legal st_size of 0x7fffffff already
reaches that exact state today, and it is neither an OOM nor a hang (0.47s /
53 MB, same as the sane-size control). Narrowing the extent to "distance to the
next symbol" is a heuristic that would need its own named option.
Whether one bad symbol voids the whole commit is deliberately unchanged; the
CLI-diagnostic half of GH-339 ships in the sibling fix/clidiag PR.
Closes #339 (engine half).
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1
Interleaved min-of-4 with a null control (the box was running two concurrent
workspace suites) is recorded on the DIV row.
mahaloz
force-pushed
the
fix/symbolsizeclamp
branch
from
August 27, 2026 19:19
34802c8 to
56196b2
Compare
mahaloz
added a commit
that referenced
this pull request
Aug 27, 2026
[AUTOMATED] DIV-90/91/92 were claimed by #341/#342/#344 while this branch was in flight; the row and every reference move to DIV-93. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1
mahaloz
added a commit
that referenced
this pull request
Aug 27, 2026
…e aggressive preset (DIV-93) (#345) * feat(modes): the four ARM entry-discovery options join the aggressive preset (DIV-90) cortexmvectors (#248), ptrentry (#255), tailcallentry (#259) and poolentry (#278) all shipped default-OFF and sat on the UNEVALUATED list in modes.rs, so they were absent from AGGRESSIVE_OVERRIDES. `auto` resolves to `aggressive` under 500 KiB, and the preset is what the whole-binary surfaces actually run, so all four were INERT on every default path -- the DIV-64 itaniumrtti trap, four times over. The default path's stripped-ARM entry recall had not moved since they merged. They are flipped jointly because they compose, which is exactly what the UNEVALUATED comment demanded before any flip. Measured over the 110 stripped non-x86-64 decbench twins against their unstripped twins' symbol tables (50,724 ground-truth function starts), --mode aggressive: arm entries exact midbody recall added added_exact lost_exact base 55006 44957 8333 88.63% - - - cortexm 55142 45093 8333 88.90% 136 136 0 ptr 56594 46522 8333 91.72% 1588 1565 0 tail 55655 45602 8337 89.90% 649 645 0 pool 53956 45122 7116 88.96% 167 165 0 all4 56188 47330 7117 93.31% 2402 2373 0 Recall and precision improve together: +2,373 real entries (98.8% of everything added is a real function start) while mid-body false entries FALL 8,333 -> 7,117. No ground-truth entry is lost by any arm -- poolentry's 1,217 removals contain zero ground-truth addresses. 0 of 110 binaries lose recall. Restricted to the 105 binaries `auto` actually sends to `aggressive` (< 500 KiB), the default-path number is 90.92% -> 96.06%. The 5 images at/over the threshold resolve to `reliable` and are disclosed in the DIV row rather than papered over. Non-ARM inertness is measured: identical entry sets over 90 x86-64 twins and the 12 i386 PE images in the ARM corpus, byte-identical emitted C over 8 x86-64 binaries. Speed, interleaved min-of-4: decompile-all cf2.elf -5.8% (a speedup), nuttx +3.5%, x86-64 controls at noise; discovery-only `kuna functions` +6.2%, which is more work for more output on the one surface that only does discovery. The 0/675 ablation is proven, not asserted: a throwaway build with all four forced ON as engine defaults -- strictly stronger than preset membership, which the XML harness never applies -- still reports 675/675 and 538/538 PARITY OK. Also lands PR #239's two doc corrections, repointed at the shipped feature docs rather than at its unshipped-proposal directory: the recall-measurement.md mechanism/noise correction and the missing-ghidra-analyses.md OperandReferenceAnalyzer row (its "function creation is subsumed by entry-disc" claim is what ptrentry disproved). [AUTOMATED] Generated by Claude Code. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1 * docs(decbench): retire the two round-ledger claims DIV-90 falsifies features-round4.md Rank 6 was a filed, still-open recommendation to flip `tailcallentry` into the preset ("aggressive does not carry it"); DIV-90 does exactly that, so it is marked SHIPPED with the sweep it asked for. features.md still called step 3 "in flight" and did not know about step 5 (`poolentry`, #278). [AUTOMATED] Generated by Claude Code. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1 * docs: state the ARM restriction precisely -- poolentry has no arch gate cortexmvectors/ptrentry/tailcallentry each early-return on `object::Architecture::Arm`; poolentry does not, and is ARM-only in EFFECT because it keys on PC-relative literal pools. The measured inertness is the same either way (identical entry sets on 90 x86-64 twins and 12 i386 PE images), but "all four are ARM-gated" overstated the mechanism for one of them. [AUTOMATED] Generated by Claude Code. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1 * docs(history): add the leave-one-out direction to the DIV-90 evidence Dropping each option from the combination loses 27 / 1427 / 645 / 136 ground-truth entries respectively, and dropping poolentry is the only one that also raises mid-body false entries (7117 -> 8337). No option is redundant given the others. [AUTOMATED] Generated by Claude Code. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1 * docs: renumber the ARM-preset divergence to DIV-93 [AUTOMATED] DIV-90/91/92 were claimed by #341/#342/#344 while this branch was in flight; the row and every reference move to DIV-93. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1 --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #339 (engine half).
A single data symbol whose declared
st_sizeis not representable as theint4thetype factory sizes types in cost the binary its entire analysis commit — or the
process.
st_sizeis a 64-bit ELF field that no header check validates, so it isordinary attacker-controlled data.
The defect
commit_analysis_outputarm 4a narrowed the loader's data-symbol extent with(*size).max(1) as int4— it clamps the number after truncating it, so itinspects the wrong one. Two classes fell straight through:
st_size0x1_0000_0000(low 32 bits zero)0→error: read symbols (analysis commit) failed: g_a symbol created with zero size type, exit 1, no outputg_anamed0xffff_fff0(low 32 bits sign-bit set)-16→index out of bounds: the len is 9 but the index is 18446744073709551600, exit 101g_anamed8(control)The first case is not "one symbol is dropped".
commit_analysis_outputmutates thearchitecture arm by arm and propagates the first error, so arms 0–4 stay applied
and every later arm is abandoned: library prototypes, cppsig and DWARF prototypes,
ARM/MIPS context paints, tracked register values, call-fixups, DWARF stack locals,
DWARF line comments. It is also unretryable —
pending_analysisandloader_data_objectsare bothmem::taken before the failure, so a secondread symbolscommits nothing.The second case is not in the issue. The filing claims
0xfffffff0"loads clean";it does not — it is a process abort, and it is the more severe half. Verified verbatim
on the parent commit before the fix.
The fix (strict bug fix — no option, no catalog counts, no stage XML)
kuna-console/src/engine.rsarm 4a — clamp into1 ..= int4::MAXbefore thecast. One edit closes both classes at the one live site.
d.sizecomesfrom a
Datatype::get_size()(itself anint4) filtered to>= 1, so it alreadylives in
1..=int4::MAX— but the two arms must not differ in shape, and the armcomment says why that one is already bounded upstream.
kuna-decomp/src/substrate/dtype.rs— a lower bound at both type-factory cachelookups (
get_base,get_type_char_sized), so a negative size is an ordinaryKunaErrorrather than a process abort if one ever arrives by another route.get_baserefuses a negative rather than falling through toDatatype::new:find_addthen computes an alignment fromsize as uint4, which overflows fors == -1— a second, debug-only panic on the same input. (This differs from thescouted
(0..9).contains(&s)shape for exactly that reason.)The judgment call, measured rather than designed away
The clamp saturates, so a
0x1_0000_0004symbol goes from a silently-wrong 4-byteextent to a ~2 GiB one, and a ~2 GiB
SymbolEntrywinsfind_containerfor everyaddress above it. That is a real cost and it is stated, not hidden:
Two things bound it, and both are measurements:
st_size = 0x7fffffffalready produces byte-for-bytethat output today, on the parent commit. Only symbols committed after the huge one
are absorbed (
n_6/n_8come earlier in.symtaband survive); the rest lose theirown name to a
g_huge[offset]index.fixture decompiles in 0.47 s / 53 MB peak RSS, the same as the sane-size control;
an oversize extent becomes a
TypeArraycount, never an allocation.Narrowing the extent to "distance to the next symbol" would fix the shadowing, but it
is a heuristic — a judgment call — and by the standing options contract it would need
its own named option. It is deliberately not smuggled in here.
Collateral: zero on real software, and structurally so
No
STT_OBJECTsymbol withst_size > int4::MAXexists in any ELF scanned: every/usr/binbinary (5675 files), every/usr/lib/x86_64-linux-gnushared object,tests/bug-repro/*, and all committed fixtures. No previously-loading real binaryreaches the changed path.
decompile-all --jsonbase vs branch is byte-identical ongrep, sort, faillog, libselinux.so.1, fmt_x86_64 and cpp_mangled_x86_64.
What this PR deliberately does NOT change
Whether one bad symbol voids the whole analysis commit. There are 20 in-loop
?sitesin
commit_analysis_output, each the same hazard; converting them to skip-and-collecttrades a loud failure for a quiet one and needs its own PR, a warning channel, and
probably a flag. The reported symptom — that
kuna decompileswallowed thisentirely and exited 0 with degraded C while
kuna functionsexited 1 — is theCLI-diagnostic half of GH-339 and ships in the sibling
fix/clidiagPR, whichmakes the failure loud on all surfaces. This PR does not touch
kuna-cli/src/decompile.rs, so the two do not conflict.Tests
kuna-console/tests/verify_hostile_symbol_sizes.rs— 3 e2e cases over 3 newchecked-in fixtures built reproducibly from checked-in assembly (no byte-patching),
differing only in the
st_sizeofg_a. The assertion is that the recoveredsymbol name comes back, not merely that the load returns
Ok— a silently droppedsymbol would satisfy the weaker one. Plus a
TypeFactoryunit test for the negative-sizeguards.
A/B'd against the reverted source: the two hostile cases fail with exactly the
historical error and the historical panic, and the sane-size control passes both ways.
Neither parity corpus can cover this and a green parity run is not evidence the fix
works: every fixture in
tests/datatests/andtests/stages/is a symbol-less<bytechunk>that never constructs anObjectLoadImage, so a.symtab-gated changeis unreachable from them in either direction. Correspondingly there is no new stage
XML, so no
kuna-base/src/xml.rscorpus-count bump and nobaseline-stages.jsonre-record — this PR cannot collide with the in-flight stage-test PRs.
Speed
No measurable change, and this host could not resolve one anyway. Interleaved,
alternating-arm, minimum-of-4
decompile-all --json, base vs branch:libselinux.so.1(621 fns)grep(449 fns)grepThe null control establishes the noise floor at ~4%, which is already near the 5%
budget — the box was running two concurrent workspace suites (load average 15–23 on
80 cores). Structurally the change is one extra comparison per data symbol plus one
sign test per
get_base.Gates
make testdatatests: 675/675 assertions passed/ PARITY OK (no re-pin)make test-stagesdatatests: 538/538 assertions passed/ PARITY OKmake rust-testCARGO_EXIT=0— 325 suites, 4838 passed, 0 failed, 38 ignored, 0 failure blocksmake check-speccheck-spec OK (lenient mode)+check-spec OK (strict mode)kuna catalog --checkcatalog OK: documents exactly the registered kuna optionsNo option added, so no catalog counts move. No stage XML added, so no
kuna-base/src/xml.rscorpus-count bump and nobaseline-stages.jsonre-record.DIV
DIV-90 (
docs/history.md). Warranted because the0x1_0000_0004class previouslyloaded and its shipped output changes (
g_a→g_a[0], unnamed neighbours absorbed).DIV-89 is the highest on main as of this branch; a sibling PR may claim 90 first, in
which case renumber the row and its references at merge.
🤖 Generated with Claude Code
https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1