Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseThat not outputting executable binary (Exec format error) #71

Closed
jdetter opened this issue Jun 1, 2016 · 6 comments
Closed

parseThat not outputting executable binary (Exec format error) #71

jdetter opened this issue Jun 1, 2016 · 6 comments
Assignees
Labels
Milestone

Comments

@jdetter
Copy link
Contributor

jdetter commented Jun 1, 2016

Mohamed is having an issue where he runs:

parseThat --binary-edit=ssh-dyn -i 0 /usr/bin/ssh

and the output binary ssh-dyn will not execute due to an exec format error. The header information looks correct to me so I'm not sure why exec won't take it:

detter@ubuntu-16:~/Mohamed$ readelf -h ./ssh-dyn
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0xdea0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          768992 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         10
  Size of section headers:           64 (bytes)
  Number of section headers:         40
  Section header string table index: 39

Ubuntu's version of /usr/bin/ssh can be found here
The ssh-dyn binary generated by parseThat can be found here

@jdetter
Copy link
Contributor Author

jdetter commented Jun 1, 2016

@wrwilliams or @cuviper do you see anything wrong with the header? Here is a gist of the full readelf output for ssh-dyn:

https://gist.github.com/jdetter/8b2268edf4a61190848b358863ae12cd

@cuviper
Copy link
Contributor

cuviper commented Jun 1, 2016

Looks like the interp adjustments are still not right. The section header shifted by a page size without changing for the extra phdr, and the program headers also got a bad page size update.

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .interp           PROGBITS         0000000000001238  00001238
       000000000000001c  0000000000000000   A       0     0     1
Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040
                 0x0000000000000230 0x0000000000000230  R E    8
  INTERP         0x0000000000001270 0x0000000000000270 0x0000000000000270
                 0x000000000000001c 0x000000000000001c  R      1
      [Requesting program interpreter: ]
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000000a9b7c 0x00000000000a9b7c  R E    200000

@jdetter
Copy link
Contributor Author

jdetter commented Jun 1, 2016

Would you have time to try to fix this? You have a much better idea of what's going on.

@cuviper cuviper self-assigned this Jun 1, 2016
@cuviper
Copy link
Contributor

cuviper commented Jun 1, 2016

I'll give it a shot.

@jdetter
Copy link
Contributor Author

jdetter commented Jun 8, 2016

Mohamed is looking for an update on this, I told him were all busy looking at the test4_2 issue but after that someone will have time to look at this.

@jdetter jdetter added the bug label Jun 8, 2016
@jdetter jdetter added this to the 9.2 Release milestone Jun 8, 2016
@cuviper
Copy link
Contributor

cuviper commented Jun 8, 2016

Yes, sorry about that, the runtime hangs were more pressing to me. I think we've got a handle on that though, so I'll get back to this one. I'm going to see if I can simplify this logic to just "interp goes directly after phdrs, no matter what."

cuviper added a commit to cuviper/dyninst that referenced this issue Jun 11, 2016
When .interp was in the first page, keep it there like the comment about
FreeBSD requires.  Just shift it for the new PHDR.  But if .interp is
already past the first page, as seen in libc.so for instance, then move
its offset a whole page like we do for every other section.  Then
program headers follow the same logic.

The conditional around startMovingSections and object type is totally
removed, as it did the wrong thing for PIE binaries which otherwise look
like shared libraries.  We now just move all sections except low interp.

Fixes dyninst#71.
wrwilliams pushed a commit that referenced this issue Jun 13, 2016
When .interp was in the first page, keep it there like the comment about
FreeBSD requires.  Just shift it for the new PHDR.  But if .interp is
already past the first page, as seen in libc.so for instance, then move
its offset a whole page like we do for every other section.  Then
program headers follow the same logic.

The conditional around startMovingSections and object type is totally
removed, as it did the wrong thing for PIE binaries which otherwise look
like shared libraries.  We now just move all sections except low interp.

Fixes #71.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants