Repository navigation
[AUTOMATED] fix(p6): close GH-180 - overflow guards read the pre-add operands (verified fixed by DIV-47; regression pinned) - #304
Merged
Conversation
[AUTOMATED] GH-180's illegal pre-add/post-add merge (the SCARRY input and the ADD output printing as one variable, so the emitted guard tested the post-add value) was fixed by the DIV-47 cover restorations in #228, which never referenced the issue. This closes the loop: every witness and the issue's whole scope table re-verified at zero on current main (including the non-vendored decbench gzip/diff/tar binaries), the shipped fix audited against the pinned upstream rev, and the corrected contract pinned by a stage testcase: grep nlscan's verbatim bytes plus the minimal unsigned add/jb growth-guard form; the SCARRY8/CARRY8 guards must keep their PRE-add operands and the collapsed self-update-then-test rendering must not appear. Bookkeeping: corpus file count 204 -> 205 (kuna-base xml.rs), stages baseline re-recorded 460 -> 468 keys, README row added. No engine code change, no option, no DIV row. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq
mahaloz
added a commit
that referenced
this pull request
Aug 16, 2026
…T effect (GH-181) [AUTOMATED] Two stacked correctness fixes, no new option: 1. Port the upstream Merge::snipReads carve-out (merge.cc:461, "snip must come after OP CAUSING EFFECT") that kuna's do_snip_reads_insert_point dropped: a cover-trim COPY of an INDIRECT-defined Varnode is inserted after the op iop-encoded in the INDIRECT's input 1 (the call), not at the INDIRECT marker, which precedes the call in block order. Without it, libselinux lsetfilecon_raw's out-parameter copy printed above the lgetfilecon_raw call that fills the slot, so freecon() consumed the pre-call NULL. Audited the other upstream sites: trimOpOutput already had the arm; eliminateIntersect/snipOutputInterference already used indirect_effect_op; mergeIndirect/trimOpInput match upstream. 2. Close the matching reordering hazard in kuna's own foldcallret (default-on, DIV-14): an op strictly between a call and its lone use that reads a value the call indirectly writes (an input defined by a CPUI_INDIRECT whose iop input names the call) is now a fold barrier, so the call expression is not sunk past the very copy fix 1 places after it. Marker ops are skipped (a later call's INDIRECTs chain the earlier call's versions without a textual evaluation point). New two-pass stage test gh181-snipreads-indirect.xml (default proves both fixes; option foldcallret off isolates fix 1) plus a README row; corpus count recounted to 206 on the rebased tree; baseline-stages re-recorded (473/473 on post-#306 main, including #304's eight GH-180 assertions; this branch's stage patterns are number-agnostic, so #306's canary renumbering required no re-pinning). Three stage tests pinned renderings the fixes legitimately changed and were updated with comments: ghangr-x8664-cvs-863633 (slot 0x58 now merge-coalesced even with dedupvardecls off), ghangr-morton-my-message-callback (renumbering; the bogus self-assign artifact is gone), ghdec-symbol-keyed-local-decls (the checksum call is now sequenced before the CONCAT13 reading the slot it may write). Spec prose added to docs/spec/06-variables-and-merge.md. Gates: make test PARITY OK (675/675), make test-stages PARITY OK, make rust-test green, make check-spec green. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq
mahaloz
added a commit
that referenced
this pull request
Aug 16, 2026
…T effect (GH-181) (#307) [AUTOMATED] Two stacked correctness fixes, no new option: 1. Port the upstream Merge::snipReads carve-out (merge.cc:461, "snip must come after OP CAUSING EFFECT") that kuna's do_snip_reads_insert_point dropped: a cover-trim COPY of an INDIRECT-defined Varnode is inserted after the op iop-encoded in the INDIRECT's input 1 (the call), not at the INDIRECT marker, which precedes the call in block order. Without it, libselinux lsetfilecon_raw's out-parameter copy printed above the lgetfilecon_raw call that fills the slot, so freecon() consumed the pre-call NULL. Audited the other upstream sites: trimOpOutput already had the arm; eliminateIntersect/snipOutputInterference already used indirect_effect_op; mergeIndirect/trimOpInput match upstream. 2. Close the matching reordering hazard in kuna's own foldcallret (default-on, DIV-14): an op strictly between a call and its lone use that reads a value the call indirectly writes (an input defined by a CPUI_INDIRECT whose iop input names the call) is now a fold barrier, so the call expression is not sunk past the very copy fix 1 places after it. Marker ops are skipped (a later call's INDIRECTs chain the earlier call's versions without a textual evaluation point). New two-pass stage test gh181-snipreads-indirect.xml (default proves both fixes; option foldcallret off isolates fix 1) plus a README row; corpus count recounted to 206 on the rebased tree; baseline-stages re-recorded (473/473 on post-#306 main, including #304's eight GH-180 assertions; this branch's stage patterns are number-agnostic, so #306's canary renumbering required no re-pinning). Three stage tests pinned renderings the fixes legitimately changed and were updated with comments: ghangr-x8664-cvs-863633 (slot 0x58 now merge-coalesced even with dedupvardecls off), ghangr-morton-my-message-callback (renumbering; the bogus self-assign artifact is gone), ghdec-symbol-keyed-local-decls (the checksum call is now sequenced before the CONCAT13 reading the slot it may write). Spec prose added to docs/spec/06-variables-and-merge.md. Gates: make test PARITY OK (675/675), make test-stages PARITY OK, make rust-test green, make check-spec green. Claude-Session: https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq Co-authored-by: Claude Fable 5 <[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.
Fixes #180
Summary
GH-180 reported that kuna printed an overflow guard after the add it guards, on the
same variable —
v3 = v3 + v1; if (SCARRY8(v3,v1))— a predicate the binary does notcompute (the hardware OF at grep's
0x7ce0comes from the pre-add operands). The IRwas correct; the pre-add Varnode (the SCARRY input) and the ADD output were illegally
merged into one HighVariable.
Investigating on current
main: the code fix already landed in #228 (DIV-47, merged2026-08-01), which restored exactly the two dropped halves this issue diagnosed —
ActionMarkImpliednow goes throughMerge::mark_implied(upstreammerge.cc:1595,operand cover-dirtying), and the
MergeContext::vn_set_cover_dirtybridge forwards aVarnode
coverdirtyto the owning HighVariable the way upstreamVarnode::setFlagsdoes (
varnode.cc:377-378). #228 was driven by two different decbench witnesses(
ocsptool,ptx) and never referenced this issue, so GH-180 stayed open with itswitnesses unverified and unpinned.
This PR completes GH-180 end-to-end: it re-verifies every witness and the issue's whole
scope table against current
main, audits the shipped fix against the pinned upstreamrev, and adds the missing stage regression testcase pinning the corrected contract. No
engine code changes; no option and no DIV row (the shipped fix is a strict correctness
fix restoring upstream behavior, recorded as DIV-47 by #228).
Root cause (recap, re-verified against the pinned GHIDRA_REV)
Cover::rebuild(upstreamcover.cc:477) walks forward through implied consumers,so an operand of an inlined expression stays live until the point where that expression
is printed — here the implied
SCARRY8prints at the CBRANCH, so the pre-add value islive across the ADD output's definition and the merge is illegal. That protection only
fires if implied-marking invalidates the operands' Covers: upstream
Merge::markImpliedmarks every operand of the defining opcoverdirty, andVarnode::setFlagsforwards that tohigh->coverDirty(). The kuna port hadMerge::mark_impliedsitting with zero callers and no high-forward, soHighIntersectTest::update_highshort-circuited on covers computed beforeimplied-marking, and
ActionMergeAdjacent/ActionMergeTypesaw boundary-onlyintersection where a real conflict exists. #228 wired both halves; I verified each
against
coreaction.cc:3524,merge.cc:1595-1605, andvarnode.cc:371-380at thepinned rev (upstream has exactly one
markImpliedcall site, and so does kuna).Design note on the second half: upstream fires the forward inside
Varnode::setFlags;kuna's
Varnode::set_flagsis a W7 stub because a Varnode cannot reachFuncdata::high_bank. The #228 bridge forward atvn_set_cover_dirtyis the faithfulequivalent:
Merge::markImpliedis the only post-heritage site that setscoverdirtyon another Varnode, and
vn_set_cover_dirtyis its only entry point in kuna, so theforward is observationally identical to completing the stub — without inventing a new
Varnode-to-HighBank back-reference the W7 architecture deliberately avoids.
Load-bearing check (why the new test pins the outcome, not the seam)
Reverting the
ActionMarkImpliedwiring on current HEAD (back to bareset_implied()):independent_selects_do_not_share_one_variableregression test fails — thewiring is still load-bearing on HEAD;
mainchangesindependently leave those covers dirty at merge time, so the specific seam is no
longer the only protection for this shape.
The new stage testcase therefore pins the user-visible contract (guards read the
pre-add operands; the collapsed self-update-then-test rendering must not appear), which
catches a regression of this bug through any future seam.
Witnesses (before = issue, after = current main + this branch)
grepnlscan@0x7c90(in-repotests/bug-repro/grep):grep@0x1f0d0:v2 = v3 + v1; if (!CARRY8(v3,v1))— pre-add.grep@0x1f160:v3 = v4 + v2; if (!CARRY8(v4,v2))— pre-add.gzip@0xf320(decbench):v2 = v3 + v1; if (!CARRY8(v3,v1))— pre-add. All match Ghidra's rendering.Scope scan (the issue's regex,
X = X ± Y;thenSCARRY|SBORROW|CARRY(X,Y)within 3 lines)Over
kuna decompile-all --jsonon current code:gzip/diff/tar are not vendored in
tests/bug-repro/; they were verified from the localdecbench checkout (
results/full_run/O2/<pkg>/stripped/), byte-for-byte the binariesthe issue measured.
Regression test
tests/stages/gh180-implied-cover-scarry.xml(single pass — no option exists to flip astrict correctness fix): the verbatim
nlscanwitness bytes (0x7c90..0x7d05, paddingreplaced by RET;
memchrand the no-return stub as single-RET stand-ins at the realcall targets), plus a minimal synthetic of the unsigned
add/jbxalloc-growth form.Eight asserts: both guards keep their PRE-add operands with the sum a separate later
expression (3-line order-pinning matches), exactly one
SCARRY8/standaloneCARRY8each, and four negative pins that the collapsed
v += w; if (CARRY(v,w))rendering(compound and plain spelling) does not appear.
Bookkeeping: corpus file count 204 -> 205 in
kuna-base/src/xml.rs,docs/baseline-stages.jsonre-recorded (460 -> 468 keys, only the 8 newGH180keysadded), row added to
tests/stages/README.md. The spec prose for the implied-markingcover-dirty semantics already landed with #228 in
docs/spec/06-variables-and-merge.md(the implied-consumer forward walk and the coverdirty forward), so no spec change is
needed;
make check-specis green.Collateral audit
decompile-all --jsonon grep/sort/faillog/libselinux.so.1 with the base (main)binary vs this branch's binary: decompiled C positionally identical on all four
binaries, zero changed functions — as expected for a test-only change.
Gates
make testmake test-stagesmake rust-testmake check-specNo
docs/baseline.jsonre-pin; the stages baseline re-record is the sanctionedadd-a-testcase procedure.
Speed
No engine code changes, so the two binaries are built from identical decompiler
sources. Measured anyway (interleaved,
decompile-all tests/bug-repro/grep --json,under concurrent sibling-agent build load): min-of-11 base 13.63s vs branch 14.10s
(+3.4%), order-swapped min-of-7 base 16.05s vs branch 15.51s (-3.4%) — i.e. no
delta, within measurement noise, as expected for a test-only change.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq