amd64-linux: DF_1_PIE marks a main program; stub juggles AT_PHDR for same
https://github.com/upx/upx/issues/105 modified: p_elf_enum.h modified: p_lx_elf.cpp modified: stub/src/amd64-linux.elf-main.c modified: ../.github/travis_testsuite_1.sh modified: stub/amd64-linux.elf-fold.h modified: stub/tmp/amd64-linux.elf-fold.map
This commit is contained in:
@@ -162,9 +162,14 @@
|
||||
DT_CHECKSUM = 0x6ffffdf8, /* Only for prelink? */
|
||||
DT_GNU_HASH = 0x6ffffef5, /* GNU-style hash table */
|
||||
DT_VERSYM = 0x6ffffff0, /* version[] for each symbol */
|
||||
DT_FLAGS_1 = 0x6ffffffb, /* DF_1_* */
|
||||
DT_VERDEF = 0x6ffffffc, /* version definitions[] */
|
||||
DT_VERNEEDED= 0x6ffffffe /* version[] needed */
|
||||
};
|
||||
enum { // DT_FLAGS_1
|
||||
DF_1_NOW = 0x00000001, /* Set RTLD_NOW for this object. */
|
||||
DF_1_PIE = 0x08000000 // Position-Independent Executable (main program)
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+5
-1
@@ -1949,7 +1949,7 @@ PackLinuxElf64amd::canPack()
|
||||
// Otherwise (no __libc_start_main as global undefined): skip it.
|
||||
// Also allow __uClibc_main and __uClibc_start_main .
|
||||
|
||||
if (Elf32_Ehdr::ET_DYN==get_te16(&ehdr->e_type)) {
|
||||
if (Elf64_Ehdr::ET_DYN==get_te16(&ehdr->e_type)) {
|
||||
// The DT_SYMTAB has no designated length. Read the whole file.
|
||||
alloc_file_image(file_image, file_size);
|
||||
fi->seek(0, SEEK_SET);
|
||||
@@ -1983,6 +1983,10 @@ PackLinuxElf64amd::canPack()
|
||||
rela= (Elf64_Rela const *)elf_find_dynamic(Elf64_Dyn::DT_RELA);
|
||||
Elf64_Rela const *
|
||||
jmprela= (Elf64_Rela const *)elf_find_dynamic(Elf64_Dyn::DT_JMPREL);
|
||||
|
||||
if (Elf64_Dyn::DF_1_PIE & elf_unsigned_dynamic(Elf64_Dyn::DT_FLAGS_1)) {
|
||||
goto proceed; // marked as main program
|
||||
}
|
||||
for ( int sz = elf_unsigned_dynamic(Elf64_Dyn::DT_PLTRELSZ);
|
||||
0 < sz;
|
||||
(sz -= sizeof(Elf64_Rela)), ++jmprela
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* amd64-linux.elf-fold.h
|
||||
created from amd64-linux.elf-fold.bin, 1872 (0x750) bytes
|
||||
created from amd64-linux.elf-fold.bin, 1901 (0x76d) bytes
|
||||
|
||||
This file is part of the UPX executable compressor.
|
||||
|
||||
@@ -31,20 +31,20 @@
|
||||
*/
|
||||
|
||||
|
||||
#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 1872
|
||||
#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0x40f8c9fd
|
||||
#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0xa53313c8
|
||||
#define STUB_AMD64_LINUX_ELF_FOLD_SIZE 1901
|
||||
#define STUB_AMD64_LINUX_ELF_FOLD_ADLER32 0x9209d80d
|
||||
#define STUB_AMD64_LINUX_ELF_FOLD_CRC32 0x11d99f52
|
||||
|
||||
unsigned char stub_amd64_linux_elf_fold[1872] = {
|
||||
unsigned char stub_amd64_linux_elf_fold[1901] = {
|
||||
/* 0x0000 */ 127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0010 */ 2, 0, 62, 0, 1, 0, 0, 0,188, 0, 16, 0, 0, 0, 0, 0,
|
||||
/* 0x0020 */ 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0030 */ 0, 0, 0, 0, 64, 0, 56, 0, 2, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0040 */ 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0050 */ 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0,
|
||||
/* 0x0060 */ 80, 7, 0, 0, 0, 0, 0, 0, 80, 7, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0060 */ 109, 7, 0, 0, 0, 0, 0, 0,112, 7, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0070 */ 0, 0, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0080 */ 80, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0080 */ 109, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x0090 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x00a0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0,
|
||||
/* 0x00b0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,232, 89, 0, 0,
|
||||
@@ -131,26 +131,28 @@ unsigned char stub_amd64_linux_elf_fold[1872] = {
|
||||
/* 0x05c0 */ 0, 0, 0,116, 16, 72,139, 68, 36, 24, 72,139,148, 36,160, 0,
|
||||
/* 0x05d0 */ 0, 0, 72,137, 2, 73,139, 87, 24, 72, 1, 84, 36, 24, 72,139,
|
||||
/* 0x05e0 */ 68, 36, 24, 72,131,196,104, 91, 93, 65, 92, 65, 93, 65, 94, 65,
|
||||
/* 0x05f0 */ 95,195, 65, 87, 69, 49,255, 65, 86, 73,137,206, 49,201, 65, 85,
|
||||
/* 0x0600 */ 76,141,106, 64, 65, 84, 77,137,204, 85, 72,137,213, 83, 76,137,
|
||||
/* 0x0610 */ 195, 72,131,236, 56,139, 7, 72,137, 52, 36, 72,137,116, 36, 16,
|
||||
/* 0x0620 */ 72,141,116, 36, 32, 72,137, 84, 36, 40, 72,137,124, 36, 8, 76,
|
||||
/* 0x0630 */ 137,194, 72,137,124, 36, 24, 72,137,231, 72,137, 68, 36, 32,232,
|
||||
/* 0x0640 */ 212,251,255,255, 73,139, 85, 16,190, 3, 0, 0, 0, 76,137,247,
|
||||
/* 0x0650 */ 72,131,194, 64,232,204,252,255,255, 72, 15,183, 85, 56,190, 5,
|
||||
/* 0x0660 */ 0, 0, 0, 76,137,247,232,186,252,255,255, 65, 83, 77,137,225,
|
||||
/* 0x0670 */ 49,210, 73,137,216, 76,137,241, 72,137,239, 72,141, 68, 36,120,
|
||||
/* 0x0680 */ 72,141,116, 36, 24, 80,232,204,252,255,255,190, 9, 0, 0, 0,
|
||||
/* 0x0690 */ 72,137,194, 76,137,247, 73,137,196,232,135,252,255,255,102,131,
|
||||
/* 0x06a0 */ 125, 56, 0, 65, 89, 65, 90, 15,132,145, 0, 0, 0, 65,131,125,
|
||||
/* 0x06b0 */ 0, 3,117,118, 72,139,124, 36,112, 73, 3,125, 16, 49,210, 49,
|
||||
/* 0x06c0 */ 246,232, 11,251,255,255,133,192,137,195,120, 23,186, 0, 4, 0,
|
||||
/* 0x06d0 */ 0, 72,137,238,137,199,232,242,250,255,255, 72, 61, 0, 4, 0,
|
||||
/* 0x06e0 */ 0,116, 10,191,127, 0, 0, 0,232,236,250,255,255, 65, 80, 69,
|
||||
/* 0x06f0 */ 49,201, 69, 49,192, 49,201,137,218, 72,141, 68, 36,120, 49,246,
|
||||
/* 0x0700 */ 72,137,239, 80,232, 78,252,255,255, 72,139,148, 36,128, 0, 0,
|
||||
/* 0x0710 */ 0,190, 7, 0, 0, 0, 76,137,247, 73,137,196,232, 4,252,255,
|
||||
/* 0x0720 */ 255,137,223,232,173,250,255,255, 94, 95, 15,183, 69, 56, 65,255,
|
||||
/* 0x0730 */ 199, 73,131,197, 56, 65, 57,199, 15,140,111,255,255,255, 72,131,
|
||||
/* 0x0740 */ 196, 56, 76,137,224, 91, 93, 65, 92, 65, 93, 65, 94, 65, 95,195
|
||||
/* 0x05f0 */ 95,195, 65, 87, 65, 86, 73,137,206, 49,201, 65, 85, 76,141,106,
|
||||
/* 0x0600 */ 64, 65, 84, 77,137,204, 85, 72,137,213, 83, 76,137,195, 72,131,
|
||||
/* 0x0610 */ 236, 56,139, 7, 72,137, 52, 36, 72,137,116, 36, 16, 72,141,116,
|
||||
/* 0x0620 */ 36, 32, 72,137, 84, 36, 40, 72,137,124, 36, 8, 76,137,194, 72,
|
||||
/* 0x0630 */ 137,124, 36, 24, 72,137,231, 72,137, 68, 36, 32,232,215,251,255,
|
||||
/* 0x0640 */ 255, 73,139, 85, 16,190, 3, 0, 0, 0, 76,137,247, 72,131,194,
|
||||
/* 0x0650 */ 64,232,207,252,255,255, 72, 15,183, 85, 56,190, 5, 0, 0, 0,
|
||||
/* 0x0660 */ 76,137,247,232,189,252,255,255, 65, 83, 77,137,225, 49,210, 73,
|
||||
/* 0x0670 */ 137,216, 76,137,241, 72,137,239, 72,141, 68, 36,120, 72,141,116,
|
||||
/* 0x0680 */ 36, 24, 80,232,207,252,255,255, 73,131,125, 16, 0, 73,137,196,
|
||||
/* 0x0690 */ 65, 89, 65, 90,117, 22, 72,139, 84, 36,112,190, 3, 0, 0, 0,
|
||||
/* 0x06a0 */ 76,137,247, 72,131,194, 64,232,121,252,255,255, 76,137,226,190,
|
||||
/* 0x06b0 */ 9, 0, 0, 0, 76,137,247,232,105,252,255,255, 69, 49,255,102,
|
||||
/* 0x06c0 */ 131,125, 56, 0, 15,132,145, 0, 0, 0, 65,131,125, 0, 3,117,
|
||||
/* 0x06d0 */ 118, 72,139,124, 36,112, 73, 3,125, 16, 49,210, 49,246,232,238,
|
||||
/* 0x06e0 */ 250,255,255,133,192,137,195,120, 23,186, 0, 4, 0, 0, 72,137,
|
||||
/* 0x06f0 */ 238,137,199,232,213,250,255,255, 72, 61, 0, 4, 0, 0,116, 10,
|
||||
/* 0x0700 */ 191,127, 0, 0, 0,232,207,250,255,255, 65, 80, 69, 49,201, 69,
|
||||
/* 0x0710 */ 49,192, 49,201,137,218, 72,141, 68, 36,120, 49,246, 72,137,239,
|
||||
/* 0x0720 */ 80,232, 49,252,255,255, 72,139,148, 36,128, 0, 0, 0,190, 7,
|
||||
/* 0x0730 */ 0, 0, 0, 76,137,247, 73,137,196,232,231,251,255,255,137,223,
|
||||
/* 0x0740 */ 232,144,250,255,255, 94, 95, 15,183, 69, 56, 65,255,199, 73,131,
|
||||
/* 0x0750 */ 197, 56, 65, 57,199, 15,140,111,255,255,255, 72,131,196, 56, 76,
|
||||
/* 0x0760 */ 137,224, 91, 93, 65, 92, 65, 93, 65, 94, 65, 95,195
|
||||
};
|
||||
|
||||
@@ -344,6 +344,10 @@ upx_main( // returns entry address
|
||||
//auxv_up(av, AT_PAGESZ, PAGE_SIZE); /* ld-linux.so.2 does not need this */
|
||||
|
||||
entry = do_xmap(ehdr, &xi1, 0, av, f_decompress, f_unf, &reloc); // "rewind"
|
||||
if (!phdr->p_vaddr) { // -fPIE at 0
|
||||
// Needed if no PT_PHDR (libmusl); else repeat of do_xmap()
|
||||
auxv_up(av, AT_PHDR, reloc + (unsigned long)(1+(Elf64_Ehdr *)phdr->p_vaddr));
|
||||
}
|
||||
auxv_up(av, AT_ENTRY, entry);
|
||||
|
||||
{ // Map PT_INTERP program interpreter
|
||||
|
||||
@@ -8,7 +8,7 @@ Linker script and memory map
|
||||
|
||||
0x00000000001000bc . = ((0x100000 + SIZEOF_HEADERS) + 0xc)
|
||||
|
||||
.text 0x00000000001000bc 0x694
|
||||
.text 0x00000000001000bc 0x6b4
|
||||
*(.text)
|
||||
.text 0x00000000001000bc 0x121 tmp/amd64-linux.elf-fold.o
|
||||
0x00000000001001aa munmap
|
||||
@@ -20,19 +20,20 @@ Linker script and memory map
|
||||
0x00000000001001ae mprotect
|
||||
0x00000000001001d5 close
|
||||
*fill* 0x00000000001001dd 0x3 00
|
||||
.text 0x00000000001001e0 0x570 tmp/amd64-linux.elf-main.o
|
||||
.text 0x00000000001001e0 0x58d tmp/amd64-linux.elf-main.o
|
||||
0x00000000001005f2 upx_main
|
||||
*(.data)
|
||||
.data 0x0000000000100750 0x0 tmp/amd64-linux.elf-fold.o
|
||||
.data 0x0000000000100750 0x0 tmp/amd64-linux.elf-main.o
|
||||
*fill* 0x000000000010076d 0x3 00
|
||||
.data 0x0000000000100770 0x0 tmp/amd64-linux.elf-fold.o
|
||||
.data 0x0000000000100770 0x0 tmp/amd64-linux.elf-main.o
|
||||
|
||||
.data
|
||||
|
||||
.bss 0x0000000000100750 0x0
|
||||
.bss 0x0000000000100750 0x0 tmp/amd64-linux.elf-fold.o
|
||||
.bss 0x0000000000100750 0x0 tmp/amd64-linux.elf-main.o
|
||||
.bss 0x0000000000100770 0x0
|
||||
.bss 0x0000000000100770 0x0 tmp/amd64-linux.elf-fold.o
|
||||
.bss 0x0000000000100770 0x0 tmp/amd64-linux.elf-main.o
|
||||
|
||||
.rela.dyn 0x0000000000100750 0x0
|
||||
.rela.dyn 0x0000000000100770 0x0
|
||||
.rela.text 0x0000000000000000 0x0 tmp/amd64-linux.elf-fold.o
|
||||
LOAD tmp/amd64-linux.elf-fold.o
|
||||
LOAD tmp/amd64-linux.elf-main.o
|
||||
|
||||
Reference in New Issue
Block a user