Blame SOURCES/glibc-rh645672.patch

b9ba6d
2010-10-22  Andreas Schwab  <schwab@redhat.com>
b9ba6d
b9ba6d
	* include/dlfcn.h (__RTLD_SECURE): Define.
b9ba6d
	* elf/dl-load.c (_dl_map_object): Remove preloaded parameter.  Use
b9ba6d
	mode & __RTLD_SECURE instead.
b9ba6d
	(open_path): Remove preloaded parameter to secure.
b9ba6d
	* sysdeps/generic/ldsodefs.h (_dl_map_object): Adjust declaration.
b9ba6d
	* elf/dl-open.c (dl_open_worker): Adjust call to _dl_map_object.
b9ba6d
	* elf/dl-deps.c (openaux): Likewise.
b9ba6d
	* elf/rtld.c (struct map_args): Remove is_preloaded.
b9ba6d
	(map_doit): Don't use it.
b9ba6d
	(dl_main): Likewise.
b9ba6d
	(do_preload): Use __RTLD_SECURE instead of is_preloaded.
b9ba6d
	(dlmopen_doit): Add __RTLD_SECURE to mode bits.
b9ba6d
b9ba6d
Index: glibc-2.12-2-gc4ccff1/elf/dl-deps.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-deps.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/elf/dl-deps.c
b9ba6d
@@ -62,7 +62,7 @@ openaux (void *a)
b9ba6d
 {
b9ba6d
   struct openaux_args *args = (struct openaux_args *) a;
b9ba6d
 
b9ba6d
-  args->aux = _dl_map_object (args->map, args->name, 0,
b9ba6d
+  args->aux = _dl_map_object (args->map, args->name,
b9ba6d
 			      (args->map->l_type == lt_executable
b9ba6d
 			       ? lt_library : args->map->l_type),
b9ba6d
 			      args->trace_mode, args->open_mode,
b9ba6d
Index: glibc-2.12-2-gc4ccff1/elf/dl-load.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-load.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/elf/dl-load.c
b9ba6d
@@ -1811,7 +1811,7 @@ open_verify (const char *name, struct fi
b9ba6d
    if MAY_FREE_DIRS is true.  */
b9ba6d
 
b9ba6d
 static int
b9ba6d
-open_path (const char *name, size_t namelen, int preloaded,
b9ba6d
+open_path (const char *name, size_t namelen, int secure,
b9ba6d
 	   struct r_search_path_struct *sps, char **realname,
b9ba6d
 	   struct filebuf *fbp, struct link_map *loader, int whatcode,
b9ba6d
 	   bool *found_other_class)
b9ba6d
@@ -1893,7 +1893,7 @@ open_path (const char *name, size_t name
b9ba6d
 	  /* Remember whether we found any existing directory.  */
b9ba6d
 	  here_any |= this_dir->status[cnt] != nonexisting;
b9ba6d
 
b9ba6d
-	  if (fd != -1 && __builtin_expect (preloaded, 0)
b9ba6d
+	  if (fd != -1 && __builtin_expect (secure, 0)
b9ba6d
 	      && INTUSE(__libc_enable_secure))
b9ba6d
 	    {
b9ba6d
 	      /* This is an extra security effort to make sure nobody can
b9ba6d
@@ -1962,7 +1962,7 @@ open_path (const char *name, size_t name
b9ba6d
 
b9ba6d
 struct link_map *
b9ba6d
 internal_function
b9ba6d
-_dl_map_object (struct link_map *loader, const char *name, int preloaded,
b9ba6d
+_dl_map_object (struct link_map *loader, const char *name,
b9ba6d
 		int type, int trace_mode, int mode, Lmid_t nsid)
b9ba6d
 {
b9ba6d
   int fd;
b9ba6d
@@ -2066,7 +2066,8 @@ _dl_map_object (struct link_map *loader,
b9ba6d
 	  for (l = loader; l; l = l->l_loader)
b9ba6d
 	    if (cache_rpath (l, &l->l_rpath_dirs, DT_RPATH, "RPATH"))
b9ba6d
 	      {
b9ba6d
-		fd = open_path (name, namelen, preloaded, &l->l_rpath_dirs,
b9ba6d
+		fd = open_path (name, namelen, mode & __RTLD_SECURE,
b9ba6d
+				&l->l_rpath_dirs,
b9ba6d
 				&realname, &fb, loader, LA_SER_RUNPATH,
b9ba6d
 				&found_other_class);
b9ba6d
 		if (fd != -1)
b9ba6d
@@ -2081,14 +2082,15 @@ _dl_map_object (struct link_map *loader,
b9ba6d
 	      && main_map != NULL && main_map->l_type != lt_loaded
b9ba6d
 	      && cache_rpath (main_map, &main_map->l_rpath_dirs, DT_RPATH,
b9ba6d
 			      "RPATH"))
b9ba6d
-	    fd = open_path (name, namelen, preloaded, &main_map->l_rpath_dirs,
b9ba6d
+	    fd = open_path (name, namelen, mode & __RTLD_SECURE,
b9ba6d
+			    &main_map->l_rpath_dirs,
b9ba6d
 			    &realname, &fb, loader ?: main_map, LA_SER_RUNPATH,
b9ba6d
 			    &found_other_class);
b9ba6d
 	}
b9ba6d
 
b9ba6d
       /* Try the LD_LIBRARY_PATH environment variable.  */
b9ba6d
       if (fd == -1 && env_path_list.dirs != (void *) -1)
b9ba6d
-	fd = open_path (name, namelen, preloaded, &env_path_list,
b9ba6d
+	fd = open_path (name, namelen, mode & __RTLD_SECURE, &env_path_list,
b9ba6d
 			&realname, &fb,
b9ba6d
 			loader ?: GL(dl_ns)[LM_ID_BASE]._ns_loaded,
b9ba6d
 			LA_SER_LIBPATH, &found_other_class);
b9ba6d
@@ -2097,12 +2099,12 @@ _dl_map_object (struct link_map *loader,
b9ba6d
       if (fd == -1 && loader != NULL
b9ba6d
 	  && cache_rpath (loader, &loader->l_runpath_dirs,
b9ba6d
 			  DT_RUNPATH, "RUNPATH"))
b9ba6d
-	fd = open_path (name, namelen, preloaded,
b9ba6d
+	fd = open_path (name, namelen, mode & __RTLD_SECURE,
b9ba6d
 			&loader->l_runpath_dirs, &realname, &fb, loader,
b9ba6d
 			LA_SER_RUNPATH, &found_other_class);
b9ba6d
 
b9ba6d
       if (fd == -1
b9ba6d
-	  && (__builtin_expect (! preloaded, 1)
b9ba6d
+	  && (__builtin_expect (! (mode & __RTLD_SECURE), 1)
b9ba6d
 	      || ! INTUSE(__libc_enable_secure)))
b9ba6d
 	{
b9ba6d
 	  /* Check the list of libraries in the file /etc/ld.so.cache,
b9ba6d
@@ -2168,7 +2170,7 @@ _dl_map_object (struct link_map *loader,
b9ba6d
 	  && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL
b9ba6d
 	      || __builtin_expect (!(l->l_flags_1 & DF_1_NODEFLIB), 1))
b9ba6d
 	  && rtld_search_dirs.dirs != (void *) -1)
b9ba6d
-	fd = open_path (name, namelen, preloaded, &rtld_search_dirs,
b9ba6d
+	fd = open_path (name, namelen, mode & __RTLD_SECURE, &rtld_search_dirs,
b9ba6d
 			&realname, &fb, l, LA_SER_DEFAULT, &found_other_class);
b9ba6d
 
b9ba6d
       /* Add another newline when we are tracing the library loading.  */
b9ba6d
Index: glibc-2.12-2-gc4ccff1/elf/dl-open.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/elf/dl-open.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/elf/dl-open.c
b9ba6d
@@ -252,7 +252,7 @@ dl_open_worker (void *a)
b9ba6d
 
b9ba6d
   /* Load the named object.  */
b9ba6d
   struct link_map *new;
b9ba6d
-  args->map = new = _dl_map_object (call_map, file, 0, lt_loaded, 0,
b9ba6d
+  args->map = new = _dl_map_object (call_map, file, lt_loaded, 0,
b9ba6d
 				    mode | __RTLD_CALLMAP, args->nsid);
b9ba6d
 
b9ba6d
   /* If the pointer returned is NULL this means the RTLD_NOLOAD flag is
b9ba6d
Index: glibc-2.12-2-gc4ccff1/elf/rtld.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/elf/rtld.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/elf/rtld.c
b9ba6d
@@ -589,7 +589,6 @@ struct map_args
b9ba6d
   /* Argument to map_doit.  */
b9ba6d
   char *str;
b9ba6d
   struct link_map *loader;
b9ba6d
-  int is_preloaded;
b9ba6d
   int mode;
b9ba6d
   /* Return value of map_doit.  */
b9ba6d
   struct link_map *map;
b9ba6d
@@ -627,16 +626,17 @@ static void
b9ba6d
 map_doit (void *a)
b9ba6d
 {
b9ba6d
   struct map_args *args = (struct map_args *) a;
b9ba6d
-  args->map = _dl_map_object (args->loader, args->str,
b9ba6d
-			      args->is_preloaded, lt_library, 0, args->mode,
b9ba6d
-			      LM_ID_BASE);
b9ba6d
+  args->map = _dl_map_object (args->loader, args->str, lt_library, 0,
b9ba6d
+			      args->mode, LM_ID_BASE);
b9ba6d
 }
b9ba6d
 
b9ba6d
 static void
b9ba6d
 dlmopen_doit (void *a)
b9ba6d
 {
b9ba6d
   struct dlmopen_args *args = (struct dlmopen_args *) a;
b9ba6d
-  args->map = _dl_open (args->fname, RTLD_LAZY | __RTLD_DLOPEN | __RTLD_AUDIT,
b9ba6d
+  args->map = _dl_open (args->fname,
b9ba6d
+			(RTLD_LAZY | __RTLD_DLOPEN | __RTLD_AUDIT
b9ba6d
+			 | __RTLD_SECURE),
b9ba6d
 			dl_main, LM_ID_NEWLM, _dl_argc, INTUSE(_dl_argv),
b9ba6d
 			__environ);
b9ba6d
 }
b9ba6d
@@ -806,8 +806,7 @@ do_preload (char *fname, struct link_map
b9ba6d
 
b9ba6d
   args.str = fname;
b9ba6d
   args.loader = main_map;
b9ba6d
-  args.is_preloaded = 1;
b9ba6d
-  args.mode = 0;
b9ba6d
+  args.mode = __RTLD_SECURE;
b9ba6d
 
b9ba6d
   unsigned int old_nloaded = GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
b9ba6d
 
b9ba6d
@@ -1054,7 +1053,6 @@ of this helper program; chances are you 
b9ba6d
 
b9ba6d
 	  args.str = rtld_progname;
b9ba6d
 	  args.loader = NULL;
b9ba6d
-	  args.is_preloaded = 0;
b9ba6d
 	  args.mode = __RTLD_OPENEXEC;
b9ba6d
 	  (void) _dl_catch_error (&objname, &err_str, &malloced, map_doit,
b9ba6d
 				  &args);
b9ba6d
@@ -1066,7 +1064,7 @@ of this helper program; chances are you 
b9ba6d
       else
b9ba6d
 	{
b9ba6d
 	  HP_TIMING_NOW (start);
b9ba6d
-	  _dl_map_object (NULL, rtld_progname, 0, lt_library, 0,
b9ba6d
+	  _dl_map_object (NULL, rtld_progname, lt_library, 0,
b9ba6d
 			  __RTLD_OPENEXEC, LM_ID_BASE);
b9ba6d
 	  HP_TIMING_NOW (stop);
b9ba6d
 
b9ba6d
Index: glibc-2.12-2-gc4ccff1/include/dlfcn.h
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/include/dlfcn.h
b9ba6d
+++ glibc-2.12-2-gc4ccff1/include/dlfcn.h
b9ba6d
@@ -9,6 +9,7 @@
b9ba6d
 #define __RTLD_OPENEXEC	0x20000000
b9ba6d
 #define __RTLD_CALLMAP	0x10000000
b9ba6d
 #define __RTLD_AUDIT	0x08000000
b9ba6d
+#define __RTLD_SECURE	0x04000000 /* Apply additional security checks.  */
b9ba6d
 
b9ba6d
 #define __LM_ID_CALLER	-2
b9ba6d
 
b9ba6d
Index: glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/generic/ldsodefs.h
b9ba6d
+++ glibc-2.12-2-gc4ccff1/sysdeps/generic/ldsodefs.h
b9ba6d
@@ -824,11 +824,9 @@ extern void _dl_receive_error (receiver_
b9ba6d
 
b9ba6d
 /* Open the shared object NAME and map in its segments.
b9ba6d
    LOADER's DT_RPATH is used in searching for NAME.
b9ba6d
-   If the object is already opened, returns its existing map.
b9ba6d
-   For preloaded shared objects PRELOADED is set to a non-zero
b9ba6d
-   value to allow additional security checks.  */
b9ba6d
+   If the object is already opened, returns its existing map.  */
b9ba6d
 extern struct link_map *_dl_map_object (struct link_map *loader,
b9ba6d
-					const char *name, int preloaded,
b9ba6d
+					const char *name,
b9ba6d
 					int type, int trace_mode, int mode,
b9ba6d
 					Lmid_t nsid)
b9ba6d
      internal_function attribute_hidden;