-
-
Notifications
You must be signed in to change notification settings - Fork 604
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
Can't add a new segment in a non-pie dynamic ELF #143
Comments
Hi @0xs4r By looking at the source code of the loader: I'll investigate this error this week |
Very weird: if you do |
Indeed it works for me too |
It look really weird, I can't spot where this come from within the glibc source code right now but i'ii try to find out why this is happening. Anyway, if it works with |
When we insert a segment in a non-pie executable, we move the program headers at the end of the binary. In the readelf -hl ./hello_lief
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x80483b0
Start of program headers: 7229 (bytes into file)
Start of section headers: 14781 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 10
Size of section headers: 40 (bytes)
Number of section headers: 31
Section header string table index: 30
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x001c3d 0x08049c3d 0x08049c3d 0x00140 0x00140 R E 0x4
INTERP 0x000154 0x08048154 0x08048154 0x00047 0x00047 R 0x1
[Requesting program interpreter: /usr/lib/ld.so]
LOAD 0x000000 0x08048000 0x08048000 0x01d7d 0x01d7d R E 0x1000
LOAD 0x000f04 0x08049f04 0x08049f04 0x00118 0x0011c RW 0x1000
LOAD 0x002000 0x10002000 0x10002000 0x01000 0x01000 0x1000
DYNAMIC 0x000f0c 0x08049f0c 0x08049f0c 0x000e8 0x000e8 RW 0x4
NOTE 0x00019c 0x0804819c 0x0804819c 0x00044 0x00044 R 0x4
GNU_EH_FRAME 0x00055c 0x0804855c 0x0804855c 0x00034 0x00034 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x10
GNU_RELRO 0x000f04 0x08049f04 0x08049f04 0x000fc 0x000fc R 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .plt.got .text .fini .rodata .eh_frame_hdr .eh_frame
03 .init_array .fini_array .dynamic .got .got.plt .data .bss
04
05 .dynamic
06 .note.ABI-tag .note.gnu.build-id
07 .eh_frame_hdr
08
09 .init_array .fini_array .dynamic .got The new phdr is located at the offset Thus the loader iterate over an empty program headers. As the program is running when launching with |
How did you managed to print the empty program header in gdb? In my case, this memory address is not accessible, because it's not mapped. Could this come from the fact that, in This isn't happening in EDIT: Well, by manually modifying vaddr of the second LOAD segment, it looks like it solve our problem
The program is still segfaulting because I did not update the content of .dynamic section, but it looks like it's well loaded. |
Hi, |
Has any progress been made with this issue? I just encountered this also when attempting to use LIEF to add segments to a 32 bit ELF file. |
At the moment it seems that the problem is still here. However you can update the NOTE segment with your updated section. |
Hi, has there been any progress on this issue, or could you give me some pointers on how to fix this? From what I've understood the underlying problem is that the kernel does the following:
and I guess that AUX entry is used by the loader to locate the PHDR. This is a problem when the PHDR is moved at the end of the binary, as its load address won't be Is this correct in your opinion?
There is a problem if the original binary maps a big .bss for instance, as I would need to pad the binary to account for that, but I haven't found a better way to do it. -- |
Hello @fcremo |
Should be fixed now |
This issue is closely related to #98
Hi ! I'm doing some test using LIEF and a simple hello world.
Compiled without pie
Replacing the NOTE segment with an updated segment is fully working, the binary does print "hello world" (I used the code you provided here #98 (comment))
However, if I try to add a new LOAD segment within this script
The generated binary is not properly working
It looks like it broke something in dynamic linking
The text was updated successfully, but these errors were encountered: