macaw-base
: ELF loader spuriously warns on binary with overlapping PLT/relocation tables
#416
Labels
macaw-base
: ELF loader spuriously warns on binary with overlapping PLT/relocation tables
#416
To reproduce this bug, compile this program:
Using the PPC32 cross-compiler obtained from here:
And then load the resulting binary using this
macaw
-based program, which does nothing except load thetest.exe
binary and print any warnings that were emitted when callingmemoryForElf
:Running this program will reveal the following warnings:
I claim that these warnings are spurious. If you look at the relocations in
test.exe
, we have:Why is
macaw
giving spurious warnings about the.rela.plt
relocations? It's because the addresses for theJMPREL
table (i.e., the PLT table) with the addresses for theRELA
table (i.e., the relocation table):Note that the
RELASZ
(the size of theRELA
table) is 252 bytes, so starting from theRELA
address, we can see that it spans the range[0x2ec, 0x3e8)
. Moreover, thePLTRELSZ
(the size of theJMPREL
table) is 48 bytes, so starting from theJMPREL
address, we can see that it spans the range[0x3b8, 0x3e8)
. This means that theJMPREL
table completely overlaps with theRELA
table.macaw
, on the other hand, currently assumes that theRELA
table and theJMPREL
table are completely disjoint, as seen in the implementation ofdynamicRelocationTable
. This will parse the entirety of theRELA
table (usingdynRelaBuffer
/addElfRelaEntries
here) followed by the entirety of theJMPREL
table (usingdynPLTRel
/addRelaEntries
here). Moreover, if theJMPREL
table contains any relocations that were previously found when loading theRELA
table, thenmacaw
will emit this warning (theMultiple relocations modify
warning seen above). Because the relocations from the.rela.plt
section are contained in both theJMPREL
andRELA
tables, this causesmacaw
to warn about them in the example above.As it turns out, this issue has already been reported before in GaloisInc/elf-edit#40, but in an
elf-edit
context rather than amacaw
one. Interestingly, not allgcc
architectures exhibit this overlapping table behavior, as a PPC64 version ofgcc
does not do this. In order to avoid these spurious warnings,macaw
will likely need to implement something similar to the algorithm described in GaloisInc/elf-edit#40 (comment), which is necessary to determine if the PLT/relocation tables overlap before attempting to load them.The text was updated successfully, but these errors were encountered: