Repository navigation
Conversation
GCC -O0 on SPARC V9 64-bit reads a spilled int's low byte through (fp+0x7fb)|3. The spill was deleted and the result read a slot nothing wrote, from two defects that each suffice: - Heritage's indexed-stack-pointer walk did not follow INT_OR, so the LOAD got no guard. An INT_OR with a constant below 0x1000 (the window an unrefined guard covers) is now an indexed access at the pointer's offset, like a non-constant INT_ADD. - SparcV9_64.cspec spelled its below-the-frame local range in 32 bits (0xfff0bdc1..0xffffffff), a range near 4 GiB in the 64-bit stack space. The open array at 0x7fb then ran on into the parameter range, markUnaliased reset it to unaliased at the range boundary, and symbol sync cleared the guard's address force from the spill. The range is sign-extended, as x86-64-gcc.cspec spells it. Measured: either change alone leaves the spill dead; both keep v1[0] = n. Stage test kuna-sparc64-or-masked-spill; stage baseline re-recorded (+2 keys, none removed); make test, test-stages, check-spec, lint, test-cli, rust-test and the kuna-ghidra suite pass.
Regenerated with `kuna test --datatests --datatests-dir tests/stages --save-baseline`; adds only this branch's new stage assertions.
This branch has not been deployed
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.
Problem
GCC
-O0on SPARC V9 64-bit spills anintargument and reads its low byte back through an OR-masked frame address. The spill was deleted, so the result read a stack slot nothing wrote. This independent example isint f(int n) { return n & 1; }:Before the fix the spill is gone:
Compiled and run, that returns whatever the uninitialized array holds.
Fix
Two independent defects each delete the spill:
heritage.rs (Heritage::discover_indexed_stack_pointers)followedINT_ADD,SEGMENTOP,COPY,INDIRECTandMULTIEQUALfrom the stack pointer, but notINT_OR, so theLOADgot no guard. AnINT_ORwith a constant below0x1000(the window an unrefined guard covers) is now an indexed access at the pointer's offset, like a non-constantINT_ADD; the constant is not added, sincep | clies anywhere in[p, p+c].SparcV9_64.cspecspelled its below-the-frame local range in 32 bits (0xfff0bdc1..0xffffffff), a range near 4 GiB in the 64-bit stack space. The frame's only real local range then ended at the window save area, so the open array at0x7fbran on through the parameter range,markUnaliasedreset it to unaliased at the range boundary, and symbol sync cleared the guard's address force from the spill. Bothlocalrangeentries are sign-extended, asx86-64-gcc.cspecspells the same window.Either change alone leaves the spill dead (measured). With both:
No option: the previous output is false about the program.
Tests
kuna-sparc64-or-masked-spill.xmlwith the example (0x7fb | 3 == 0x7fb, so a fix that added the constant would miss the slot).sparcv9-linux-gnuand run underqemu-sparc64fornin[-300, 300): before, wrong results at-O0and-O2; after, every value matchesn & 1at both.decompile-all, 113 executables, 23,142 functions across 10 architectures; a second base run showed no nondeterministic function): 46 functions change, all sparc64, all reviewed.0x887now ends at the frame ([540]→[40]) instead of running into the parameter range.char buf[1024]with the canary load beside it, instead of a 1708-byte array that swallowed the canary slot.ls): locals below the stack pointer are declared.sub_9140wassub_8bf0(&Stack…e7e7, …)with undeclared symbols; it is nowptr = buf; sub_8bf0(&ptr, …); if (ptr != a0 && ptr != buf) free(ptr);.ls): callers ofsub_9140pick up itschar *parameter.error/error_at_line): the third spilled variadic register (%i5) is recovered with the other two.dev-vizneeds full git history and could not run in the cluster's export.arm-none-eabi-gcc,i686-w64-mingw32-gcc; every recompiler available): no change from this PR. Each arm scores 95,698 functions, 80,402 recompilable, 15,296 not, 5,836 perfect, 0 metric errors. The default run reported 7 per-function score differences, but the decompiled C is byte-identical between arms for every binary, so they cannot come from this change. They come from the scorer's wall-clock diff timeout on large functions (inflate,template_parse,ssh_tty_parse_modes, ...). Re-scored with that timeout disabled, every pair has byte-identical original and recompiled machine code and equal scores.Timing:
kuna decompile-all --jsonover each Debian set, from node-local copies, one pinned CPU on an exclusive node, 11 rounds (2 warmups discarded), arm order rotated. Process start and spec loading are included.