From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20997 invoked by alias); 29 Oct 2006 11:32:52 -0000 Received: (qmail 20979 invoked by uid 22791); 29 Oct 2006 11:32:52 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 29 Oct 2006 11:32:45 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k9TBW3gF014080; Sun, 29 Oct 2006 12:32:03 +0100 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k9TBW3k1014076; Sun, 29 Oct 2006 12:32:03 +0100 Date: Sun, 29 Oct 2006 11:32:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix *SINGLE_THREAD_P in ld.so Message-ID: <20061029113202.GS5868@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-10/txt/msg00021.txt.bz2 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 * 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