c6d234
commit 10e93d968716ab82931d593bada121c17c0a4b93
c6d234
Author: Dmitry V. Levin <ldv@altlinux.org>
c6d234
Date:   Mon Dec 18 21:46:07 2017 +0000
c6d234
c6d234
    elf: remove redundant __libc_enable_secure check from fillin_rpath
c6d234
    
c6d234
    There are just two users of fillin_rpath: one is decompose_rpath that
c6d234
    sets check_trusted argument to 0, another one is _dl_init_paths that
c6d234
    sets check_trusted argument to __libc_enable_secure and invokes
c6d234
    fillin_rpath only when LD_LIBRARY_PATH is non-empty.
c6d234
    
c6d234
    Starting with commit
c6d234
    glibc-2.25.90-512-gf6110a8fee2ca36f8e2d2abecf3cba9fa7b8ea7d,
c6d234
    LD_LIBRARY_PATH is ignored for __libc_enable_secure executables,
c6d234
    so check_trusted argument of fillin_rpath is always zero.
c6d234
    
c6d234
    * elf/dl-load.c (is_trusted_path): Remove.
c6d234
    (fillin_rpath): Remove check_trusted argument and its use,
c6d234
    all callers changed.
c6d234
c6d234
Index: glibc-2.17-c758a686/elf/dl-load.c
c6d234
===================================================================
c6d234
--- glibc-2.17-c758a686.orig/elf/dl-load.c
c6d234
+++ glibc-2.17-c758a686/elf/dl-load.c
c6d234
@@ -169,24 +169,6 @@ local_strdup (const char *s)
c6d234
 
c6d234
 
c6d234
 static bool
c6d234
-is_trusted_path (const char *path, size_t len)
c6d234
-{
c6d234
-  const char *trun = system_dirs;
c6d234
-
c6d234
-  for (size_t idx = 0; idx < nsystem_dirs_len; ++idx)
c6d234
-    {
c6d234
-      if (len == system_dirs_len[idx] && memcmp (trun, path, len) == 0)
c6d234
-	/* Found it.  */
c6d234
-	return true;
c6d234
-
c6d234
-      trun += system_dirs_len[idx] + 1;
c6d234
-    }
c6d234
-
c6d234
-  return false;
c6d234
-}
c6d234
-
c6d234
-
c6d234
-static bool
c6d234
 is_trusted_path_normalize (const char *path, size_t len)
c6d234
 {
c6d234
   if (len == 0)
c6d234
@@ -487,8 +469,7 @@ static size_t max_dirnamelen;
c6d234
 
c6d234
 static struct r_search_path_elem **
c6d234
 fillin_rpath (char *rpath, struct r_search_path_elem **result, const char *sep,
c6d234
-	      int check_trusted, const char *what, const char *where,
c6d234
-	      struct link_map *l)
c6d234
+	      const char *what, const char *where, struct link_map *l)
c6d234
 {
c6d234
   char *cp;
c6d234
   size_t nelems = 0;
c6d234
@@ -518,13 +499,6 @@ fillin_rpath (char *rpath, struct r_sear
c6d234
       if (len > 0 && cp[len - 1] != '/')
c6d234
 	cp[len++] = '/';
c6d234
 
c6d234
-      /* Make sure we don't use untrusted directories if we run SUID.  */
c6d234
-      if (__builtin_expect (check_trusted, 0) && !is_trusted_path (cp, len))
c6d234
-	{
c6d234
-	  free (to_free);
c6d234
-	  continue;
c6d234
-	}
c6d234
-
c6d234
       /* See if this directory is already known.  */
c6d234
       for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
c6d234
 	if (dirp->dirnamelen == len && memcmp (cp, dirp->dirname, len) == 0)
c6d234
@@ -674,7 +648,7 @@ decompose_rpath (struct r_search_path_st
c6d234
       _dl_signal_error (ENOMEM, NULL, NULL, errstring);
c6d234
     }
c6d234
 
c6d234
-  fillin_rpath (copy, result, ":", 0, what, where, l);
c6d234
+  fillin_rpath (copy, result, ":", what, where, l);
c6d234
 
c6d234
   /* Free the copied RPATH string.  `fillin_rpath' make own copies if
c6d234
      necessary.  */
c6d234
@@ -847,8 +821,7 @@ _dl_init_paths (const char *llp)
c6d234
 	}
c6d234
 
c6d234
       (void) fillin_rpath (llp_tmp, env_path_list.dirs, ":;",
c6d234
-			   INTUSE(__libc_enable_secure), "LD_LIBRARY_PATH",
c6d234
-			   NULL, l);
c6d234
+			   "LD_LIBRARY_PATH", NULL, l);
c6d234
 
c6d234
       if (env_path_list.dirs[0] == NULL)
c6d234
 	{