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