relinker --to-intel: signed integer overflow in Amd64OnlyConverter::_collectBranchTargets for a segment mapped across 2^63 #10653
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by TechLevelZero on 2026-10-24T15:20:27Z.
What happens
With
--to-intel(or--to-rosetta),_collectBranchTargetsadds the branch displacement to the next instruction's address asstd::int64_t. For an executable segment mapped at or above 2^63 the sum overflows:Amd64OnlyConverter.cpp:282: runtime error: signed integer overflow: -9223372036854774438 + -2105376126 cannot be represented in type 'std::int64_t'.Title, test or build step
relinker --to-intelon a malformed ELF. Found by fuzzingRelinker::Conversion::Convertwith libFuzzer, ASan and UBSan.AnyPS5 commit
main6cd36e651(alsob84322da6and924b5628b). No PRs on top.System
Ubuntu 26.04 (clang 21.1.8,
-fsanitize=address,undefined) for the fuzzer. Ubuntu 26.04 container (GCC 15,-fsanitize=undefined, relinker-only build) for the command-line reproduction.Steps to reproduce
overflow-repro.elf. It's an 8,107-byte fuzzer-generated file, SHA-2563636a37f7422a0eaf3b247a22a65fdb730101666cdea934bda996daeda1cc2c4. Its firstPT_LOADis executable atp_vaddr0x7fffffffffffffff,p_offset0x1000,p_filesz0x800.Log
Stack from the fuzzer (clang):
What was checked
next + displacementfor LEA (line 288) has the same pattern.target >= 0. A consequence even without the UB is that a branch into an AMD-only instruction in such a segment is not refused. The existingconverterSegmentcheck ("Branch into an AMD-only instruction was accepted") passes at 0x1000 but accepts the same bytes mapped at 0x7FFFFFFFFFFFFFFC.--to-intelthe same file is refused before conversion (FAIL: ET_NONE inputs do not specify an ELF object type). With it,Amd64OnlyConverter::Convertruns on the raw program headers first.ProgramHeaderLayoutBuilder(Load segment virtual range overflowed) doesn't cover this. 0x7fffffffffffffff plus 0x800 doesn't overflowstd::uint64_t, onlystd::int64_t.StubBodyBuilder.cpp:228(end + info.BranchDisp) uses an unsignedend, so it wraps without UB.overflow-repro.zip