Share

UPX - a powerful executable packer

Tracker: Bugs

5 Linux ELF exes which use RPATH are incorrecly packed - ID: 1947878
Last Update: Comment added ( sf-robot )

When an ELF executable using rpath to locate its libraries is compressed
with UPX, it will not work anymore.

I've written (and attached) a small example:

$ make
gcc -o lib/libsomelib.so somelib.c -fPIC -shared
gcc -o test test.c -Wl,-rpath,'$ORIGIN'/lib -Llib -lsomelib

$ ldd test
linux-gate.so.1 => (0xb7f87000)
libsomelib.so => /mnt/work/testupx/lib/libsomelib.so (0xb7f84000)
libc.so.6 => /lib/libc.so.6 (0xb7e1f000)
/lib/ld-linux.so.2 (0xb7f88000)

$ ./test

asdaaaaaaaaaaaa...[etc.]

$ upx --best test
Ultimate Packer for eXecutables
Copyright (C)
1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007
UPX 3.02 Markus Oberhumer, Laszlo Molnar & John Reiser Dec 16th
2007

File size Ratio Format Name
-------------------- ------ ----------- -----------
22507 -> 4968 22.07% linux/elf386 test


$ ./test
./test: error while loading shared libraries: libsomelib.so: cannot open
shared object file: No such file or directory


I've attached the test case for this issue.


DragonK ( dragonk ) - 2008-04-21 14:05

5

Closed

Rejected

John Reiser

None

None

Public


Comments ( 3 )




Date: 2008-05-13 02:20
Sender: sf-robotSourceForge.net Site Admin


This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).


Date: 2008-04-28 14:05
Sender: jreiser


The behavior occurs because ld-linux.so.2 uses readlink("/proc/self/exe",)
when expanding $ORIGIN for rpath. The upx runtime decompression stub is so
good at removing all traces of itself, that *all* pages of the original
executable are unmapped, and under these circumstances the kernel erases
the symlink for /proc/self/exe. Removing all traces of the stub is
desirable so that the process has no interference with its address space
because of compression.

The upx decompression stub saves the original value of
readlink("/proc/self/exe",) as the value of new environment variable " "
[three spaces.] Also, the linux kernel puts the filename that was
specified as the first argument to execve(), into the process address space
as (char *)(1+ strlen(env[-1+ n_env]) + env[-1+ n_env]) where env and n_env
are the original environment and number of environment variables. The upx
decompression stub adds its environment variable " " [three spaces] in a
compatible way.

If readlink("/proc/self/exe",) fails then ld-linux should use some other
algorithm, such as the one involving env[-1 + n_env]. That is faster
anyway; but it requires ld-linux to save [a pointer to] the value upon
invocation, and it might regquire that the linux kernel admit [document]
its behavior. Complain to ld-linux. Note that $ORIGIN fails anyway if
some other process unmounts it between the execve() and the search for the
library; thus -rpath is not robust.


Date: 2008-04-21 14:39
Sender: dragonk


I need to mention that this applies only to executables using $ORIGIN in
rpath


Log in to comment.

Attached File ( 1 )

Filename Description Download
testupx.tar.gz Test for the RPATH issue Download

Changes ( 7 )

Field Old Value Date By
status_id Pending 2008-05-13 02:20 sf-robot
close_date 2008-04-28 14:05 2008-05-13 02:20 sf-robot
close_date - 2008-04-28 14:05 jreiser
resolution_id None 2008-04-28 14:05 jreiser
status_id Open 2008-04-28 14:05 jreiser
assigned_to nobody 2008-04-28 12:53 mfx
File Added 275350: testupx.tar.gz 2008-04-21 14:05 dragonk