[PATCH] D34321: Less strict validation of Mach-O rebase opcode

Kevin Enderby via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 10:09:29 PDT 2017


This looks fine.  I suspect their is a mismatch between what is checked in llvm’s libObject and what dyld requires.  As I think dyld allows rebases to span segments and have one rebase entry to start in one segment and apply the opcode after adjusting the offset.  Nick will know for sure.

Kev

> On Jun 17, 2017, at 4:24 PM, Dave Lee via Phabricator <reviews at reviews.llvm.org> wrote:
> 
> kastiglione created this revision.
> 
> When running `llvm-objdump -macho -rebase` on a binary that I presume to be
> fully valid (published in the app store), the output was:
> 
>  llvm-objdump: '/path/to/Some.app/Some': truncated or malformed object (for REBASE_OPCODE_ADD_ADDR_IMM_SCALED bad segOffset, too large for opcode at: 0x123)
> 
> The state and sequence is:
> 
> 1. Handling `REBASE_OPCODE_ADD_ADDR_IMM_SCALED`
> 2. Before: `SegmentIndex, SegmentOffset` pair fails `RebaseEntryCheckSegAndOffset`
> 3. `SegmentOffset` is incremented according to opcode
> 4. After: `SegmentIndex, SegmentOffset` pair passes `RebaseEntryCheckSegAndOffset`
> 
> The reason the second step errors is that the index-offset pair points exactly
> to the end of a section, but the check is passing `endInvalid = true`. Since
> this check happens before applying the opcode, and the opcode in this case
> produces a valid offset that passes the check in step 4, it seems erroneous to
> fail the pre-check in this case.
> 
> This fix is to pass `false` for `endInvalid` in the pre-check in step 2.
> 
> 
> https://reviews.llvm.org/D34321
> 
> Files:
>  lib/Object/MachOObjectFile.cpp
> 
> 
> Index: lib/Object/MachOObjectFile.cpp
> ===================================================================
> --- lib/Object/MachOObjectFile.cpp
> +++ lib/Object/MachOObjectFile.cpp
> @@ -2877,7 +2877,7 @@
>       break;
>     case MachO::REBASE_OPCODE_ADD_ADDR_IMM_SCALED:
>       error = O->RebaseEntryCheckSegAndOffset(SegmentIndex, SegmentOffset,
> -                                              true);
> +                                              false);
>       if (error) {
>         *E = malformedError("for REBASE_OPCODE_ADD_ADDR_IMM_SCALED " +
>              Twine(error) + " for opcode at: 0x" +
> 
> 
> <D34321.102949.patch>



More information about the llvm-commits mailing list