On Sat, 2017-09-09 at 22:04 +0200, Samuel Thibault wrote:
> Svante Signell, on sam. 09 sept. 2017 10:51:36 +0200, wrote:
> > On Fri, 2017-09-08 at 00:39 +0200, Samuel Thibault wrote:
> > > That goes back to file_exec_file_name provided with a relative path, and
> > > not
> > > an
> > > absolute path. That's where it needs fixing. I guess it could be a
> > > matter of making sysdeps/mach/hurd/execve.c call realpath(), as well as
> > > sysdeps/mach/hurd/spawni.c in the
> > > if ((xflags & SPAWN_XFLAGS_USE_PATH) == 0 || strchr (file, '/') != NULL)
> > > case.
> >
> > Sorry, but none of these changes had any effect. I built a new libc.so
> > including
> > print statements and run the programs with both LD_PRELOAD and
> > LD_LIBRARY_PATH.
> > No difference.
>
> Which programs do you run?
>
> execv/spawn are called from the parent, so the program that needs
> LD_LIBRARY_PATH is the parent of the program to be observed in
> /proc/pid/exe
Attached is a diff of the patch submitted-exec-filename.diff using realpath for
execve.c and spawni.c. The change of __execve fixes the /proc/self/exe problem.
What about freeing filename/file_name, using lstat instead of second argument of
realpath being NULL, declaring filename as const char* etc?
The second change of __spawni I did not find being effective. I added print
statements to all cases of the if then else construct, and nothing was printed
when running the test code with sh -c "..."
(some tab vs blank space differences might still be present)
--- ../submitted-exec_filename.diff.orig 2017-09-11 09:28:18.000000000 +0200
+++ ../submitted-exec_filename.diff 2017-09-11 09:22:09.000000000 +0200
@@ -199,16 +199,43 @@
===================================================================
--- glibc-2.24-17.1x.orig/sysdeps/mach/hurd/execve.c
+++ glibc-2.24-17.1x/sysdeps/mach/hurd/execve.c
-@@ -31,7 +31,8 @@ __execve (const char *file_name, char *c
+@@ -19,23 +19,32 @@
+ #include <hurd.h>
+ #include <fcntl.h>
+
+-/* Replace the current process, executing FILE_NAME with arguments ARGV and
+- environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
++/* Replace the current process, executing FILENAME, a canonicalized
++ absolute pathname from FILE_NAME, with arguments ARGV and
++ environment ENVP. ARGV and ENVP are terminated by NULL
++ pointers. */
+ int
+ __execve (const char *file_name, char *const argv[], char *const envp[])
+ {
+ error_t err;
+- file_t file = __file_name_lookup (file_name, O_EXEC, 0);
++ char *filename = NULL;
+
++ filename = realpath (file_name, NULL);
++ if (filename == NULL)
++ return -1;
++
++ file_t file = __file_name_lookup (filename, O_EXEC, 0);
+ if (file == MACH_PORT_NULL)
return -1;
/* Hopefully this will not return. */
- err = _hurd_exec (__mach_task_self (), file, argv, envp);
+ err = _hurd_exec_file_name (__mach_task_self (), file,
-+ file_name, argv, envp);
++ filename, argv, envp);
/* Oh well. Might as well be tidy. */
__mach_port_deallocate (__mach_task_self (), file);
+
++ free (filename);
+ return __hurd_fail (err);
+ }
+
Index: glibc-2.24-17.1x/sysdeps/mach/hurd/fexecve.c
===================================================================
--- glibc-2.24-17.1x.orig/sysdeps/mach/hurd/fexecve.c
@@ -268,16 +295,31 @@
except that all errors will be detected here (in the parent process)
and return proper errno codes rather than the child dying with 127.
-@@ -546,7 +548,7 @@ __spawni (pid_t *pid, const char *file,
+@@ -545,8 +547,21 @@ __spawni (pid_t *pid, const char *file,
+ etc) can be observed before what errors. */
if ((xflags & SPAWN_XFLAGS_USE_PATH) == 0 || strchr (file, '/') != NULL)
- /* The FILE parameter is actually a path. */
+- /* The FILE parameter is actually a path. */
- err = child_lookup (file, O_EXEC, 0, &execfile);
-+ err = child_lookup (filename = file, O_EXEC, 0, &execfile);
++ {
++ /* The FILE parameter is actually a path. */
++
++ /* path is not absolute */
++ if (strchr (file, '/') == NULL)
++ {
++ char *file_name = realpath (file, NULL);
++ if (file_name == NULL)
++ return -1;
++ err = child_lookup (filename = file_name, O_EXEC, 0, &execfile);
++ free (file_name);
++ }
++ else
++ err = child_lookup (filename = file, O_EXEC, 0, &execfile);
++ }
else
{
/* We have to search for FILE on the path. */
-@@ -573,20 +575,18 @@ __spawni (pid_t *pid, const char *file,
+@@ -573,20 +588,18 @@ __spawni (pid_t *pid, const char *file,
p = path;
do
{
@@ -301,7 +343,7 @@
switch (err)
{
case EACCES:
-@@ -623,14 +623,27 @@ __spawni (pid_t *pid, const char *file,
+@@ -623,14 +636,27 @@ __spawni (pid_t *pid, const char *file,
inline error_t exec (file_t file)
{