From c264750924c44aa7d1b1cec935afa247183b2525 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Fri, 21 Apr 2006 22:08:52 +0000 Subject: [PATCH] Adapt better to SELinux. We still need allow_execmem. p_lx_elf.cpp stub/a_lx_elf64.c stub/l_lx_elf64amd.h stub/l_lx_elf64amd.lds stub/l_lx_elf64amd.S stub/fold_elf64amd.h committer: jreiser 1145657332 +0000 --- src/p_lx_elf.cpp | 3 +- src/stub/a_lx_elf64.c | 31 +++--- src/stub/fold_elf64amd.h | 199 +++++++++++++++++-------------------- src/stub/l_lx_elf64amd.S | 29 +++++- src/stub/l_lx_elf64amd.h | 30 +++--- src/stub/l_lx_elf64amd.lds | 2 +- 6 files changed, 155 insertions(+), 139 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 46471aca..54e2c4ff 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -667,7 +667,7 @@ PackLinuxElf64amd::generateElfHdr( if (ph.format==UPX_F_LINUX_ELF64_AMD) { cprElfHdr2 *const h2 = (cprElfHdr2 *)&elfout; assert(2==get_native16(&h2->ehdr.e_phnum)); - set_native32(&h2->phdr[0].p_flags, Elf64_Phdr::PF_W | get_native32(&h2->phdr[0].p_flags)); + set_native32(&h2->phdr[0].p_flags, ~Elf64_Phdr::PF_W & get_native32(&h2->phdr[0].p_flags)); memset(&h2->linfo, 0, sizeof(h2->linfo)); fo->write(h2, sizeof(*h2)); } @@ -1510,6 +1510,7 @@ void PackLinuxI386elf::pack1(OutputFile *fo, Filter &) fi->seek(ehdri.e_phoff, SEEK_SET); fi->readx(phdri, sz_phdrs); + progid = getRandomId(); generateElfHdr(fo, linux_i386elf_fold, getbrk(phdri, ehdri.e_phnum) ); } diff --git a/src/stub/a_lx_elf64.c b/src/stub/a_lx_elf64.c index 0d64dad5..44b6cd3c 100644 --- a/src/stub/a_lx_elf64.c +++ b/src/stub/a_lx_elf64.c @@ -224,9 +224,9 @@ xfind_pages(unsigned mflags, Elf64_Phdr const *phdr, int phnum, lo -= ~PAGE_MASK & lo; // round down to page boundary hi = PAGE_MASK & (hi - lo - PAGE_MASK -1); // page length szlo = PAGE_MASK & (szlo - PAGE_MASK -1); // page length - addr = mmap((void *)lo, hi, PROT_READ|PROT_WRITE|PROT_EXEC, mflags, 0, 0); + addr = mmap((void *)lo, hi, PROT_NONE, mflags, -1, 0); *p_brk = hi + addr; // the logical value of brk(0) - munmap(szlo + addr, hi - szlo); // desirable if PT_LOAD non-contiguous + //mprotect(szlo + addr, hi - szlo, PROT_NONE); // no access, but keep the frames! return (unsigned long)addr - lo; } @@ -260,29 +260,36 @@ do_xmap( mlen += frag; addr -= frag; - if (addr != mmap(addr, mlen, PROT_READ | PROT_WRITE, + if (addr != mmap(addr, mlen, prot | (xi ? PROT_WRITE : 0), MAP_FIXED | MAP_PRIVATE | (xi ? MAP_ANONYMOUS : 0), - fdi, phdr->p_offset - frag) ) { + (xi ? -1 : fdi), phdr->p_offset - frag) ) { err_exit(8); } if (xi) { unpackExtent(xi, &xo, f_decompress, f_unf); } - bzero(addr, frag); // fragment at lo end + // Linux does not fixup the low end, so neither do we. + //if (PROT_WRITE & prot) { + // bzero(addr, frag); // fragment at lo end + //} frag = (-mlen) &~ PAGE_MASK; // distance to next page boundary - bzero(mlen+addr, frag); // fragment at hi end - if (xi && 0==phdr->p_offset) { - Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)addr; - *(int *)&ehdr->e_ident[12] = 0x90c3050f; // syscall; ret; nop + if (PROT_WRITE & prot) { // note: read-only .bss not supported here + bzero(mlen+addr, frag); // fragment at hi end } - if (0!=mprotect(addr, mlen, prot)) { - err_exit(10); + if (xi) { + if (0==phdr->p_offset) { + Elf64_Ehdr *const ehdr = (Elf64_Ehdr *)addr; + *(int *)&ehdr->e_ident[12] = 0x90c3050f; // syscall; ret; nop + } + if (0!=mprotect(addr, mlen, prot)) { + err_exit(10); ERR_LAB + } } addr += mlen + frag; /* page boundary on hi end */ if (addr < haddr) { // need pages for .bss if (addr != mmap(addr, haddr - addr, prot, - MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0 ) ) { + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0 ) ) { err_exit(9); } } diff --git a/src/stub/fold_elf64amd.h b/src/stub/fold_elf64amd.h index 869f030a..b799d423 100644 --- a/src/stub/fold_elf64amd.h +++ b/src/stub/fold_elf64amd.h @@ -1,4 +1,4 @@ -/* fold_elf64amd.h -- created from fold_elf64amd.bin, 1964 (0x7ac) bytes +/* fold_elf64amd.h -- created from fold_elf64amd.bin, 1653 (0x675) bytes This file is part of the UPX executable compressor. @@ -27,22 +27,22 @@ */ -#define LINUX_ELF64AMD_FOLD_SIZE 1964 -#define LINUX_ELF64AMD_FOLD_ADLER32 0xbcebb18a -#define LINUX_ELF64AMD_FOLD_CRC32 0x2dba754c +#define LINUX_ELF64AMD_FOLD_SIZE 1653 +#define LINUX_ELF64AMD_FOLD_ADLER32 0xd8f37766 +#define LINUX_ELF64AMD_FOLD_CRC32 0xb2c19390 -unsigned char linux_elf64amd_fold[1964] = { +unsigned char linux_elf64amd_fold[1653] = { 127, 69, 76, 70, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */ 2, 0, 62, 0, 1, 0, 0, 0,188, 0, 16, 0, 0, 0, 0, 0, /* 0x 10 */ 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 20 */ 0, 0, 0, 0, 64, 0, 56, 0, 2, 0, 0, 0, 0, 0, 0, 0, /* 0x 30 */ 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 40 */ 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, /* 0x 50 */ -172, 6, 0, 0, 0, 0, 0, 0,172, 6, 0, 0, 0, 0, 0, 0, /* 0x 60 */ +117, 6, 0, 0, 0, 0, 0, 0,120, 6, 0, 0, 0, 0, 0, 0, /* 0x 60 */ 0, 0, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 6, 0, 0, 0, /* 0x 70 */ -172, 6, 0, 0, 0, 0, 0, 0,172, 6, 16, 0, 0, 0, 0, 0, /* 0x 80 */ -172, 6, 16, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, /* 0x 90 */ - 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, /* 0x a0 */ +117, 6, 0, 0, 0, 0, 0, 0,120, 6, 16, 0, 0, 0, 0, 0, /* 0x 80 */ +120, 6, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 90 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, /* 0x a0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,232, 80, 0, 0, /* 0x b0 */ 0,131,249, 73,117, 74, 72,137,241, 72,137,254,235, 44,138, 7, /* 0x c0 */ 72,131,199, 1, 60,128,114, 10, 60,143,119, 6,128,127,254, 15, /* 0x d0 */ @@ -51,108 +51,89 @@ unsigned char linux_elf64amd_fold[1964] = { 72,131,199, 1, 72,255,201,117,217,235, 5, 72,255,201,117,190, /* 0x 100 */ 195, 72,141,116, 36, 56, 72,173, 72,133,192,117,249, 72,173, 72, /* 0x 110 */ 133,192,117,249, 65, 89, 72,137,241, 94, 95, 72,129,236, 0, 8, /* 0x 120 */ - 0, 0, 72,137,226, 73,137,232,232, 77, 4, 0, 0, 72,129,196, /* 0x 130 */ + 0, 0, 72,137,226, 73,137,232,232, 27, 4, 0, 0, 72,129,196, /* 0x 130 */ 0, 8, 0, 0, 94, 95, 89, 80,106, 11, 88,255,225,176, 11,235, /* 0x 140 */ 13,176, 10,235, 9,176, 12,235, 5,176, 9, 73,137,202, 15,182, /* 0x 150 */ 192, 15, 5, 72, 61, 0,240,255,255,114, 4, 72,131,200,255,195, /* 0x 160 */ 176, 0,235,234,176, 2,235,230,176, 3,235,226,176, 60,235,222, /* 0x 170 */ - 81, 72, 57, 23, 76,139, 71, 8, 72,141, 74,255,115, 10,191,127, /* 0x 180 */ - 0, 0, 0,232,228,255,255,255, 72,131,249,255,116, 17, 65, 15, /* 0x 190 */ -182, 0, 72,255,201, 73,255,192,136, 6, 72,255,198,235,233, 72, /* 0x 1a0 */ - 1, 87, 8, 72, 41, 23, 88,195, 65, 85, 73,137,213, 65, 84, 73, /* 0x 1b0 */ -137,204, 85, 72,137,253, 83, 72,137,243, 72,131,236, 40, 72,131, /* 0x 1c0 */ - 62, 0, 15,132,223, 0, 0, 0, 72,141,116, 36, 16,186, 12, 0, /* 0x 1d0 */ - 0, 0, 72,137,239,232,150,255,255,255,139, 84, 36, 16,139,116, /* 0x 1e0 */ - 36, 20,133,210,117, 21,129,254, 85, 80, 88, 33,117, 17, 72,131, /* 0x 1f0 */ -125, 0, 0, 15,132,174, 0, 0, 0,235, 4,133,246,117, 10,191, /* 0x 200 */ -127, 0, 0, 0,232, 99,255,255,255, 57,214,119,242,137,208, 72, /* 0x 210 */ - 59, 3,119,235, 57,214, 72,139, 67, 8,115,101, 68, 15,182, 68, /* 0x 220 */ - 36, 24, 72,139,125, 8, 72,141, 76, 36, 12, 72,137,194, 65,255, /* 0x 230 */ -213,133,192,117,202,139,116, 36, 12, 59,116, 36, 16,117,192, 15, /* 0x 240 */ -182, 76, 36, 25,132,201, 15,149,194, 49,192, 77,133,228, 15,149, /* 0x 250 */ -192,133,194,116, 30,129,254, 0, 2, 0, 0,119, 7,137,240, 72, /* 0x 260 */ - 57, 3,117, 15, 15,182, 84, 36, 26, 15,182,201, 72,139,123, 8, /* 0x 270 */ - 65,255,212,139, 68, 36, 20, 72, 1, 69, 8, 72, 41, 69, 0,235, /* 0x 280 */ - 13,137,242, 72,137,239, 72,137,198,232,226,254,255,255,139, 84, /* 0x 290 */ - 36, 16, 72,139, 3, 72, 1, 83, 8, 72, 41,208, 72,133,192, 72, /* 0x 2a0 */ -137, 3,233, 27,255,255,255, 72,131,196, 40, 91, 93, 65, 92, 65, /* 0x 2b0 */ - 93,195, 72,133,255, 73,137,208,116, 41, 72,139, 7,137,241, 72, /* 0x 2c0 */ - 57,200,116, 17, 72,255,200, 15,148,194, 49,192,133,246, 15,149, /* 0x 2d0 */ -192,133,194,116, 8, 72,137, 15, 76,137, 71, 8,195, 72,131,199, /* 0x 2e0 */ - 16,235,215,195, 65, 87,184, 0, 0, 0, 0, 73,137,255, 65, 86, /* 0x 2f0 */ - 73,137,254, 65, 85, 65, 84, 85, 83, 72,131,236, 88, 76, 3,119, /* 0x 300 */ - 32,102,131,127, 16, 3, 72,137,116, 36, 48, 15,183,119, 56, 72, /* 0x 310 */ -137, 76, 36, 32,185, 16, 0, 0, 0,137, 84, 36, 44, 76,137, 68, /* 0x 320 */ - 36, 24, 76,137, 76, 36, 16, 15, 68,200, 76,137,242, 73,131,205, /* 0x 330 */ -255, 49,237, 69, 49,228,131,193, 34,255,206,120, 38,131, 58, 1, /* 0x 340 */ -117, 27, 72,139, 66, 16, 76, 57,232,115, 7, 76,139, 98, 32, 73, /* 0x 350 */ -137,197, 72, 3, 66, 40, 72, 57,197, 72, 15, 66,232, 72,131,194, /* 0x 360 */ - 56,235,214, 76,137,232, 73,129,229, 0,240,255,255, 69, 49,201, /* 0x 370 */ - 76, 41,237, 37,255, 15, 0, 0, 69, 49,192, 72,129,197,255, 15, /* 0x 380 */ - 0, 0, 77,141,164, 4,255, 15, 0, 0,186, 7, 0, 0, 0, 72, /* 0x 390 */ -129,229, 0,240,255,255, 76,137,239, 72,137,238, 73,129,228, 0, /* 0x 3a0 */ -240,255,255,232,161,253,255,255, 72,137,195, 72,141, 4, 40, 76, /* 0x 3b0 */ - 41,229, 74,141, 60, 35, 72,137,238, 76, 41,235, 72,137, 68, 36, /* 0x 3c0 */ - 56,232,119,253,255,255,102, 65,131,127, 56, 0, 72,137, 92, 36, /* 0x 3d0 */ - 8,199, 68, 36, 4, 0, 0, 0, 0, 15,132,100, 1, 0, 0, 72, /* 0x 3e0 */ -131,124, 36, 48, 0,116, 35, 65,131, 62, 6,117, 29, 72,139, 84, /* 0x 3f0 */ - 36, 8, 73, 3, 86, 16,190, 3, 0, 0, 0, 72,139,124, 36, 32, /* 0x 400 */ -232,173,254,255,255,233, 34, 1, 0, 0, 65,131, 62, 1, 15,133, /* 0x 410 */ - 24, 1, 0, 0, 72,139,124, 36, 8, 73, 3,126, 16,186, 3, 0, /* 0x 420 */ - 0, 0, 65,139, 78, 4,199, 4, 36, 64, 98, 81,115, 73,139, 70, /* 0x 430 */ - 32, 77,139, 78, 8, 68,139, 68, 36, 44,131,225, 7, 72,137,253, /* 0x 440 */ - 72,137,251,129,229,255, 15, 0, 0,193,225, 2,211, 44, 36, 72, /* 0x 450 */ - 41,235,131, 36, 36, 7, 73,137,253, 77, 3,110, 40, 72,131,124, /* 0x 460 */ - 36, 48, 1, 76,141, 36, 40, 72,137,124, 36, 72, 72,137,223, 76, /* 0x 470 */ -137,230, 72,137, 68, 36, 64, 25,201, 73, 41,233,131,225,224,131, /* 0x 480 */ -193, 50,232,194,252,255,255, 72, 57,195,117,105, 72,131,124, 36, /* 0x 490 */ - 48, 0,116, 25, 72,139, 76, 36, 16, 72,139, 84, 36, 24, 72,141, /* 0x 4a0 */ -116, 36, 64, 72,139,124, 36, 48,232,251,252,255,255, 72,137,233, /* 0x 4b0 */ - 76,137,229, 49,192, 72,247,221, 72,137,223,252,129,229,255, 15, /* 0x 4c0 */ - 0, 0, 72,131,124, 36, 48, 0,243,170, 74,141, 60, 35, 72,137, /* 0x 4d0 */ -233,243,170,116, 14, 73,131,126, 8, 0,117, 7,199, 67, 12, 15, /* 0x 4e0 */ - 5,195,144,139, 20, 36, 76,137,230, 72,137,223,232, 80,252,255, /* 0x 4f0 */ -255,133,192,116, 10,191,127, 0, 0, 0,232,109,252,255,255, 73, /* 0x 500 */ -141, 4, 44, 72, 1,195, 76, 57,235,115, 33,139, 20, 36, 73, 41, /* 0x 510 */ -221, 69, 49,201, 69, 49,192,185, 50, 0, 0, 0, 76,137,238, 72, /* 0x 520 */ -137,223,232, 34,252,255,255, 72, 57,195,117,201,255, 68, 36, 4, /* 0x 530 */ - 65, 15,183, 71, 56, 73,131,198, 56, 57, 68, 36, 4, 15,140,156, /* 0x 540 */ -254,255,255, 72,131,124, 36, 48, 0,116, 18,102, 65,131,127, 16, /* 0x 550 */ - 3,116, 10, 72,139,124, 36, 56,232,232,251,255,255, 73,139, 71, /* 0x 560 */ - 24, 72, 1, 68, 36, 8, 72,139, 68, 36, 8, 72,131,196, 88, 91, /* 0x 570 */ - 93, 65, 92, 65, 93, 65, 94, 65, 95,195, 65, 86, 76,141,114, 64, /* 0x 580 */ - 65, 85, 77,137,205, 65, 84, 77,137,196, 85, 72,137,213, 83, 72, /* 0x 590 */ -137,203, 49,201, 72,131,236, 48,139, 7, 72,137, 52, 36, 72,137, /* 0x 5a0 */ -116, 36, 16, 72,141,116, 36, 32, 72,137, 84, 36, 40, 72,137,124, /* 0x 5b0 */ - 36, 8, 76,137,194, 72,137,124, 36, 24, 72,137,231, 72,137, 68, /* 0x 5c0 */ - 36, 32,232,225,251,255,255, 73,139, 86, 16,190, 3, 0, 0, 0, /* 0x 5d0 */ - 72,137,223, 72,131,194, 64,232,214,252,255,255, 72, 15,183, 85, /* 0x 5e0 */ - 56,190, 5, 0, 0, 0, 72,137,223,232,196,252,255,255, 72,139, /* 0x 5f0 */ - 85, 24,190, 9, 0, 0, 0, 72,137,223,232,179,252,255,255, 72, /* 0x 600 */ -141,116, 36, 16, 77,137,233, 77,137,224, 49,210, 72,137,217, 72, /* 0x 610 */ -137,239,232,205,252,255,255, 69, 49,237,102,131,125, 56, 0, 73, /* 0x 620 */ -137,196,116,104, 65,131, 62, 3,117, 82, 73,139,126, 16, 49,210, /* 0x 630 */ - 49,246,232, 45,251,255,255,133,192,137,195,120, 23,186, 0, 4, /* 0x 640 */ - 0, 0, 72,137,238,137,199,232, 20,251,255,255, 72, 61, 0, 4, /* 0x 650 */ - 0, 0,116, 10,191,127, 0, 0, 0,232, 14,251,255,255, 72,137, /* 0x 660 */ -239, 69, 49,201, 69, 49,192, 49,201,137,218, 49,246,232,114,252, /* 0x 670 */ -255,255,137,223, 73,137,196,232,236,250,255,255, 15,183, 69, 56, /* 0x 680 */ - 65,255,197, 73,131,198, 56, 65, 57,197,124,152, 72,131,196, 48, /* 0x 690 */ - 76,137,224, 91, 93, 65, 92, 65, 93, 65, 94,195, 0, 0, 0, 0, /* 0x 6a0 */ - 20, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1,120, 16, 12, 7, 8, /* 0x 6b0 */ -144, 1, 0, 0, 0, 0, 0, 0, 36, 0, 0, 0, 28, 0, 0, 0, /* 0x 6c0 */ -128, 1, 16, 0, 0, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, /* 0x 6d0 */ - 65, 14, 16, 46, 8, 87, 14, 8, 46, 0, 95, 14, 0, 0, 0, 0, /* 0x 6e0 */ - 44, 0, 0, 0, 68, 0, 0, 0,184, 1, 16, 0, 0, 0, 0, 0, /* 0x 6f0 */ - 10, 1, 0, 0, 0, 0, 0, 0, 66, 14, 16,141, 2, 69, 14, 24, /* 0x 700 */ -140, 3, 68, 14, 32,134, 4, 68, 14, 40,131, 5, 71, 14, 80, 0, /* 0x 710 */ - 20, 0, 0, 0,116, 0, 0, 0,194, 2, 16, 0, 0, 0, 0, 0, /* 0x 720 */ - 50, 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0,140, 0, 0, 0, /* 0x 730 */ -244, 2, 16, 0, 0, 0, 0, 0,150, 2, 0, 0, 0, 0, 0, 0, /* 0x 740 */ - 66, 14, 16,143, 2, 74, 14, 24,142, 3, 69, 14, 32, 66, 14, 40, /* 0x 750 */ - 65, 14, 48, 65, 14, 56, 68, 14,144, 1,131, 7,134, 6,140, 5, /* 0x 760 */ -141, 4, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0,204, 0, 0, 0, /* 0x 770 */ -138, 5, 16, 0, 0, 0, 0, 0, 34, 1, 0, 0, 0, 0, 0, 0, /* 0x 780 */ - 66, 14, 16,142, 2, 70, 14, 24,141, 3, 69, 14, 32,140, 4, 68, /* 0x 790 */ - 14, 40,134, 5, 68, 14, 48,131, 6, 73, 14, 96 /* 0x 7a0 */ + 81, 49,201, 72, 57, 23, 76,139, 71, 8,115, 20,191,127, 0, 0, /* 0x 180 */ + 0,232,230,255,255,255, 66,138, 4, 1,136, 4, 49, 72,255,193, /* 0x 190 */ + 72, 57,209,117,241, 72, 1, 87, 8, 72, 41, 23, 88,195, 65, 85, /* 0x 1a0 */ + 73,137,213, 65, 84, 73,137,204, 85, 72,137,253, 83, 72,137,243, /* 0x 1b0 */ + 72,131,236, 24,233,200, 0, 0, 0,186, 12, 0, 0, 0, 72,137, /* 0x 1c0 */ +230, 72,137,239,232,167,255,255,255,139, 20, 36,139,116, 36, 4, /* 0x 1d0 */ +133,210,117, 20,129,254, 85, 80, 88, 33,117, 16, 72,131,125, 0, /* 0x 1e0 */ + 0,117, 9,233,163, 0, 0, 0,133,246,117, 10,191,127, 0, 0, /* 0x 1f0 */ + 0,232,118,255,255,255, 57,214,119,242,137,208, 72, 59, 3,119, /* 0x 200 */ +235, 57,214, 72,139, 67, 8,115, 97, 68, 15,182, 68, 36, 8, 72, /* 0x 210 */ +139,125, 8, 72,141, 76, 36, 12, 72,137,194, 65,255,213,133,192, /* 0x 220 */ +117,202,139,116, 36, 12, 59, 52, 36,117,193,138, 76, 36, 9,132, /* 0x 230 */ +201, 15,149,194, 77,133,228, 15,149,192,132,208,116, 30,129,254, /* 0x 240 */ + 0, 2, 0, 0,119, 7,137,240, 72, 57, 3,117, 15, 15,182, 84, /* 0x 250 */ + 36, 10, 15,182,201, 72,139,123, 8, 65,255,212,139, 68, 36, 4, /* 0x 260 */ + 72, 1, 69, 8, 72, 41, 69, 0,235, 13,137,242, 72,137,239, 72, /* 0x 270 */ +137,198,232,249,254,255,255,139, 4, 36, 72, 1, 67, 8, 72, 41, /* 0x 280 */ + 3, 72,131, 59, 0, 15,133, 46,255,255,255, 72,131,196, 24, 91, /* 0x 290 */ + 93, 65, 92, 65, 93,195, 72,133,255, 73,137,208,116, 39, 72,139, /* 0x 2a0 */ + 7,137,241, 72, 57,200,116, 15, 72,255,200, 15,148,194,133,246, /* 0x 2b0 */ + 15,149,192,132,208,116, 8, 72,137, 15, 76,137, 71, 8,195, 72, /* 0x 2c0 */ +131,199, 16,235,217,195, 65, 87, 73,137,255,184, 16, 0, 0, 0, /* 0x 2d0 */ + 65, 86, 65, 85, 65, 84, 85, 72,137,253, 83, 72,131,236,104, 72, /* 0x 2e0 */ + 3,111, 32,102, 65,131,127, 16, 3,137, 84, 36, 28, 15,183,127, /* 0x 2f0 */ + 56,186, 0, 0, 0, 0, 72,137, 76, 36, 16, 72,137,116, 36, 32, /* 0x 300 */ + 76,137, 68, 36, 8, 76,137, 12, 36, 15, 68,194, 72,137,234, 73, /* 0x 310 */ +131,204,255,141, 72, 34, 49,246,235, 31,131, 58, 1,117, 22, 72, /* 0x 320 */ +139, 66, 16, 76, 57,224, 76, 15, 66,224, 72, 3, 66, 40, 72, 57, /* 0x 330 */ +198, 72, 15, 66,240, 72,131,194, 56,255,207,121,221, 73,129,228, /* 0x 340 */ + 0,240,255,255, 69, 49,201, 65,131,200,255, 76, 41,230, 49,210, /* 0x 350 */ + 76,137,231, 72,141,158,255, 15, 0, 0, 72,129,227, 0,240,255, /* 0x 360 */ +255, 72,137,222,232,224,253,255,255, 72,141, 28, 24, 76, 41,224, /* 0x 370 */ +199, 68, 36, 60, 0, 0, 0, 0, 72,137, 68, 36, 48, 72,137, 92, /* 0x 380 */ + 36, 40,233,123, 1, 0, 0, 72,131,124, 36, 32, 0,116, 35,131, /* 0x 390 */ +125, 0, 6,117, 29, 72,139, 84, 36, 48, 72, 3, 85, 16,190, 3, /* 0x 3a0 */ + 0, 0, 0, 72,139,124, 36, 16,232,233,254,255,255,233, 72, 1, /* 0x 3b0 */ + 0, 0,131,125, 0, 1, 15,133, 62, 1, 0, 0, 72,139, 68, 36, /* 0x 3c0 */ + 48, 72, 3, 69, 16, 65,190, 64, 98, 81,115, 72,139, 85, 40,139, /* 0x 3d0 */ + 77, 4, 68,139, 68, 36, 28, 72, 1,194,131,225, 7, 73,137,196, /* 0x 3e0 */ + 72,137, 68, 36, 88, 72,137, 84, 36, 64, 72,137,194, 72,141, 69, /* 0x 3f0 */ + 8,193,225, 2,129,226,255, 15, 0, 0, 65,211,238, 72,139, 77, /* 0x 400 */ + 32, 73, 41,212, 72,137, 68, 36, 72, 72,139, 69, 8, 65,131,230, /* 0x 410 */ + 7, 76,141, 44, 17, 72,137, 76, 36, 80,185, 18, 0, 0, 0, 72, /* 0x 420 */ + 41,208, 49,210, 72,131,124, 36, 32, 0,116, 8,178, 2, 65,131, /* 0x 430 */ +200,255,177, 50, 68, 9,242, 73,137,193, 76,137,238, 76,137,231, /* 0x 440 */ +232, 4,253,255,255, 73, 57,196,117,112, 72,131,124, 36, 32, 0, /* 0x 450 */ +116, 24, 72,139, 12, 36, 72,139, 84, 36, 8, 72,141,116, 36, 80, /* 0x 460 */ + 72,139,124, 36, 32,232, 52,253,255,255, 76,137,235, 68,137,240, /* 0x 470 */ + 72,247,219,131,224, 2,129,227,255, 15, 0, 0,133,192,116, 12, /* 0x 480 */ + 75,141, 60, 44, 49,192, 72,137,217,252,243,170, 72,131,124, 36, /* 0x 490 */ + 32, 0,116, 48, 72,139, 84, 36, 72, 72,131, 58, 0,117, 9, 65, /* 0x 4a0 */ +199, 68, 36, 12, 15, 5,195,144, 68,137,242, 76,137,238, 76,137, /* 0x 4b0 */ +231,232,139,252,255,255,133,192,116, 10,191,127, 0, 0, 0,232, /* 0x 4c0 */ +168,252,255,255, 73,141, 68, 29, 0, 73,141, 28, 4, 72, 59, 92, /* 0x 4d0 */ + 36, 64,115, 38, 72, 41, 92, 36, 64, 69, 49,201, 65,131,200,255, /* 0x 4e0 */ + 72,139,116, 36, 64,185, 50, 0, 0, 0, 68,137,242, 72,137,223, /* 0x 4f0 */ +232, 84,252,255,255, 72, 57,195,117,192,255, 68, 36, 60, 72,131, /* 0x 500 */ +197, 56, 65, 15,183, 71, 56, 57, 68, 36, 60, 15,140,118,254,255, /* 0x 510 */ +255, 72,131,124, 36, 32, 0,116, 18,102, 65,131,127, 16, 3,116, /* 0x 520 */ + 10, 72,139,124, 36, 40,232, 26,252,255,255, 73,139, 71, 24, 72, /* 0x 530 */ + 1, 68, 36, 48, 72,139, 68, 36, 48, 72,131,196,104, 91, 93, 65, /* 0x 540 */ + 92, 65, 93, 65, 94, 65, 95,195, 65, 86, 76,141,114, 64, 65, 85, /* 0x 550 */ + 77,137,205, 65, 84, 77,137,196, 85, 72,137,213, 83, 72,137,203, /* 0x 560 */ + 49,201, 72,131,236, 48,139, 7, 72,137, 52, 36, 72,137,116, 36, /* 0x 570 */ + 16, 72,141,116, 36, 32, 72,137, 84, 36, 40, 72,137,124, 36, 8, /* 0x 580 */ + 76,137,194, 72,137,124, 36, 24, 72,137,231, 72,137, 68, 36, 32, /* 0x 590 */ +232, 9,252,255,255, 73,139, 86, 16,190, 3, 0, 0, 0, 72,137, /* 0x 5a0 */ +223, 72,131,194, 64,232,236,252,255,255, 72, 15,183, 85, 56,190, /* 0x 5b0 */ + 5, 0, 0, 0, 72,137,223,232,218,252,255,255, 72,139, 85, 24, /* 0x 5c0 */ +190, 9, 0, 0, 0, 72,137,223,232,201,252,255,255, 72,141,116, /* 0x 5d0 */ + 36, 16, 77,137,233, 77,137,224, 72,137,217, 49,210, 72,137,239, /* 0x 5e0 */ +232,225,252,255,255, 69, 49,237, 73,137,196,235, 95, 65,131, 62, /* 0x 5f0 */ + 3,117, 82, 73,139,126, 16, 49,210, 49,246,232,100,251,255,255, /* 0x 600 */ +133,192,137,195,120, 23,186, 0, 4, 0, 0, 72,137,238,137,199, /* 0x 610 */ +232, 75,251,255,255, 72, 61, 0, 4, 0, 0,116, 10,191,127, 0, /* 0x 620 */ + 0, 0,232, 69,251,255,255, 72,137,239, 69, 49,201, 69, 49,192, /* 0x 630 */ + 49,201,137,218, 49,246,232,139,252,255,255,137,223, 73,137,196, /* 0x 640 */ +232, 35,251,255,255, 73,131,198, 56, 65,255,197, 15,183, 69, 56, /* 0x 650 */ + 65, 57,197,124,152, 72,131,196, 48, 76,137,224, 91, 93, 65, 92, /* 0x 660 */ + 65, 93, 65, 94,195 /* 0x 670 */ }; diff --git a/src/stub/l_lx_elf64amd.S b/src/stub/l_lx_elf64amd.S index dd418fcb..b428376a 100644 --- a/src/stub/l_lx_elf64amd.S +++ b/src/stub/l_lx_elf64amd.S @@ -169,6 +169,26 @@ eof: pop %rbx; pop %rbp ret + +/* These from /usr/include/asm-x86_64/unistd.h */ +__NR_write = 1 +__NR_exit = 60 + +msg_SELinux: + push $ L71 - L70; pop %arg3 # length + call L71 +L70: + .asciz "SELinux denied execmem.\n" +L71: + pop %arg2 # message text + push $2; pop %arg1 # fd stderr + push $ __NR_write; pop %rax + syscall +die: + push $127; pop %arg1 + push $ __NR_exit; pop %rax + syscall + /* Decompress the rest of this loader, and jump to it. Map a page to hold the decompressed bytes. Logically this could be done by setting .p_memsz for our first PT_LOAD. But as of 2005-11-09, @@ -195,7 +215,7 @@ unfold: subl %arg5l,%arg5l #; subl %arg6l,%arg6l # MAP_ANON ==> ignore offset push $ SYS_mmap; pop %rax syscall # %rax= result; trashes %rcx,%r11 only - cmpl %eax,%edi; je 0f; hlt; 0: # XXX: 4GB + cmpl %eax,%edi; jne msg_SELinux # XXX: 4GB /* Load the addresses and lengths that ::pack3() patched in. XXX: 2GB Note that PUSH $imm32 sign-extends to 64 bits. @@ -226,11 +246,14 @@ unfold: movl %ebx,%esi # %arg2l= &b_info (relocated) push %rax # ret_addr after decompression xchgl %eax,%arg3l # %arg3= dst for unfolding XXX: 4GB - lodsl; movl %esi,%arg4l # &len_dst ==> &do_not_care XXX: 4GB + lodsl; push %rax # allocate slot on stack + movq %rsp,%arg4 # &len_dst ==> &do_not_care lodsl; xchgl %eax,%arg1l # sz_cpr XXX: 4GB lodsl; movzbl %al,%arg5l # b_method xchg %arg1l,%arg2l # XXX: 4GB - jmp *%rbp # goto decompress; return to unfolded loader + call *%rbp # decompress + pop %rcx # discard len_dst + ret main: # int3 # uncomment for debugging diff --git a/src/stub/l_lx_elf64amd.h b/src/stub/l_lx_elf64amd.h index eabb24c9..1e13e46b 100644 --- a/src/stub/l_lx_elf64amd.h +++ b/src/stub/l_lx_elf64amd.h @@ -1,4 +1,4 @@ -/* l_lx_elf64amd.h -- created from l_lx_elf64amd.bin, 560 (0x230) bytes +/* l_lx_elf64amd.h -- created from l_lx_elf64amd.bin, 619 (0x26b) bytes This file is part of the UPX executable compressor. @@ -27,12 +27,12 @@ */ -#define LINUX_ELF64AMD_LOADER_SIZE 560 -#define LINUX_ELF64AMD_LOADER_ADLER32 0xdfe11659 -#define LINUX_ELF64AMD_LOADER_CRC32 0x1c0a6afb +#define LINUX_ELF64AMD_LOADER_SIZE 619 +#define LINUX_ELF64AMD_LOADER_ADLER32 0xbfe028a3 +#define LINUX_ELF64AMD_LOADER_CRC32 0xe248fd34 -unsigned char linux_elf64amd_loader[560] = { -232, 37, 2, 0, 0, 85, 83, 81, 82, 72, 1,254, 86, 72,137,254, /* 0x 0 */ +unsigned char linux_elf64amd_loader[619] = { +232, 96, 2, 0, 0, 85, 83, 81, 82, 72, 1,254, 86, 72,137,254, /* 0x 0 */ 72,137,215, 49,219, 49,201, 72,131,205,255,232,129, 1, 0, 0, /* 0x 10 */ 1,219,116, 2,243,195,139, 30, 72,131,238,252, 17,219,138, 22, /* 0x 20 */ 243,195, 72,141, 4, 47,131,249, 5,138, 16,118, 33, 72,131,253, /* 0x 30 */ @@ -60,11 +60,15 @@ unsigned char linux_elf64amd_loader[560] = { 237, 72,129,253, 0,243,255,255, 17,193,232,147,254,255,255,235, /* 0x 190 */ 135,252, 65, 91, 65,131,248, 8, 15,132,202,254,255,255, 65,131, /* 0x 1a0 */ 248, 2, 15,132,112,255,255,255, 89, 72,137,240, 72, 41,200, 90, /* 0x 1b0 */ - 72, 41,215, 89,137, 57, 91, 93,195, 91,191, 65, 68, 82, 77,106, /* 0x 1c0 */ - 7, 90,190, 76, 69, 78, 77,106, 50, 65, 90, 69, 41,192,106, 9, /* 0x 1d0 */ - 88, 15, 5, 57,199,116, 1,244,104, 74, 77, 80, 85,104, 65, 68, /* 0x 1e0 */ - 82, 85,190, 65, 68, 82, 67,104, 76, 69, 78, 85,185, 67, 78, 84, /* 0x 1f0 */ - 67,104, 65, 68, 82, 88,104, 76, 69, 78, 88,137,250, 41,242, 1, /* 0x 200 */ -213, 1,211,252,243, 72,165,151,137,222, 80,146,173,137,241,173, /* 0x 210 */ -151,173, 68, 15,182,192,135,254,255,229, 93,232,153,255,255,255 /* 0x 220 */ + 72, 41,215, 89,137, 57, 91, 93,195,104, 25, 0, 0, 0, 90,232, /* 0x 1c0 */ + 25, 0, 0, 0, 83, 69, 76,105,110,117,120, 32,100,101,110,105, /* 0x 1d0 */ +101,100, 32,101,120,101, 99,109,101,109, 46, 10, 0, 94,106, 2, /* 0x 1e0 */ + 95,106, 1, 88, 15, 5,106,127, 95,106, 60, 88, 15, 5, 91,191, /* 0x 1f0 */ + 65, 68, 82, 77,106, 7, 90,190, 76, 69, 78, 77,106, 50, 65, 90, /* 0x 200 */ + 69, 41,192,106, 9, 88, 15, 5, 57,199,117,173,104, 74, 77, 80, /* 0x 210 */ + 85,104, 65, 68, 82, 85,190, 65, 68, 82, 67,104, 76, 69, 78, 85, /* 0x 220 */ +185, 67, 78, 84, 67,104, 65, 68, 82, 88,104, 76, 69, 78, 88,137, /* 0x 230 */ +250, 41,242, 1,213, 1,211,252,243, 72,165,135,199,137,222, 80, /* 0x 240 */ +135,194,173, 80, 72,137,225,173,135,199,173, 68, 15,182,192,135, /* 0x 250 */ +254,255,213, 89,195, 93,232,147,255,255,255 /* 0x 260 */ }; diff --git a/src/stub/l_lx_elf64amd.lds b/src/stub/l_lx_elf64amd.lds index c1be85fa..d029e842 100644 --- a/src/stub/l_lx_elf64amd.lds +++ b/src/stub/l_lx_elf64amd.lds @@ -33,7 +33,7 @@ OUTPUT_ARCH(i386:x86-64) /*ENTRY(_start)*/ PHDRS { - text PT_LOAD FILEHDR PHDRS ; + text PT_LOAD FILEHDR PHDRS FLAGS ( 5 ) ; /* r-x (no -w-) */ data PT_LOAD ; /* for setting brk(0) */ } SECTIONS