Bug 2101 - When loading binary not compiled with the correct options, dce crashes default tip
authorHajime Tazaki <tazaki@sfc.wide.ad.jp>
Mon, 01 Jun 2015 14:21:35 +0900
changeset 664 213835f32c54
parent 663 0ef3608fee11
Bug 2101 - When loading binary not compiled with the correct options, dce crashes
vdl-dl.c
vdl-file.h
vdl-map.c
--- a/vdl-dl.c	Thu Jul 24 11:15:08 2014 +0900
+++ b/vdl-dl.c	Mon Jun 01 14:21:35 2015 +0900
@@ -184,6 +184,17 @@
       map.requested->is_executable = 1;
     }
 
+  /* from _dl_map_object_from_fd() of glibc/elf/dl-load.c (glibc-2.20) */
+  /* This object is loaded at a fixed address.  This must never
+     happen for objects loaded with dlopen.  */
+  if ((map.requested->e_type != ET_DYN) &&
+      (map.requested->is_executable == 0))
+    {
+      VDL_LOG_DEBUG ("Unable to load requested %s: %s", filename, map.error_string);
+      set_error ("Unable to load: \"%s\"", filename);
+      goto error;
+    }
+
   bool ok = vdl_tls_file_initialize (map.newly_mapped);
 
   if (!ok)
@@ -292,6 +303,7 @@
 }
 void *vdl_dlopen (const char *filename, int flags)
 {
+  VDL_LOG_FUNCTION ("filename=%s", filename);
   futex_lock (g_vdl.futex);
   // map it in memory using the normal context, that is, the
   // first context in the context list.
@@ -402,6 +414,7 @@
 int vdl_dladdr1 (const void *addr, Dl_info *info, 
 		 void **extra_info, int flags)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlFile *file = addr_to_file ((unsigned long)addr);
   if (file == 0)
@@ -592,6 +605,7 @@
 			 void *data,
 			 unsigned long caller)
 {
+  VDL_LOG_FUNCTION ("", 0);
   int ret = 0;
   futex_lock (g_vdl.futex);
   struct VdlFile *file = addr_to_file (caller);
@@ -633,6 +647,7 @@
 }
 void *vdl_dlmopen (Lmid_t lmid, const char *filename, int flag)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlContext *context;
   if (lmid == LM_ID_BASE)
@@ -660,6 +675,7 @@
 }
 int vdl_dlinfo (void *handle, int request, void *p)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlFile *file = search_file (handle);
   if (file == 0)
@@ -714,6 +730,7 @@
 }
 Lmid_t vdl_dl_lmid_new (int argc, char **argv, char **envp)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlContext *context = vdl_context_new (argc, argv, envp);
   Lmid_t lmid = (Lmid_t) context;
@@ -722,6 +739,7 @@
 }
 void vdl_dl_lmid_delete (Lmid_t lmid)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlContext *context = (struct VdlContext *) lmid;
   if (search_context (context) == 0)
@@ -757,6 +775,7 @@
 			      void (*cb) (void *handle, int event, void *context),
 			      void *cb_context)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlContext *context = (struct VdlContext *)lmid;
   if (search_context (context) == 0)
@@ -775,6 +794,7 @@
 int
 vdl_dl_lmid_add_lib_remap (Lmid_t lmid, const char *src, const char *dst)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlContext *context = (struct VdlContext *)lmid;
   if (search_context (context) == 0)
@@ -796,6 +816,7 @@
 				  const char *dst_ver_name,
 				  const char *dst_ver_filename)
 {
+  VDL_LOG_FUNCTION ("", 0);
   futex_lock (g_vdl.futex);
   struct VdlContext *context = (struct VdlContext *)lmid;
   if (search_context (context) == 0)
--- a/vdl-file.h	Thu Jul 24 11:15:08 2014 +0900
+++ b/vdl-file.h	Mon Jun 01 14:21:35 2015 +0900
@@ -197,6 +197,7 @@
   const char *dt_rpath;
   const char *dt_runpath;
   const char *dt_soname;
+  ElfW(Half) e_type;
 };
 
 #endif /* VDL_FILE_H */
--- a/vdl-map.c	Thu Jul 24 11:15:08 2014 +0900
+++ b/vdl-map.c	Mon Jun 01 14:21:35 2015 +0900
@@ -691,6 +691,7 @@
   
   file->phdr = phdr;
   file->phnum = header.e_phnum;
+  file->e_type = header.e_type;
 
   system_close (fd);