Alan Cox wrote:
> execve /proc/self/fd/n ???
Inspired by this and because Alan of course cannot be wrong about
something as simple as this I went on and implemented it. Just to jind
that it's not working properly. Try this:
$ echo -e "#! /bin/sh\necho u1" > u1
$ chmod +x u1
$ echo -e "#! /bin/sh\necho u2" > u2
$ chmod +x u2
$ cat u.c
int
main()
{
system ("cp -f u1 uu");
int fd = open ("./uu", 0);
char buf[100];
sprintf (buf, "/proc/self/fd/%d", fd);
char buf2[100];
int n = readlink (buf, buf2, sizeof (buf2));
buf2[n] = '\0';
system ("cp -f u2 uu");
execl (buf, buf2, "hallo", 0);
return 0;
}
$ gcc -c o u u.c
$ ./u
You should see 'u2' as the result. But this is exactly what the fexecve
call is supposed to prevent. The file, once opened, should be reused.
The expected result is 'u1'.
The problem is, as you can see from the readlink call in strace's
output, that /proc/self/fd/XXX is used as a symlink in the execve call.
The symlink of course refers to 'u2'.
And thinking back, I did try to write fexecve like this back when...
Anyway, any solution to this is welcome since the missing fexecve is
regularly asked for.
- --
- --------------. ,-. 444 Castro Street
Ulrich Drepper \ ,-----------------' \ Mountain View, CA 94041 USA
Red Hat `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9xtor2ijCOnn/RHQRAgHQAJ9YsYVnX9rKVYf9Rzy4fgUx5195pgCghnXC
b5ZIJ1+vivZ2pWTmLxdrXtc=
=vJwO
-----END PGP SIGNATURE-----
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/