Is it possible to change the value of "/proc/self/exe" for an exec'ed child process?

1.4k Views Asked by At

I'm trying to use an exec system call to start another executable, but that executable is using readlink() on /proc/self/exe to determine its file location. I would like it to think that it has the same location as the parent executable, but it instead determines its actual location. I think that I could potentially accomplish something like this by using LD_PRELOAD to intercept the readlink() call, but is there any easier or more direct way to accomplish this? I'm looking only for solutions that can be implemented in the parent executable, modifying the child is not an option.

1

There are 1 best solutions below

0
wildplasser On

Create a hard link to the executable:


$sudo ln /bin/ls ./ls
[sudo] password for plasser: 

# check it:
$ls -l ls
-rwxr-xr-x 2 root root 110080 mrt 10  2016 ls

#call it:
$./ls -l /proc/self/exe
lrwxrwxrwx 1 plasser uri 0 mrt  3 18:36 /proc/self/exe -> /home/plasser/krant/ls
$