Repository navigation
Conversation
MetaELF.__init__ computes the RELRO level before ELF.__init__ gets to run, and
pyelftools reads the section header table to answer it: iter_segments() builds a
DynamicSegment for PT_DYNAMIC and that constructor walks iter_sections(), while
get_section_by_name(".dynamic") builds a name map over the whole table. On a file
whose e_shoff points past the end, pyelftools' ELFParseError escapes
Loader.__init__ and the whole load is lost -- including when
discard_section_headers is set, which is documented for section headers that are
corrupt or malicious.
ELF.__init__ already recovers from a section header table it cannot walk, by
reloading the file with the section header fields zeroed so that pyelftools reads
it from the program headers alone. Guarding the RELRO probe lets that recovery
happen. RELRO is a property CLE reports rather than one the load needs, and the
level is reported as none because the parse can fail inside the PT_GNU_RELRO test
itself, which leaves "no RELRO" and "cannot tell" indistinguishable; only
Relro.FULL changes any behaviour, and FULL is what needs the dynamic table.
tests/test_truncated_section_headers.py loads
tests/armel/fauxware.truncated.elf, which is fauxware cut at the end of its last
PT_LOAD.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS This is the full load result for The sample cannot be shared. SHA-256 Before. Pyelftools raises cle master 997d432After. The file loads from its program headers through the existing fallback in with this change |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Validation record for head Summary. The sample and the public fixture raise Sample. The sample cannot be shared. SHA-256 The sample is a
Public reproducer. The untruncated Scope. Thirteen catalog rows declare The regression set contains 947 other objects. It covers the 858 ELF paths under Recorded commands. The evidence used Limits.
|
|
Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/cle_856 |
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS
Problem
When an ELF file has an
e_shoffpast EOF, pyelftools can raiseELFParseErrorduring RELRO detection. The exception escapesLoader.__init__before CLE can use its existing fallback for damaged section headers.main_opts={"discard_section_headers": True}raises the same error because the RELRO probe runs first.Cause
MetaELF.__init__calls_get_relrobefore the body ofELF.__init__runs. Two paths in_get_relrocan read the section header table:elf.iter_segments()can build aDynamicSegmentforPT_DYNAMIC. Its constructor callselffile.iter_sections().elf.get_section_by_name(".dynamic")scans the sections to build its name map.ELFFile._get_section_headerraises when a section header starts paststream_len. A file withPT_DYNAMIC, such as the public fixture, fails on the first path. A file withoutPT_DYNAMIC, such as the sample, fails on the second path.ELF.__init__already recovers from this condition aftersuper().__init__(). It installs aPatchedStreamthat clearse_shoff,e_shentsize,e_shnum, ande_shstrndx. Pyelftools can then load the file from its program headers. The RELRO probe currently fails before that recovery and beforediscard_section_headerstakes effect.2a8adaa8added the fallback in 2018 and changedextract_sonameto use program headers in #113.4a7e4f7aadded the RELRO section read in #278.Fix
Guard the RELRO probe so that an
ELFErrordoes not end the load. The loader can then reach its existing recovery. The fallback RELRO value isRelro.NONE.A parse error can occur while checking for
PT_GNU_RELRO, so this code cannot distinguish no RELRO from an unknown RELRO level. The only consumer in CLE or angr,MetaELF._block_references_addr, compares the value withRelro.FULL. That answer requires the dynamic table that could not be read.The guard belongs at the call site because either section read can fail. #815 moves the first read to the program headers. The segment path can still fail in
iter_tags()when aPT_DYNAMICsegment has no string table, as described in #731. Those changes can reduce how often the guard runs, but they do not replace it.Reproducer
tests/armel/fauxware.truncated.elfistests/armel/fauxwarecut at0xf04 + 0x140, the end of the lastPT_LOADfile data. All bytes described as loadable remain. The section header table at0x11b0is absent.tests/test_truncated_section_headers.pycovers this input.The sample cannot be shared. SHA-256
7cb8df1ec5e810bf42b3cd9fca3c28a2117f696cd800dc8620f34fdf622448bd. It is an ARMET_EXECwhosee_shoffis past EOF.Run these commands from the
cleworktree withangr/binariesbeside it. SetOBJECTto the sample:The fixture is new. At
9eb02bd1032e1d96e729df2739f9a10a337bd154, none of the 858 files undertests/that begin with\x7fELFhave a section header table past EOF.Merge angr/binaries#246 first.
sync: angr/binaries#246