Skip to content

Avoid Universal2 load failures when 0x400000 is occupied - #776

Open
zardus wants to merge 1 commit into
masterfrom
feature/main-binary-base
Open

zardus wants to merge 1 commit into
masterfrom
feature/main-binary-base

Conversation

@zardus

@zardus zardus commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

Problem

cle.Loader can assign the occupied conventional base to a second
main-marked position-independent object. Memory insertion then raises
ValueError: Address 0x400000 is already backed!.

A container backend loads its children through the loader. In a main Universal2
load, the selected Mach-O slices are marked as main binaries. Two main-marked
child objects loaded beside binaries/tests/i386/manysum show the collision:

    first  0x400000-0x400fff
    second 0x400000-0x400fff  ON TOP OF THE FIRST

On binaries/tests/multi_arch/fauxware_macho_multiarch, the i386 slice also
lands on the container object:

Universal2   0x400000-0x400000 is_main_bin=True
MachO        0x400000-0x40ffff is_main_bin=True
ExternObject 0x500000-0x500030 is_main_bin=False
MachO        0x100000000-0x100003fff is_main_bin=True

Cause

_map_object checks whether custom and linked ranges are free. It does not
check the range before assigning 0x400000 to another main-marked
position-independent object:

            elif not obj.is_main_bin:
                base_addr = self._find_safe_rebase_addr(obj_size)
            else:
                base_addr = 0x400000

Fix

Check whether 0x400000 is free before using it. If it is occupied, use the
existing safe-rebase search. A lone main object still receives the conventional
base when it has no custom or nonzero linked base.

    first  0x400000-0x400fff
    second 0x8200000-0x8200fff
Universal2   0x400000-0x400000 is_main_bin=True
MachO        0x500000-0x50ffff is_main_bin=True
ExternObject 0x600000-0x600030 is_main_bin=False
MachO        0x100000000-0x100003fff is_main_bin=True

Affected samples

The campaign record identifies five affected samples:

  • 19be29f38a574b5b1448a6256f2cec0f2ed850c750792dd46a57fa4a37b8e4ea — The sample cannot be shared.
  • 1a74eab65c67676a4584c7316929054cc861bc6dbad65ebb9d8f530e9da9e3a8 — The sample cannot be shared.
  • 24e042930c58dbc0c832f896b2569fa6e2160bd86cb877d2d476621fa9159577 — The sample cannot be shared.
  • 7389f21dcf8406ea78817e5ed47985b2eeff59beb92e617879cbd90febb2f13e — The sample cannot be shared.
  • 751e8656af24f4a5af5614167071c326df333c4046466573e9b34d61eb715908 — The sample cannot be shared.
Campaign commands
./nix/run.sh --env-link scratch/campaign/jobs/j-523/evidence/env-base --tools-link scratch/campaign/jobs/j-523/evidence/tools --repos-root /home/yans/angr/nonagentic --no-build -- python3 -P scratch/campaign/jobs/j-461/work/scripts/measure_loads.py --jobs scratch/campaign/jobs/j-461/work/out/regression_jobs.jsonl --out scratch/campaign/jobs/j-523/evidence/base.jsonl --workers 4 --timeout 300
./nix/run.sh --env-link scratch/campaign/jobs/j-523/evidence/env-head --tools-link scratch/campaign/jobs/j-523/evidence/tools --repos-root /home/yans/angr/nonagentic --no-build -- python3 -P scratch/campaign/jobs/j-461/work/scripts/measure_loads.py --jobs scratch/campaign/jobs/j-461/work/out/regression_jobs.jsonl --out scratch/campaign/jobs/j-523/evidence/head.jsonl --workers 4 --timeout 300
python3 -P scratch/campaign/jobs/j-461/work/scripts/compare.py scratch/campaign/jobs/j-461/work/out/regression_selection.jsonl scratch/campaign/jobs/j-523/evidence/base.jsonl scratch/campaign/jobs/j-523/evidence/head.jsonl scratch/campaign/jobs/j-523/evidence/compare.json

#674 would limit the default universal load to one slice. It would hide this
case without fixing the unchecked placement.

Campaign record: #776 (comment)

@zardus

zardus commented Aug 23, 2026 •

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

This record compares head 3443309fefc6d821bcac352beaf23002d6026a50
with baseline 46a37333f4f59b0facf8774ee743ebc4cc074e9b.

Five campaign samples raise ValueError on the baseline because
0x400000 is already backed. Each sample loads as Universal2 on the
head.

SHA-256 Availability Before After
19be29f38a574b5b1448a6256f2cec0f2ed850c750792dd46a57fa4a37b8e4ea The sample cannot be shared. loaded=false; exception=ValueError; message=Address 0x400000 is already backed!; site=memory.py:248:add_backer loaded=true; backend=Universal2; mapped_base=4194304
1a74eab65c67676a4584c7316929054cc861bc6dbad65ebb9d8f530e9da9e3a8 The sample cannot be shared. loaded=false; exception=ValueError; message=Address 0x400000 is already backed!; site=memory.py:248:add_backer loaded=true; backend=Universal2; mapped_base=4194304
24e042930c58dbc0c832f896b2569fa6e2160bd86cb877d2d476621fa9159577 The sample cannot be shared. loaded=false; exception=ValueError; message=Address 0x400000 is already backed!; site=memory.py:248:add_backer loaded=true; backend=Universal2; mapped_base=4194304
7389f21dcf8406ea78817e5ed47985b2eeff59beb92e617879cbd90febb2f13e The sample cannot be shared. loaded=false; exception=ValueError; message=Address 0x400000 is already backed!; site=memory.py:248:add_backer loaded=true; backend=Universal2; mapped_base=4194304
751e8656af24f4a5af5614167071c326df333c4046466573e9b34d61eb715908 The sample cannot be shared. loaded=false; exception=ValueError; message=Address 0x400000 is already backed!; site=memory.py:248:add_backer loaded=true; backend=Universal2; mapped_base=4194304

The other 482 campaign-recorded Mach-O objects have the same outcome and
metadata on both revisions. Of those objects, 345 load and 137 are refused.
None get worse.

An earlier record covered a separate group of six universal Mach-O libraries.
Each file has x86-64 and arm64 MH_DYLIB slices with __TEXT at vmaddr 0.
The baseline assigns both slices to 0x400000. The head places the slices
side by side.

SHA-256 Availability
1a74eab65c67676a4584c7316929054cc861bc6dbad65ebb9d8f530e9da9e3a8 The sample cannot be shared.
28b95a44763254ec212839e8555abb609a25ef29b2409876c5aa443aa07dbce1 The sample cannot be shared.
40ef7b22b7c6b30a61de0787bc4823caf1a890c50bca0470b0fd2ea14cd3fc77 The sample cannot be shared.
62f48bc807392ffc0b5bc751cd4e3ea6d5c647bf613b3eb8f73997dd46b359cd The sample cannot be shared.
7389f21dcf8406ea78817e5ed47985b2eeff59beb92e617879cbd90febb2f13e The sample cannot be shared.
c0977b28a37f7e26faf396ba71a71451dfcf5069c4934f65696f3e8091e7d531 The sample cannot be shared.

@angr-bot

Copy link
Copy Markdown
Member

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

Every other placement in _map_object asks the address space first. The
position-independent main binary does not: it takes 0x400000 unconditionally,
which is right while it is the only object being placed and wrong as soon as it
is not.

A container backend loads its children through the loader, and a child can come
out marked as the main binary. Universal2 marks every slice it loads, because a
Mach-O executable refuses to load as anything else. The slices of a universal
Mach-O therefore all asked for 0x400000, the first one got the backer, and the
rest failed with "Address 0x400000 is already backed!". Six universal Mach-O
libraries in a corpus sweep failed to load this way.

Ask _is_range_free first and fall back to the ordinary rebase search, so the
main binary keeps its conventional base whenever that base is available.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@zardus
zardus force-pushed the feature/main-binary-base branch from 6f08fcb to 3443309 Compare August 26, 2026 22:46
@zardus

zardus commented Aug 28, 2026 •

Copy link
Copy Markdown
Member Author

THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS

These public fixtures show two forms of the same collision. One loads two child
objects marked as main. The other loads a main universal Mach-O whose backend
marks both selected slices as main. Both fixtures are on binaries master.

Reproducer
import logging, os
logging.getLogger("cle").setLevel(logging.CRITICAL)
import cle

BIN = os.environ["BINARIES"]   # a checkout of angr/binaries
T = lambda *p: os.path.join(BIN, "tests", *p)

path = T("multi_arch", "fauxware_macho_multiarch")
ld = cle.Loader(path, auto_load_libs=False)
for o in ld.all_objects:
    print(f"{type(o).__name__:<12} {o.min_addr:#x}-{o.max_addr:#x} is_main_bin={o.is_main_bin}")
print("--- two container children both marked as the main binary")
class Mock(cle.backends.Backend):
    def __init__(self, size, **kw):
        super().__init__("/dev/zero", None, **kw)
        self.size = size
        self.pic = True
        self.has_memory = False
    @property
    def max_addr(self):
        return self.mapped_base + self.size - 1
ld2 = cle.Loader(T("i386", "manysum"), auto_load_libs=False)
first = Mock(0x1000, arch=ld2.main_object.arch, is_main_bin=True)
second = Mock(0x1000, arch=ld2.main_object.arch, is_main_bin=True)
ld2.dynamic_load(first)
print(f"    first  {first.min_addr:#x}-{first.max_addr:#x}")
try:
    ld2.dynamic_load(second)
    print(f"    second {second.min_addr:#x}-{second.max_addr:#x}"
          f"{'  ON TOP OF THE FIRST' if second.min_addr <= first.max_addr else ''}")
except Exception:  # noqa: BLE001
    print("    second: EXCEPTION: " + traceback.format_exc().strip().splitlines()[-1])

Before

At 46a37333f4f59b0facf8774ee743ebc4cc074e9b, the loader uses
0x400000 without checking it. The second main object lands on the first.

Universal2   0x400000-0x400000 is_main_bin=True
MachO        0x400000-0x40ffff is_main_bin=True
ExternObject 0x500000-0x500030 is_main_bin=False
MachO        0x100000000-0x100003fff is_main_bin=True
--- two container children both marked as the main binary
    first  0x400000-0x400fff
    second 0x400000-0x400fff  ON TOP OF THE FIRST

After

At 3443309fefc6d821bcac352beaf23002d6026a50, the loader uses the
conventional base when it is free. It uses the rebase search when that address
is occupied.

Universal2   0x400000-0x400000 is_main_bin=True
MachO        0x500000-0x50ffff is_main_bin=True
ExternObject 0x600000-0x600030 is_main_bin=False
MachO        0x100000000-0x100003fff is_main_bin=True
--- two container children both marked as the main binary
    first  0x400000-0x400fff
    second 0x8200000-0x8200fff

@zardus zardus changed the title Place the main binary at 0x400000 only when that space is free Prevent Universal2 load failures when 0x400000 is occupied Oct 12, 2026
@zardus zardus changed the title Prevent Universal2 load failures when 0x400000 is occupied Avoid Universal2 load failures when 0x400000 is occupied Nov 30, 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.

2 participants