Skip to content

Prevent rebased objects from making null addresses look mapped - #765

Closed
zardus wants to merge 1 commit into
masterfrom
feature/externzero
Closed

zardus wants to merge 1 commit into
masterfrom
feature/externzero

Conversation

@zardus

@zardus zardus commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

Problem

Loading this ARMEL blob at 0x90000000 places the extern object at zero. As a result, find_object_containing(0) reports that a null address outside the input image belongs to the extern object.

Root cause

When the mapped address space is narrower than 32 bits or the image reaches its upper half, Loader._find_safe_rebase_addr starts searching at zero even if free space remains above the image. The first suitable gap can therefore claim the null page.

Fix

Search above the image first. If that fails, search lower gaps starting at the loader's configured page_size, and use the guarded low region only when no other gap can fit the object. Calculate the limit from the mapped address width so formats such as DOS MZ can use an address space wider than their registers.

Testing

tests/test_rebase.py covers ARM and Z80 placement, the exhausted-space fallback, exact one-byte, 4 KiB, and 8 KiB page sizes, an image below the guard, and DOS MZ placement in a 20-bit address space with 16-bit registers. The one-byte regression fails if the removed 4 KiB floor is restored and passes when page_size alone defines the guard.

Fixes #745.

Validation: #765 (comment)

session: sharpen

@angr-bot

Copy link
Copy Markdown
Member

Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/cle_765

@zardus

zardus commented Aug 26, 2026 •

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

Validation record for head e9a5cf026c0d8e358bf25594c6133f3a19486d2a against baseline 7c5e1a2c1e25524863ed5e778eef63b4d8bc56a1.

Fixtures are from angr/binaries at 213d9d4c310eca1be489aefe42ab91d214cd4c6a; no fixture changes are needed. The DOS MZ regression covers placement above 0x90000 in a 20-bit mapped address space.

Regression evidence

  • pytest --import-mode=append -q tests/test_rebase.py::test_null_guard_has_no_extra_floor: 1 passed on this head. Restoring the removed max(self.page_size, 0x1000) without changing the test makes it fail with assert 4096 == 1.
  • pytest --import-mode=append -q tests/test_rebase.py tests/test_mz.py tests/test_blob.py: 22 passed through the feature's Nix environment.
  • Captured ARM placement output shows the extern object at zero on the baseline and above the image on this head.

Gate and static checks

  • ./feature.sh test pr-cle-765: exit 0, PARTIAL PASS (8 of 14 suites). The adopted-scope suites workspace, test-inputs, test-packages, pre-commit, feature-build, mono, pysoot, and cle all passed; the cle suite reported 283 passed, 9 skipped. The six unadopted component suites (archinfo, pypcode, pyvex, angr, angr-rust, and angr-management) did not run. Worktree cleanliness passed with no checkout changed.
  • nix/run.sh --feature pr-cle-765 -- python .agents/skills/angr-validate-workspace/scripts/run-ci-diff-checks.py --repository cle: no lint or type regressions across two changed files. cle/loader.py holds pylint 9.93 -> 9.93 and pyright 5 -> 5; tests/test_rebase.py holds pylint 10.00 -> 10.00 and pyright 0 -> 0.

The hosted macOS, Windows, and Pyodide jobs, downstream angr tests, and decompiler snapshots were not run locally. Hosted CI must provide that coverage on the new head.

This record replaces the earlier record for 30ce1134096691e9ea16270474530d95a797d554. Earlier corpus/CFG figures, snapshot comparisons, and cross-PR integration results were not rerun, so they do not validate this candidate. This does not mean the historical measurements were false.

Comment thread cle/loader.py Resolved
@zardus

zardus commented Aug 28, 2026 •

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

Complete extern-object placement for the ARMEL blob tests/armel/i2c_master_read-nucleol152re.bin from angr/binaries at 213d9d4c310eca1be489aefe42ab91d214cd4c6a, loaded at 0x90000000.

Reproducer (BINARIES names the fixture checkout)
import logging
import os
import cle

logging.getLogger("cle").setLevel(logging.CRITICAL)
path = os.path.join(os.environ["BINARIES"], "tests", "armel", "i2c_master_read-nucleol152re.bin")
ld = cle.Loader(path, auto_load_libs=False, main_opts={"backend": "blob", "arch": "ARMEL", "base_addr": 0x90000000})
main, extern = ld.main_object, ld.extern_object
print(f"main object   {main.min_addr:#018x}-{main.max_addr:#018x}")
print(f"extern object {extern.min_addr:#018x}-{extern.max_addr:#018x}")
print(f"find_object_containing(0x0) -> {ld.find_object_containing(0)}")
print(f"find_object_containing(0x4) -> {ld.find_object_containing(4)}")

Before — address zero belongs to the extern object:

cle 7c5e1a2
main object   0x0000000090000000-0x000000009000ff5f
extern object 0x0000000000000000-0x0000000000007fff
find_object_containing(0x0) -> <ExternObject Object cle##externs, maps [0x0:0x7fff]>
find_object_containing(0x4) -> <ExternObject Object cle##externs, maps [0x0:0x7fff]>

After — the extern object is above the image and address zero is unoccupied:

cle e9a5cf0
main object   0x0000000090000000-0x000000009000ff5f
extern object 0x0000000090100000-0x0000000090107fff
find_object_containing(0x0) -> None
find_object_containing(0x4) -> None

@zardus

zardus commented Aug 29, 2026 •

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

Resolved: rollup conflicts with #730 and #721

This pull request was excluded from every mono rollup because it broke tests in two
other green pull requests. Both failures came from assertions that pinned the
placement this change moves; neither was a behavioral disagreement. The owning
pull requests now fix those assertions.

Each fixed test still fails on its branch's merge base with the error it was
written for, so both remain effective regressions for their original defects.

Starting the rebase search above the image also changes one #730 interaction. An
outer object mapped at 0 can matter only during the null-page fallback, which a
64-bit address space never reaches. As a result, #730's _free_gaps outer-object
skip is unobservable through that path. Removing the skip on the merged tree
produced:

with the outer-object skip (as merged):  plain=0xffffffff80100000 wrapped=0xffffffff80100000 equal=True
without the outer-object skip:           plain=0xffffffff80100000 wrapped=0xffffffff80100000 equal=True

#730's _describe_range_conflict half is unaffected and stays covered by
test_outer_object_does_not_occupy_address_space.

Verification

With master + #765 + #730 + #721 at heads d160d975, 6c31c31, and d124129,
cle's whole suite reports:

257 passed, 9 skipped

session: sharpen

@twizmwazin

Copy link
Copy Markdown
Member

There is already a page size, the null page size is the same size as any other page

For narrow address spaces and images in the upper half, search above the
image before falling back below it. Use the loader's page size for the null
page guard, while allowing that page when no other gap fits.

Preserve mapped_address_bits when bounding the search. Cover ARM and Z80
placement, the exhausted-space fallback, a larger page size, and DOS MZ
placement above the 16-bit register range.
@zardus

zardus commented Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

You're right. I removed the separate null-page constant and the 4 KiB floor; the guard is now exactly self.page_size.

test_null_guard_has_no_extra_floor exhausts the space above a 16-bit image, sets page_size=1 with byte alignment, and requires the next object to start at address 1 while address zero remains unoccupied. Restoring the floor moves the object to 0x1000 and fails the test; the published candidate places it at address 1. Existing tests still cover 4 KiB and 8 KiB page sizes and the last-resort fallback to address zero.

All 22 focused loader tests pass. I also rebased the branch onto current master; the complete validation record is at #765 (comment).

@zardus zardus changed the title Keep a rebased object out of the null page Prevent rebased objects from making null addresses look mapped Oct 12, 2026
@zardus

zardus commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

Closing this pull request under the campaign scope: it does not establish qualifying impact on binaries recorded by our sweeps. We are withdrawing it from this campaign.

On one campaign-recorded object, 35 of 44 main-object function texts changed after auxiliary objects moved from below to above the unchanged main object, but status, errors, goto/return behavior, executable statement/control-flow shape, and main-object CFG counts were unchanged, and no ground truth establishes either improvement or regression.

@zardus zardus closed this Oct 12, 2026
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.

The extern object is mapped over address zero when the image sits in the top half of the address space

3 participants