Skip to content

[AUTOMATED] Reject stated jump destinations whose labels depend on the load address or code segment - #1933

Merged
mahaloz merged 4 commits into
Noelo-Lab:mainfrom
phix33:fix/stated-jump-load-placement
Nov 24, 2026
Merged

mahaloz merged 4 commits into
Noelo-Lab:mainfrom
phix33:fix/stated-jump-load-placement

Conversation

@phix33

@phix33 phix33 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

The problem

A jumptable assertion still labels cases with mapped addresses on images whose code runs elsewhere when the loader is not the ELF, PE or Mach-O one. This DOS executable jumps through ax; DOS picks its segment at load time, and the C compares the 16-bit offset with linear addresses it can never equal.

(
  image=$(mktemp ./dos.XXXXXX)
  trap 'rm -f "$image"' EXIT
  printf '%s\n' 4d5a2a0001000000020000000000000000010000000000001c00000000000000ffe0b80b00c3b81600c3 | xxd -r -p >"$image"
  kuna decompile "$image" 0x10000 --addr --assert 'jumptable 10000 10002 10006'
)
  unsigned short v1; // ax

  switch((unsigned int)v1) {
    case 0x10002:
      return 0xb;
    case 0x10006:
      return 0x16;

A UEFI TE image with base relocations prints the same kind of cases, and so does any segmented real-mode jump, raw image included. A jump that takes a 16-bit value does too: jmp far [bx] at 0x10000 prints case 0x10002: against a 16-bit load, and a 32-bit jmp ax stated as reaching 0x401003 prints case 0x1003:.

The fix

  • Every loader now states whether code can move, and the engine assumes it can until a loader proves a fixed placement or the caller states the base of a raw or XML image. A TE image with a base-relocation directory and an MZ executable reject the directive with the existing reason, runtime load base is unknown for this image.
  • A branch input computed by the address space's segment operation also rejects the directive, because its C is the offset within the code segment.
  • A destination wider than the value the jump takes, after the zero extensions in its instruction, rejects the directive. A destination that fits still labels its case.
  • The function then decompiles exactly as without the directive, and --assert-strict fails.

Tests

tests/stages/kuna-stated-jump-placement.xml pins the rejection of a real-mode near jump, a far jump above 0xffff and the MZ fixture, and the cases of a far jump whose destinations fit. The CLI tests cover TE images with and without a base-relocation directory, an MZ executable, and real-mode and 32-bit jumps whose output must equal the unhinted run. Both fail on main, which prints the cases. A microMIPS language still accepts a 4-aligned destination.

Known limitation

MIPS16e and microMIPS destinations cannot be stated yet. jr clears the mode bit from its operand, and the directive has no way to say that a destination is compressed code, so each destination is checked against the mode its context already holds. A 2-byte-aligned destination, or its odd mode-bit form, is rejected:

(
  image=$(mktemp ./jump.XXXXXX)
  trap 'rm -f "$image"' EXIT
  printf '%s\n' 03200008000000002402000b03e00008000000002402001603e0000800000000 | xxd -r -p >"$image"
  kuna decompile "$image" 0x100 --addr --raw-image --base 0x100 \
    --target MIPS:BE:32:micro --assert 'jumptable 100 108 10a'
)
warning: --assert "jumptable 100 108 10a" rejected: address 0x10a violates 4-byte instruction alignment

A follow-up can accept a destination's ISA mode and set it before flow, which ARM interworking needs as well.

Model: anthropic/claude-opus-5-5

@phix33
phix33 force-pushed the fix/stated-jump-load-placement branch from 080ce68 to 7cab440 Compare November 24, 2026 11:59
mahaloz and others added 3 commits November 24, 2026 12:16
…segmented

A real-mode or 16-bit protected-mode destination is an offset in a code
segment: CS for a near jump, the loaded segment for a far one. SLEIGH lifts
the prefixed near jumps (67/66 67 ff /4) and the far jump (ff /5) without the
segment operation, so the producer check accepted them and labelled cases
with linear addresses the jump's value cannot equal (for example `case
0x10004:` against `eax` for `jmp eax` at 0x10000).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
… near jumps

The placement stage test now expects all three real-mode jumps rejected as
segmented; the CLI test adds the far jump at 0x100 and a prefixed `jmp eax`,
and keeps the 32-bit `jmp ax` as the width rule's accepted case. cli.md,
spec 02 and the stages README describe the rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@mahaloz

mahaloz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed e7c2c4c on top of your rebased head 7cab440 (no force). It merges main e033b33 (xml.rs count 901, stage baseline) and adds two commits: every computed branch of a 16-bit x86 language is now rejected as segmented. SLEIGH lifts the prefixed near jumps (67 ff /4, 66 67 ff /4) and the far jmp far [bx] without the segment operation, so the producer check let them through with labels the jump's value cannot equal. Repro on 7cab440:

printf '\x66\x67\xff\xe0\x66\xb8\x0b\x00\x00\x00\xc3\x66\xb8\x16\x00\x00\x00\xc3' > eax.bin
kuna decompile eax.bin 0x10000 --addr --raw-image --target 'x86:LE:16:Real Mode:default' \
  --base 0x10000 --assert 'jumptable 10000 10004 1000b'

It printed case 0x10004: against eax, but the raw image runs at CS 0x1000, so eax is 4 at that destination. The far jump at 0x100 with destinations that fit 16 bits is now rejected for the same reason (its loaded segment is unknown). The placement stage test, the CLI test, cli.md, spec 02 and the stages README follow; the 32-bit jmp ax remains the width rule's accepted case.

@mahaloz
mahaloz merged commit d9d0e4a into Noelo-Lab:main Nov 24, 2026
2 checks passed
mahaloz added a commit to phix33/kuna that referenced this pull request Nov 24, 2026
@phix33
phix33 deleted the fix/stated-jump-load-placement branch November 25, 2026 20:24
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.

2 participants