check that stack overflow link wink
I didn't see the answer in there.
FWIW I tried it with the following C program:
#define_GNU_SOURCE#include<sys/mman.h>#include<unistd.h>#include<fcntl.h>charelf[] = {
#include"elf.xxd"
};
intmain() {
intfd=memfd_create("foo", MFD_CLOEXEC);
if (fd==-1) return1;
if (write(fd, elf, sizeofelf) <0) return2;
if (fd!=3) return3;
fd=open("/proc/self/fd/3", O_RDONLY);
if (-1==fd) return4;
if (-1==close(3)) return5;
char*cmd[] = { "ls", "-l", "/proc/self/fd/", "/proc/self/exe", NULL };
char*env[] = { NULL };
if (-1==fexecve(fd, cmd, env)) return6;
return7;
}Where elf.xxd is created with xxd -i < /usr/bin/ls > elf.xxd
And I see:
lrwxrwxrwx 1 root root 0 May 27 16:15 /proc/self/exe -> '/memfd:foo (deleted)'
/proc/self/fd:
total 0
lrwx------ 1 root root 64 May 27 16:15 0 -> /dev/pts/1
lrwx------ 1 root root 64 May 27 16:15 1 -> /dev/pts/1
lrwx------ 1 root root 64 May 27 16:15 2 -> /dev/pts/1
lr-x------ 1 root root 64 May 27 16:15 3 -> /proc/18364/fd
lr-x------ 1 root root 64 May 27 16:15 4 -> '/memfd:foo (deleted)'
Originally posted by @daurnimator in #2527
I didn't see the answer in there.
FWIW I tried it with the following C program:
Where
elf.xxdis created withxxd -i < /usr/bin/ls > elf.xxdAnd I see:
Originally posted by @daurnimator in #2527