[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[HURD PATCH 3/7] Hurd startup: fetch the exec filename using exec_startu

From: Jeremie Koenig
Subject: [HURD PATCH 3/7] Hurd startup: fetch the exec filename using exec_startup_get_info_2
Date: Wed, 17 Aug 2011 21:35:28 +0200

        * hurd/hurd.h (_hurd_init_filename): Declare new variable.
        * hurd/hurdstartup.c (_hurd_init_filename): Define.
        (_hurd_startup): Use exec_startup_get_info_2 if available, to fetch
        * sysdeps/mach/hurd/configure.in: Check for exec_startup_get_info_2.
 hurd/hurd.h                    |   11 +++++++++++
 hurd/hurdstartup.c             |   24 +++++++++++++++++++++++-
 sysdeps/mach/hurd/configure.in |    3 +++
 3 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/hurd/hurd.h b/hurd/hurd.h
index 3429f66..ccd17c1 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -101,24 +101,35 @@ extern error_t _hurd_ports_use (int which, error_t 
(*operate) (mach_port_t));
    If using cthreads, this stack is deallocated in startup.
    Not locked.  */
 extern vm_address_t _hurd_stack_base;
 extern vm_size_t _hurd_stack_size;
 /* Initial file descriptor table we were passed at startup.  If we are
    using a real dtable, these are turned into that and then cleared at
    startup.  If not, these are never changed after startup.  Not locked.  */
 extern mach_port_t *_hurd_init_dtable;
 extern mach_msg_type_number_t _hurd_init_dtablesize;
+/* File name passed at startup by the exec server.  May not be present,
+   in which case it will stay an empty string.
+   We trust the exec server on this one, especially with respect to its
+   reliability in EXEC_SECURE circumstances.  Rationale: exec could clear
+   the flag in question anyway.  This might be an ugly guess but must not
+   be exploitable to gain setuid priviledges through RPATH/$ORIGIN, for
+   instance.  */
+extern string_t _hurd_init_filename;
 /* Current process IDs.  */
 extern pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
 extern int _hurd_orphaned;
 /* This variable is incremented every time the process IDs change.  */
 extern unsigned int _hurd_pids_changed_stamp;
 /* This condition is broadcast every time the process IDs change.  */
 extern struct condition _hurd_pids_changed_sync;
diff --git a/hurd/hurdstartup.c b/hurd/hurdstartup.c
index 0c607ba..577886d 100644
--- a/hurd/hurdstartup.c
+++ b/hurd/hurdstartup.c
@@ -24,24 +24,25 @@
 #include <hurd.h>
 #include <hurd/exec_startup.h>
 #include <sysdep.h>
 #include <hurd/threadvar.h>
 #include <unistd.h>
 #include <elf.h>
 #include <set-hooks.h>
 #include "hurdstartup.h"
 #include <argz.h>
 mach_port_t *_hurd_init_dtable;
 mach_msg_type_number_t _hurd_init_dtablesize;
+string_t _hurd_init_filename;
 extern void __mach_init (void);
 /* Entry point.  This is the first thing in the text segment.
    The exec server started the initial thread in our task with this spot the
    PC, and a stack that is presumably big enough.  We do basic Mach
    initialization so mig-generated stubs work, and then do an exec_startup
    RPC on our bootstrap port, to which the exec server responds with the
    information passed in the exec call, as well as our original bootstrap
    port, and the base address and size of the preallocated stack.
@@ -77,34 +78,55 @@ _hurd_startup (void **argptr, void (*main) (intptr_t *data))
   if (err = __task_get_special_port (__mach_task_self (), TASK_BOOTSTRAP_PORT,
   if (in_bootstrap != MACH_PORT_NULL)
       /* Call the exec server on our bootstrap port and
         get all our standard information from it.  */
       argslen = envlen = 0;
       data.dtablesize = data.portarraysize = data.intarraysize = 0;
-      err = __exec_startup_get_info (in_bootstrap,
+      err = __exec_startup_get_info_2 (in_bootstrap,
                                     &data.phdr, &data.phdrsz,
                                     &data.stack_base, &data.stack_size,
+                                    _hurd_init_filename,
                                     &args, &argslen,
                                     &env, &envlen,
                                     &data.dtable, &data.dtablesize,
                                     &data.portarray, &data.portarraysize,
                                     &data.intarray, &data.intarraysize);
+      /* Clear _hurd_init_filename if it's too long, or if we failed.  */
+      if (err || _hurd_init_filename[sizeof (string_t) - 1])
+       memset (_hurd_init_filename, 0, sizeof (string_t));
+      /* Fall back to the legacy version.  */
+      if (err == MIG_BAD_ID)
+       {
+         err = __exec_startup_get_info (in_bootstrap,
+                                        &data.user_entry,
+                                        &data.phdr, &data.phdrsz,
+                                        &data.stack_base, &data.stack_size,
+                                        &data.flags,
+                                        &args, &argslen,
+                                        &env, &envlen,
+                                        &data.dtable, &data.dtablesize,
+                                        &data.portarray, &data.portarraysize,
+                                        &data.intarray, &data.intarraysize);
+       }
       __mach_port_deallocate (__mach_task_self (), in_bootstrap);
   if (err || in_bootstrap == MACH_PORT_NULL || (data.flags & EXEC_STACK_ARGS))
       /* Either we have no bootstrap port, or the RPC to the exec server
         failed, or whoever started us up passed the flag saying args are
         on the stack.  Try to snarf the args in the canonical Mach way.
         Hopefully either they will be on the stack as expected, or the
         stack will be zeros so we don't crash.  */
       argcptr = (intptr_t *) argptr;
diff --git a/sysdeps/mach/hurd/configure.in b/sysdeps/mach/hurd/configure.in
index 370be79..59704d6 100644
--- a/sysdeps/mach/hurd/configure.in
+++ b/sysdeps/mach/hurd/configure.in
@@ -17,24 +17,27 @@ fi
 case "$machine" in
     # The default oldest ABI is 2.2.6.
     # We only need a "yes" here if the oldest ABI supported will be < 2.2.6.
     if test "$oldest_abi" != default && test "$oldest_abi" \< "2.2.6"; then
 AC_CHECK_MIG_FUNC([/usr/include/hurd/fs.defs], [file_exec_file_name],,
   [AC_MSG_ERROR('Your Hurd definitions dont provide file_exec_file_name')])
+  [exec_startup_get_info_2],,
+  [AC_MSG_ERROR('Your Hurd definitions do not provide 
 AC_CACHE_CHECK(Hurd header version, libc_cv_hurd_version, [dnl
 [#include <hurd/version.h>], [
 #define NEED_VERSION 20020609
 # error Hurd version too old: HURD_INTERFACE_VERSION < NEED_VERSION
 if test "x$libc_cv_hurd_version" != xok; then
   AC_MSG_ERROR(Hurd headers not installed or too old)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]