public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix *SINGLE_THREAD_P in ld.so
@ 2006-10-29 11:32 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2006-10-29 11:32 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

My http://sources.redhat.com/ml/libc-hacker/2006-10/msg00017.html
patch broke all suid/sgid programs, as ld.so there calls its own
fcntl before %gs resp. %fs is set up.  There are many .c files that
use SINGLE_THREAD_P and in the vast majority it is used to detect whether
to use LIBC_CANCEL_{ASYNC,RESET} or not.  In ld.so those are nops and
thus it really doesn't matter which one to use, but would be better
to avoid duplication if one of the possibilities was optimized out (with
inline asm that is not something GCC will find out on its own).  And,
more importantly, THREAD_SELF shouldn't be accessed, especially not
before it could be set up (as in the fcntl case).

So, I think it is better to define a new macro and use it in the 7 places
in ld.so that need it, rather than
#ifdef NO_CANCELLATION
# undef SINGLE_THREAD_P
# define SINGLE_THREAD_P (1)
#endif
in fcntl.c and dozens of other sources that might be compiled into ld.so.

2006-10-29  Jakub Jelinek  <jakub@redhat.com>

	* elf/dl-sym.c (do_sym): Use RTLD_SINGLE_THREAD_P.
	* elf/dl-runtime.c (_dl_fixup, _dl_profile_fixup): Likewise.
	* elf/dl-close.c (_dl_close_worker): Likewise.
	* elf/dl-open.c (_dl_open_worker): Likewise.
	* sysdeps/generic/sysdep-cancel.h (RTLD_SINGLE_THREAD_P): Define.
nptl/
	* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (RTLD_SINGLE_THREAD_P):
	Define.
	(SINGLE_THREAD_P): Define to 1 if IS_IN_rtld.
	* sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h: Likewise.
	* sysdeps/unix/sysv/linux/sh/sysdep-cancel.h: Likewise.

--- libc/elf/dl-sym.c.jj	2006-10-26 14:29:14.000000000 +0200
+++ libc/elf/dl-sym.c	2006-10-29 11:55:31.000000000 +0100
@@ -115,7 +115,7 @@ do_sym (void *handle, const char *name, 
 	 the initial binary.  And then the more complex part
 	 where the object is dynamically loaded and the scope
 	 array can change.  */
-      if (match->l_type != lt_loaded || SINGLE_THREAD_P)
+      if (match->l_type != lt_loaded || RTLD_SINGLE_THREAD_P)
 	result = GLRO(dl_lookup_symbol_x) (name, match, &ref,
 					   match->l_scope, vers, 0,
 					   flags | DL_LOOKUP_ADD_DEPENDENCY,
--- libc/elf/dl-runtime.c.jj	2006-10-26 14:24:18.000000000 +0200
+++ libc/elf/dl-runtime.c	2006-10-29 11:55:31.000000000 +0100
@@ -93,14 +93,14 @@ _dl_fixup (
 	    version = NULL;
 	}
 
-      if (l->l_type == lt_loaded && !SINGLE_THREAD_P)
+      if (l->l_type == lt_loaded && !RTLD_SINGLE_THREAD_P)
 	__rtld_mrlock_lock (l->l_scope_lock);
 
       result = _dl_lookup_symbol_x (strtab + sym->st_name, l, &sym,
 				    l->l_scope, version, ELF_RTYPE_CLASS_PLT,
 				    DL_LOOKUP_ADD_DEPENDENCY, NULL);
 
-      if (l->l_type == lt_loaded && !SINGLE_THREAD_P)
+      if (l->l_type == lt_loaded && !RTLD_SINGLE_THREAD_P)
 	__rtld_mrlock_unlock (l->l_scope_lock);
 
       /* Currently result contains the base load address (or link map)
@@ -181,7 +181,7 @@ _dl_profile_fixup (
 		version = NULL;
 	    }
 
-	  if (l->l_type == lt_loaded && !SINGLE_THREAD_P)
+	  if (l->l_type == lt_loaded && !RTLD_SINGLE_THREAD_P)
 	    __rtld_mrlock_lock (l->l_scope_lock);
 
 	  result = _dl_lookup_symbol_x (strtab + refsym->st_name, l, &defsym,
@@ -189,7 +189,7 @@ _dl_profile_fixup (
 					ELF_RTYPE_CLASS_PLT,
 					DL_LOOKUP_ADD_DEPENDENCY, NULL);
 
-	  if (l->l_type == lt_loaded && !SINGLE_THREAD_P)
+	  if (l->l_type == lt_loaded && !RTLD_SINGLE_THREAD_P)
 	    __rtld_mrlock_unlock (l->l_scope_lock);
 
 	  /* Currently result contains the base load address (or link map)
--- libc/elf/dl-close.c.jj	2006-10-26 15:17:59.000000000 +0200
+++ libc/elf/dl-close.c	2006-10-29 11:55:31.000000000 +0100
@@ -417,7 +417,7 @@ _dl_close (void *_map)
 
 	      struct r_scope_elem **old = imap->l_scope;
 
-	      if (SINGLE_THREAD_P)
+	      if (RTLD_SINGLE_THREAD_P)
 		imap->l_scope = newp;
 	      else
 		{
--- libc/elf/dl-open.c.jj	2006-10-26 14:40:00.000000000 +0200
+++ libc/elf/dl-open.c	2006-10-29 11:55:31.000000000 +0100
@@ -419,7 +419,7 @@ dl_open_worker (void *a)
 	      memcpy (newp, imap->l_scope, cnt * sizeof (imap->l_scope[0]));
 	      struct r_scope_elem **old = imap->l_scope;
 
-	      if (SINGLE_THREAD_P)
+	      if (RTLD_SINGLE_THREAD_P)
 		imap->l_scope = newp;
 	      else
 		{
--- libc/nptl/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/alpha/sysdep-cancel.h	2006-10-29 12:14:41.000000000 +0100
@@ -163,13 +163,13 @@ extern int __local_multiple_threads attr
 
 #else
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h	2006-10-29 12:14:50.000000000 +0100
@@ -216,13 +216,13 @@ __GC_##name:								      \
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h	2006-10-29 12:14:59.000000000 +0100
@@ -143,13 +143,13 @@
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-		    		   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h	2006-10-29 12:15:06.000000000 +0100
@@ -109,13 +109,13 @@ L(pseudo_end):
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h	2006-10-29 12:15:13.000000000 +0100
@@ -122,13 +122,13 @@ extern int __local_multiple_threads attr
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h	2006-10-29 12:15:19.000000000 +0100
@@ -113,13 +113,13 @@
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h	2006-10-29 12:15:28.000000000 +0100
@@ -124,13 +124,13 @@
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h	2006-10-29 12:15:35.000000000 +0100
@@ -132,13 +132,13 @@ extern int __local_multiple_threads attr
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h	2006-10-29 12:15:42.000000000 +0100
@@ -100,13 +100,13 @@ __##syscall_name##_nocancel:			\
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h	2006-10-29 12:15:50.000000000 +0100
@@ -98,13 +98,13 @@ __##syscall_name##_nocancel:			\
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h.jj	2006-10-26 11:38:16.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h	2006-10-29 12:15:57.000000000 +0100
@@ -157,13 +157,13 @@
 
 #elif !defined __ASSEMBLER__
 
-# ifdef IS_IN_rtld
-#  define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
-# else
-#  define SINGLE_THREAD_P (1)
-# endif
+# define SINGLE_THREAD_P (1)
 # define NO_CANCELLATION 1
 
 #endif
+
+#ifndef __ASSEMBLER__
+# define RTLD_SINGLE_THREAD_P \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+				   header.multiple_threads) == 0, 1)
+#endif
--- libc/sysdeps/generic/sysdep-cancel.h.jj	2003-01-07 01:12:06.000000000 +0100
+++ libc/sysdeps/generic/sysdep-cancel.h	2006-10-29 12:16:39.000000000 +0100
@@ -2,6 +2,7 @@
 
 /* No multi-thread handling enabled.  */
 #define SINGLE_THREAD_P (1)
+#define RTLD_SINGLE_THREAD_P (1)
 #define LIBC_CANCEL_ASYNC()	0 /* Just a dummy value.  */
 #define LIBC_CANCEL_RESET(val)	((void)(val)) /* Nothing, but evaluate it.  */
 #define LIBC_CANCEL_HANDLED()	/* Nothing.  */

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-10-29 11:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-29 11:32 [PATCH] Fix *SINGLE_THREAD_P in ld.so Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).