From b991f954d0ae3c4b46b3b9337c08477eb17b99c2 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Thu, 27 Mar 2008 15:51:19 -0700 Subject: [PATCH] Fix "Failure with Ubuntu 7.10" SourceForge Bug tracker 1825006 when --force-execve with kernel 2.6.22-14-generic et al. --- src/stub/i386-linux.elf.execve-fold.h | 116 ++++++++++++---------- src/stub/src/i386-linux.elf.execve-main.c | 20 ++++ src/stub/src/include/linux.h | 1 + 3 files changed, 82 insertions(+), 55 deletions(-) diff --git a/src/stub/i386-linux.elf.execve-fold.h b/src/stub/i386-linux.elf.execve-fold.h index d821dadf..4bf94669 100644 --- a/src/stub/i386-linux.elf.execve-fold.h +++ b/src/stub/i386-linux.elf.execve-fold.h @@ -1,5 +1,5 @@ /* i386-linux.elf.execve-fold.h - created from i386-linux.elf.execve-fold.bin, 931 (0x3a3) bytes + created from i386-linux.elf.execve-fold.bin, 1027 (0x403) bytes This file is part of the UPX executable compressor. @@ -28,68 +28,74 @@ */ -#define STUB_I386_LINUX_ELF_EXECVE_FOLD_SIZE 931 -#define STUB_I386_LINUX_ELF_EXECVE_FOLD_ADLER32 0xdce475cc -#define STUB_I386_LINUX_ELF_EXECVE_FOLD_CRC32 0x512b1d3a +#define STUB_I386_LINUX_ELF_EXECVE_FOLD_SIZE 1027 +#define STUB_I386_LINUX_ELF_EXECVE_FOLD_ADLER32 0xadf29d6b +#define STUB_I386_LINUX_ELF_EXECVE_FOLD_CRC32 0xe444d00d -unsigned char stub_i386_linux_elf_execve_fold[931] = { +unsigned char stub_i386_linux_elf_execve_fold[1027] = { 127, 69, 76, 70, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 0 */ 2, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 52, 0, 0, 0, /* 0x 10 */ 0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 32, 0, 2, 0, 0, 0, /* 0x 20 */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 16, 64, 0, /* 0x 30 */ - 0, 16, 64, 0,163, 3, 0, 0,164, 3, 0, 0, 5, 0, 0, 0, /* 0x 40 */ - 0, 16, 0, 0, 1, 0, 0, 0,163, 3, 0, 0, 0, 0, 0, 0, /* 0x 50 */ + 0, 16, 64, 0, 3, 4, 0, 0, 4, 4, 0, 0, 5, 0, 0, 0, /* 0x 40 */ + 0, 16, 0, 0, 1, 0, 0, 0, 3, 4, 0, 0, 0, 0, 0, 0, /* 0x 50 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 60 */ 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x 70 */ 88,137,225,141, 84,132, 4,139,123, 24,141,179,128, 0, 0, 0, /* 0x 80 */ - 41,247,141, 93, 2, 96,232,196, 0, 0, 0,244, 83,141, 92, 36, /* 0x 90 */ + 41,247,141, 93, 2, 96,232, 37, 1, 0, 0,244, 83,141, 92, 36, /* 0x 90 */ 8,106, 90, 88,205,128, 91,195, 83,137,195,139, 76, 36, 8,136, /* 0x a0 */ 208,131,224, 31, 60, 25,118, 3,131,232, 43,131,192, 65, 75,136, /* 0x b0 */ - 3,137,208,193,232, 5,137,194,226,229, 91,195, 85, 49,201,137, /* 0x c0 */ -229, 87, 86,137,202, 83,131,236, 44,139, 93, 8,106, 5, 88,205, /* 0x d0 */ -128,133,192,137,198,120,108,199, 69,212, 47,112,114,111,199, 69, /* 0x e0 */ -216, 99, 47, 0, 0,106, 20, 88,205,128,141, 85,218,141,125,212, /* 0x f0 */ -232,123, 2, 0, 0,141, 80, 4,137,251,199, 0, 47,102,100, 47, /* 0x 100 */ -137,240,232,105, 2, 0, 0,186, 1, 0, 0, 0,106, 33, 88,106, /* 0x 110 */ - 5, 89,205,128, 61, 85, 80, 88, 50,117, 33,139, 93, 8,106, 10, /* 0x 120 */ - 88,205,128,185, 2, 0, 0, 0,137,243,106, 55, 88,205,128,137, /* 0x 130 */ -251,139, 77, 12,139, 85, 16,106, 11, 88,205,128,137,243,106, 6, /* 0x 140 */ - 88,205,128,131,196, 44,137,240, 91, 94, 95,201,194, 12, 0, 85, /* 0x 150 */ -137,229, 87, 86, 83,131,236,124,141,125,228,139, 69, 16,139,117, /* 0x 160 */ - 12,137, 69,156,165,165,165,131,109, 8, 12,129,125,228, 85, 80, /* 0x 170 */ - 88, 51,137,117, 12, 15,133,112, 1, 0, 0,199, 69,196, 47,116, /* 0x 180 */ -109,112,199, 69,200, 47,117,112,120,141, 77,215,106, 20, 88,205, /* 0x 190 */ -128,137,194,106, 4,137,200,141,125,211,232,249,254,255,255,139, /* 0x 1a0 */ - 85,228,198, 69,215, 0, 49,201, 49,208,141, 93,172,137, 69,132, /* 0x 1b0 */ -106, 78, 88,205,128,139, 85,172,137,248, 49, 85,132,139, 85,176, /* 0x 1c0 */ -199, 4, 36, 7, 0, 0, 0,141, 93,196,193,226, 12, 51, 85,132, /* 0x 1d0 */ -232,195,254,255,255, 88,106, 10, 88,205,128,131,248,254,116, 8, /* 0x 1e0 */ -133,192, 15,133, 3, 1, 0, 0,185,194, 0, 0, 0,186,192, 1, /* 0x 1f0 */ - 0, 0,141, 93,196,106, 5, 88,205,128,139, 85,232,137, 69,148, /* 0x 200 */ -137,195,137,209,106, 93, 88,205,128,133,192, 15,133,210, 0, 0, /* 0x 210 */ - 0,106, 0,255,117,148,106, 1,106, 3, 82,106, 0,232,106,254, /* 0x 220 */ -255,255,131,196, 24, 61, 0,240,255,255,137, 69,136, 15,135,176, /* 0x 230 */ - 0, 0, 0,139, 69,232,106, 0,106,255, 5,255, 15, 0, 0,106, /* 0x 240 */ - 50, 37, 0,240,255,255,106, 3, 3, 69,136,104, 0, 16, 0, 0, /* 0x 250 */ - 80,232, 54,254,255,255,131,196, 24,141,125,180,139,117, 12,165, /* 0x 260 */ -165,165,139, 77,180,131,109, 8, 12,133,201,137,117, 12,139, 85, /* 0x 270 */ -184,117, 16,129,250, 85, 80, 88, 33,117,104,131,125,232, 0,116, /* 0x 280 */ -116,235, 96, 57,202,119, 92, 59, 85,236,119, 87, 57,202,115, 37, /* 0x 290 */ -141, 69,168,255,117,188, 80,255,117,136, 82,255,117, 12,137, 77, /* 0x 2a0 */ -168,255, 85,156,131,196, 20,133,192,117, 56,139, 69,180, 57, 69, /* 0x 2b0 */ -168,117, 48,235, 8,139,125,136,139,117, 12,243,164,139, 85,180, /* 0x 2c0 */ -139, 93,136,137,209,106, 91, 88,205,128,139, 69,184, 41, 69, 8, /* 0x 2d0 */ - 1, 85,136, 41, 85,232, 1, 69, 12,131,125, 8, 0, 15,137,118, /* 0x 2e0 */ -255,255,255,141, 93,196,106, 10, 88,205,128,106,127, 91,106, 1, /* 0x 2f0 */ - 88,205,128,235,254,139, 93,148,106, 6, 88,205,128,133,192,117, /* 0x 300 */ -226,255,117, 28,255,117, 32,141,117,196, 86,232,172,253,255,255, /* 0x 310 */ -133,192,120,207,106, 2, 88,205,128,133,192,117, 51,106, 2, 88, /* 0x 320 */ -205,128,133,192,137,193,117, 31,199, 69,160, 85, 80, 88, 52,184, /* 0x 330 */ -162, 0, 0, 0,141, 93,160,199, 69,164, 0, 0, 0, 0,205,128, /* 0x 340 */ -137,243,106, 10, 88,205,128, 49,219,106, 1, 88,205,128,235,254, /* 0x 350 */ - 49,201,131,203,255,137,202,106, 7, 88,205,128,141, 93,196,139, /* 0x 360 */ - 77, 32,139, 85, 28,106, 11, 88,205,128,233,116,255,255,255, 0, /* 0x 370 */ - 87,137,215,106, 10,252, 89,232, 5, 0, 0, 0,136, 39,151, 95, /* 0x 380 */ -195,153,247,241, 82,133,192,116, 5,232,243,255,255,255, 88, 4, /* 0x 390 */ - 48,170,195 /* 0x 3a0 */ + 3,137,208,193,232, 5,137,194,226,229, 91,195, 85,137,229, 87, /* 0x c0 */ + 86, 49,255, 83,137,249,131,236, 96,137,250,139, 93, 8,106, 5, /* 0x d0 */ + 88,205,128,133,192,137,198, 15,136,199, 0, 0, 0,199, 69,212, /* 0x e0 */ + 47,112,114,111,199, 69,216, 99, 47, 0, 0,106, 20, 88,205,128, /* 0x f0 */ +141, 85,218,141, 93,212,232,213, 2, 0, 0,141, 80, 4,199, 0, /* 0x 100 */ + 47,102,100, 47,137,240,232,197, 2, 0, 0,186, 1, 0, 0, 0, /* 0x 110 */ +106, 33, 88,106, 5, 89,205,128, 61, 85, 80, 88, 50,117,126,139, /* 0x 120 */ + 93, 8,106, 10, 88,205,128,185, 2, 0, 0, 0,137,243,106, 55, /* 0x 130 */ + 88,205,128,141, 93,212,139, 77, 12,139, 85, 16,106, 11, 88,205, /* 0x 140 */ +128,186, 2, 0, 0, 0,137,243,137,249,106, 19, 88,205,128,106, /* 0x 150 */ + 0,137,199, 86,106, 2,106, 3, 80,106, 0,232, 44,255,255,255, /* 0x 160 */ +131,196, 24,137, 69,152,185,193, 0, 0, 0,186,192, 1, 0, 0, /* 0x 170 */ +139, 93, 8,106, 5, 88,205,128,137, 69,148,137,195,139, 77,152, /* 0x 180 */ +137,250,106, 4, 88,205,128, 57,199,116, 10,106,127, 91,106, 1, /* 0x 190 */ + 88,205,128,235,254,139, 93,148,106, 6, 88,205,128,137,243,106, /* 0x 1a0 */ + 6, 88,205,128,141,101,244,137,240, 91, 94, 95,201,194, 12, 0, /* 0x 1b0 */ + 85,137,229, 87, 86, 83,131,236,124,141,125,228,139, 69, 16,139, /* 0x 1c0 */ +117, 12,137, 69,156,165,165,165,131,109, 8, 12,129,125,228, 85, /* 0x 1d0 */ + 80, 88, 51,137,117, 12, 15,133,112, 1, 0, 0,199, 69,196, 47, /* 0x 1e0 */ +116,109,112,199, 69,200, 47,117,112,120,141, 77,215,106, 20, 88, /* 0x 1f0 */ +205,128,137,194,106, 4,137,200,141,125,211,232,152,254,255,255, /* 0x 200 */ +139, 85,228,198, 69,215, 0, 49,201, 49,208,141, 93,172,137, 69, /* 0x 210 */ +132,106, 78, 88,205,128,139, 85,172,137,248, 49, 85,132,139, 85, /* 0x 220 */ +176,199, 4, 36, 7, 0, 0, 0,141, 93,196,193,226, 12, 51, 85, /* 0x 230 */ +132,232, 98,254,255,255, 88,106, 10, 88,205,128,131,248,254,116, /* 0x 240 */ + 8,133,192, 15,133, 3, 1, 0, 0,185,194, 0, 0, 0,186,192, /* 0x 250 */ + 1, 0, 0,141, 93,196,106, 5, 88,205,128,139, 85,232,137, 69, /* 0x 260 */ +148,137,195,137,209,106, 93, 88,205,128,133,192, 15,133,210, 0, /* 0x 270 */ + 0, 0,106, 0,255,117,148,106, 1,106, 3, 82,106, 0,232, 9, /* 0x 280 */ +254,255,255,131,196, 24, 61, 0,240,255,255,137, 69,136, 15,135, /* 0x 290 */ +176, 0, 0, 0,139, 69,232,106, 0,106,255, 5,255, 15, 0, 0, /* 0x 2a0 */ +106, 50, 37, 0,240,255,255,106, 3, 3, 69,136,104, 0, 16, 0, /* 0x 2b0 */ + 0, 80,232,213,253,255,255,131,196, 24,141,125,180,139,117, 12, /* 0x 2c0 */ +165,165,165,139, 77,180,131,109, 8, 12,133,201,137,117, 12,139, /* 0x 2d0 */ + 85,184,117, 16,129,250, 85, 80, 88, 33,117,104,131,125,232, 0, /* 0x 2e0 */ +116,116,235, 96, 57,202,119, 92, 59, 85,236,119, 87, 57,202,115, /* 0x 2f0 */ + 37,141, 69,168,255,117,188, 80,255,117,136, 82,255,117, 12,137, /* 0x 300 */ + 77,168,255, 85,156,131,196, 20,133,192,117, 56,139, 69,180, 57, /* 0x 310 */ + 69,168,117, 48,235, 8,139,125,136,139,117, 12,243,164,139, 85, /* 0x 320 */ +180,139, 93,136,137,209,106, 91, 88,205,128,139, 69,184, 41, 69, /* 0x 330 */ + 8, 1, 85,136, 41, 85,232, 1, 69, 12,131,125, 8, 0, 15,137, /* 0x 340 */ +118,255,255,255,141, 93,196,106, 10, 88,205,128,106,127, 91,106, /* 0x 350 */ + 1, 88,205,128,235,254,139, 93,148,106, 6, 88,205,128,133,192, /* 0x 360 */ +117,226,255,117, 28,255,117, 32,141,117,196, 86,232, 75,253,255, /* 0x 370 */ +255,133,192,120,207,106, 2, 88,205,128,133,192,117, 51,106, 2, /* 0x 380 */ + 88,205,128,133,192,137,193,117, 31,199, 69,160, 85, 80, 88, 52, /* 0x 390 */ +184,162, 0, 0, 0,141, 93,160,199, 69,164, 0, 0, 0, 0,205, /* 0x 3a0 */ +128,137,243,106, 10, 88,205,128, 49,219,106, 1, 88,205,128,235, /* 0x 3b0 */ +254, 49,201,131,203,255,137,202,106, 7, 88,205,128,141, 93,196, /* 0x 3c0 */ +139, 77, 32,139, 85, 28,106, 11, 88,205,128,233,116,255,255,255, /* 0x 3d0 */ + 87,137,215,106, 10,252, 89,232, 5, 0, 0, 0,136, 39,151, 95, /* 0x 3e0 */ +195,153,247,241, 82,133,192,116, 5,232,243,255,255,255, 88, 4, /* 0x 3f0 */ + 48,170,195 /* 0x 400 */ }; diff --git a/src/stub/src/i386-linux.elf.execve-main.c b/src/stub/src/i386-linux.elf.execve-main.c index c3149054..de2a8764 100644 --- a/src/stub/src/i386-linux.elf.execve-main.c +++ b/src/stub/src/i386-linux.elf.execve-main.c @@ -187,6 +187,26 @@ go_self(char const *tmpname, char *argv[], char *envp[]) // Execute the original program via /proc/self/fd/X. execve(procself_buf, argv, envp); // NOTE: if we get here we've lost. + + // 2008-March: Ubuntu 7.10 linux-image-2.6.22-14.52-generic + // and SuSE 10.3 have a patch to fs/dcache.c which causes + // execve() [above] to fail with ENOENT. + // Fedora kernel-2.6.22.14-72.fc6 omits the patch, and works: +// https://sourceforge.net/tracker/?func=detail&atid=102331&aid=1825006&group_id=2331 + + // Now we must re-create the file; it was unlink()ed! + // link(procself_buf, tmpname) gets EXDEV (cross-device link). + // Luckily we still have an open fdi to the file. + // Errors from {lseek, mmap, open, write} are all caught + // by the one check on write(). + unsigned const lenf = lseek(fdi, 0, SEEK_END); + char *const buf = mmap((char *)0, lenf, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fdi, 0); + int const fdo = open(tmpname, O_WRONLY | O_CREAT | O_EXCL, 0700); + if (lenf!=(unsigned)write(fdo, buf, lenf)) { + exit(127); + } + close(fdo); } // The proc filesystem isn't working. No problem. diff --git a/src/stub/src/include/linux.h b/src/stub/src/include/linux.h index caa13ffa..f325f719 100644 --- a/src/stub/src/include/linux.h +++ b/src/stub/src/include/linux.h @@ -103,6 +103,7 @@ struct timespec { #define SEEK_SET 0 #define SEEK_CUR 1 +#define SEEK_END 2 #define O_RDONLY 00 #define O_WRONLY 01