Blame SOURCES/glibc-rh667974.patch

b40826
2011-03-14  Andreas Schwab  <schwab@redhat.com>
b40826
b40826
	* elf/dl-load.c (is_dst): Remove parameter secure, all callers
b40826
	changed.  Don't check for isolated use.
b40826
	(_dl_dst_substitute): Ignore rpath elements containing
b40826
	non-isolated use of $ORIGIN when privileged.
b40826
b40826
	* elf/dl-load.c (_dl_dst_substitute): When skipping the first
b40826
	rpath element also skip the following colon.
b40826
	(expand_dynamic_string_token): Add is_path parameter and pass
b40826
	down to DL_DST_REQUIRED and _dl_dst_substitute.
b40826
	(decompose_rpath): Call expand_dynamic_string_token with
b40826
	non-zero is_path.  Ignore empty rpaths.
b40826
	(_dl_map_object_from_fd): Call expand_dynamic_string_token
b40826
	with zero is_path.
b40826
b40826
Index: glibc-2.12-2-gc4ccff1/elf/dl-load.c
b40826
===================================================================
b40826
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-load.c
b40826
+++ glibc-2.12-2-gc4ccff1/elf/dl-load.c
b40826
@@ -169,8 +169,7 @@ local_strdup (const char *s)
b40826
 
b40826
 
b40826
 static size_t
b40826
-is_dst (const char *start, const char *name, const char *str,
b40826
-	int is_path, int secure)
b40826
+is_dst (const char *start, const char *name, const char *str, int is_path)
b40826
 {
b40826
   size_t len;
b40826
   bool is_curly = false;
b40826
@@ -199,11 +198,6 @@ is_dst (const char *start, const char *n
b40826
 	   && (!is_path || name[len] != ':'))
b40826
     return 0;
b40826
 
b40826
-  if (__builtin_expect (secure, 0)
b40826
-      && ((name[len] != '\0' && (!is_path || name[len] != ':'))
b40826
-	  || (name != start + 1 && (!is_path || name[-2] != ':'))))
b40826
-    return 0;
b40826
-
b40826
   return len;
b40826
 }
b40826
 
b40826
@@ -218,13 +212,10 @@ _dl_dst_count (const char *name, int is_
b40826
     {
b40826
       size_t len;
b40826
 
b40826
-      /* $ORIGIN is not expanded for SUID/GUID programs (except if it
b40826
-	 is $ORIGIN alone) and it must always appear first in path.  */
b40826
       ++name;
b40826
-      if ((len = is_dst (start, name, "ORIGIN", is_path,
b40826
-			 INTUSE(__libc_enable_secure))) != 0
b40826
-	  || (len = is_dst (start, name, "PLATFORM", is_path, 0)) != 0
b40826
-	  || (len = is_dst (start, name, "LIB", is_path, 0)) != 0)
b40826
+      if ((len = is_dst (start, name, "ORIGIN", is_path)) != 0
b40826
+	  || (len = is_dst (start, name, "PLATFORM", is_path)) != 0
b40826
+	  || (len = is_dst (start, name, "LIB", is_path)) != 0)
b40826
 	++cnt;
b40826
 
b40826
       name = strchr (name + len, '$');
b40826
@@ -256,9 +247,16 @@ _dl_dst_substitute (struct link_map *l, 
b40826
 	  size_t len;
b40826
 
b40826
 	  ++name;
b40826
-	  if ((len = is_dst (start, name, "ORIGIN", is_path,
b40826
-			     INTUSE(__libc_enable_secure))) != 0)
b40826
+	  if ((len = is_dst (start, name, "ORIGIN", is_path)) != 0)
b40826
 	    {
b40826
+	      /* $ORIGIN is not expanded for SUID/GUID programs
b40826
+		 (except if it is $ORIGIN alone) and it must always
b40826
+		 appear first in path.  */
b40826
+	      if (__builtin_expect (INTUSE(__libc_enable_secure), 0)
b40826
+		  && ((name[len] != '\0' && (!is_path || name[len] != ':'))
b40826
+		      || (name != start + 1 && (!is_path || name[-2] != ':'))))
b40826
+		repl = (const char *) -1;
b40826
+	      else
b40826
 #ifndef SHARED
b40826
 	      if (l == NULL)
b40826
 		repl = _dl_get_origin ();
b40826
@@ -266,9 +264,9 @@ _dl_dst_substitute (struct link_map *l, 
b40826
 #endif
b40826
 		repl = l->l_origin;
b40826
 	    }
b40826
-	  else if ((len = is_dst (start, name, "PLATFORM", is_path, 0)) != 0)
b40826
+	  else if ((len = is_dst (start, name, "PLATFORM", is_path)) != 0)
b40826
 	    repl = GLRO(dl_platform);
b40826
-	  else if ((len = is_dst (start, name, "LIB", is_path, 0)) != 0)
b40826
+	  else if ((len = is_dst (start, name, "LIB", is_path)) != 0)
b40826
 	    repl = DL_DST_LIB;
b40826
 
b40826
 	  if (repl != NULL && repl != (const char *) -1)
b40826
@@ -284,6 +282,10 @@ _dl_dst_substitute (struct link_map *l, 
b40826
 	      name += len;
b40826
 	      while (*name != '\0' && (!is_path || *name != ':'))
b40826
 		++name;
b40826
+	      /* Also skip following colon if this is the first rpath
b40826
+		 element, but keep an empty element at the end.  */
b40826
+	      if (wp == result && is_path && *name == ':' && name[1] != '\0')
b40826
+		++name;
b40826
 	    }
b40826
 	  else
b40826
 	    /* No DST we recognize.  */
b40826
@@ -310,7 +312,7 @@ _dl_dst_substitute (struct link_map *l, 
b40826
    belonging to the map is loaded.  In this case the path element
b40826
    containing $ORIGIN is left out.  */
b40826
 static char *
b40826
-expand_dynamic_string_token (struct link_map *l, const char *s)
b40826
+expand_dynamic_string_token (struct link_map *l, const char *s, int is_path)
b40826
 {
b40826
   /* We make two runs over the string.  First we determine how large the
b40826
      resulting string is and then we copy it over.  Since this is no
b40826
@@ -321,7 +323,7 @@ expand_dynamic_string_token (struct link
b40826
   char *result;
b40826
 
b40826
   /* Determine the number of DST elements.  */
b40826
-  cnt = DL_DST_COUNT (s, 1);
b40826
+  cnt = DL_DST_COUNT (s, is_path);
b40826
 
b40826
   /* If we do not have to replace anything simply copy the string.  */
b40826
   if (__builtin_expect (cnt, 0) == 0)
b40826
@@ -335,7 +337,7 @@ expand_dynamic_string_token (struct link
b40826
   if (result == NULL)
b40826
     return NULL;
b40826
 
b40826
-  return _dl_dst_substitute (l, s, result, 1);
b40826
+  return _dl_dst_substitute (l, s, result, is_path);
b40826
 }
b40826
 
b40826
 
b40826
@@ -551,13 +553,21 @@ decompose_rpath (struct r_search_path_st
b40826
 
b40826
   /* Make a writable copy.  At the same time expand possible dynamic
b40826
      string tokens.  */
b40826
-  copy = expand_dynamic_string_token (l, rpath);
b40826
+  copy = expand_dynamic_string_token (l, rpath, 1);
b40826
   if (copy == NULL)
b40826
     {
b40826
       errstring = N_("cannot create RUNPATH/RPATH copy");
b40826
       goto signal_error;
b40826
     }
b40826
 
b40826
+  /* Ignore empty rpaths.  */
b40826
+  if (*copy == 0)
b40826
+    {
b40826
+      free (copy);
b40826
+      sps->dirs = (char *) -1;
b40826
+      return false;
b40826
+    }
b40826
+
b40826
   /* Count the number of necessary elements in the result array.  */
b40826
   nelems = 0;
b40826
   for (cp = copy; *cp != '\0'; ++cp)
b40826
@@ -2176,7 +2186,7 @@ _dl_map_object (struct link_map *loader,
b40826
     {
b40826
       /* The path may contain dynamic string tokens.  */
b40826
       realname = (loader
b40826
-		  ? expand_dynamic_string_token (loader, name)
b40826
+		  ? expand_dynamic_string_token (loader, name, 0)
b40826
 		  : local_strdup (name));
b40826
       if (realname == NULL)
b40826
 	fd = -1;