public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Make LD_ASSUME_KERNEL working even for static binaries
@ 2002-12-09 10:29 Jakub Jelinek
  2002-12-09 12:50 ` Roland McGrath
  2002-12-10  2:31 ` Roland McGrath
  0 siblings, 2 replies; 5+ messages in thread
From: Jakub Jelinek @ 2002-12-09 10:29 UTC (permalink / raw)
  To: Roland McGrath, Ulrich Drepper; +Cc: Glibc hackers

Hi!

LD_ASSUME_KERNEL doesn't work for static binaries, the following patch makes
it work even for them (so you can influence what libraries it will use
during NSS lookups or ICONV).

2002-12-09  Jakub Jelinek  <jakub@redhat.com>

	* elf/dl-support.c (_dl_non_dynamic_init): Add DL_OSVERSION_INIT if
	defined.
	* sysdeps/unix/sysv/linux/dl-librecon.h (_dl_osversion_init): New
	function.
	(EXTRA_LD_ENVVARS): Use it.
	(DL_OSVERSION_INIT): Define.
	* sysdeps/unix/sysv/linux/i386/dl-librecon.h: Include linux
	dl-librecon.h.
	(EXTRA_LD_ENVVARS): Undef before defining.  Use _dl_osversion_init.

--- libc/elf/dl-support.c.jj	2002-12-06 12:27:23.000000000 +0100
+++ libc/elf/dl-support.c	2002-12-09 16:57:58.000000000 +0100
@@ -214,6 +214,10 @@ _dl_non_dynamic_init (void)
   DL_PLATFORM_INIT;
 #endif
 
+#ifdef DL_OSVERSION_INIT
+  DL_OSVERSION_INIT;
+#endif
+
   /* Now determine the length of the platform string.  */
   if (_dl_platform != NULL)
     _dl_platformlen = strlen (_dl_platform);
--- libc/sysdeps/unix/sysv/linux/i386/dl-librecon.h.jj	2002-01-31 04:39:22.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/i386/dl-librecon.h	2002-12-09 17:15:06.000000000 +0100
@@ -19,7 +19,8 @@
    02111-1307 USA.  */
 
 #ifndef _DL_LIBRECON_H
-#define _DL_LIBRECON_H	1
+
+#include <sysdeps/unix/sysv/linux/dl-librecon.h>
 
 #define DISTINGUISH_LIB_VERSIONS \
   do									      \
@@ -47,27 +48,12 @@
   while (0)
 
 /* Recognizing extra environment variables.  */
+#undef EXTRA_LD_ENVVARS
 #define EXTRA_LD_ENVVARS \
   case 13:								      \
     if (memcmp (envline, "ASSUME_KERNEL", 13) == 0)			      \
       {									      \
-	unsigned long int i, j, osversion = 0;				      \
-	char *p = &envline[14], *q;					      \
-									      \
-	for (i = 0; i < 3; i++, p = q + 1)				      \
-	  {								      \
-	    j = __strtoul_internal (p, &q, 0, 0);			      \
-	    if (j >= 255 || p == q || (i < 2 && *q && *q != '.'))	      \
-	      {								      \
-		osversion = 0;						      \
-		break;							      \
-	      }								      \
-	    osversion |= j << (16 - 8 * i);				      \
-	    if (!*q)							      \
-	      break;							      \
-	  }								      \
-	if (osversion)							      \
-	  GL(dl_osversion) = osversion;					      \
+	_dl_osversion_init (&envline[14]);				      \
 	break;								      \
       }									      \
 									      \
--- libc/sysdeps/unix/sysv/linux/dl-librecon.h.jj	2002-01-31 04:39:22.000000000 +0100
+++ libc/sysdeps/unix/sysv/linux/dl-librecon.h	2002-12-09 17:20:45.000000000 +0100
@@ -1,5 +1,5 @@
 /* Optional code to distinguish library flavours.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2001.
 
@@ -21,29 +21,42 @@
 #ifndef _DL_LIBRECON_H
 #define _DL_LIBRECON_H	1
 
+static inline void __attribute__ ((unused, always_inline))
+_dl_osversion_init (char *assume_kernel)
+{
+  unsigned long int i, j, osversion = 0;
+  char *p = assume_kernel, *q;
+
+  for (i = 0; i < 3; i++, p = q + 1)
+    {
+      j = __strtoul_internal (p, &q, 0, 0);
+      if (j >= 255 || p == q || (i < 2 && *q && *q != '.'))
+	{
+	  osversion = 0;
+	  break;
+	}
+      osversion |= j << (16 - 8 * i);
+      if (!*q)
+	break;
+    }
+  if (osversion)
+    GL(dl_osversion) = osversion;
+}
+
 /* Recognizing extra environment variables.  */
 #define EXTRA_LD_ENVVARS \
   case 13:								      \
     if (memcmp (envline, "ASSUME_KERNEL", 13) == 0)			      \
       {									      \
-	unsigned long int i, j, osversion = 0;				      \
-	char *p = &envline[14], *q;					      \
-									      \
-	for (i = 0; i < 3; i++, p = q + 1)				      \
-	  {								      \
-	    j = __strtoul_internal (p, &q, 0, 0);			      \
-	    if (j >= 255 || p == q || (i < 2 && *q && *q != '.'))	      \
-	      {								      \
-		osversion = 0;						      \
-		break;							      \
-	      }								      \
-	    osversion |= j << (16 - 8 * i);				      \
-	    if (!*q)							      \
-	      break;							      \
-	  }								      \
-	if (osversion)							      \
-	  GL(dl_osversion) = osversion;					      \
+	_dl_osversion_init (&envline[14]);				      \
 	break;								      \
       }
 
+#define DL_OSVERSION_INIT \
+  do {									      \
+    char *assume_kernel = getenv ("LD_ASSUME_KERNEL");			      \
+    if (assume_kernel)							      \
+      _dl_osversion_init (assume_kernel);				      \
+  } while (0)
+
 #endif /* dl-librecon.h */

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Make LD_ASSUME_KERNEL working even for static binaries
  2002-12-09 10:29 [PATCH] Make LD_ASSUME_KERNEL working even for static binaries Jakub Jelinek
@ 2002-12-09 12:50 ` Roland McGrath
       [not found]   ` <20021209162539.J27455@devserv.devel.redhat.com>
  2002-12-10  2:31 ` Roland McGrath
  1 sibling, 1 reply; 5+ messages in thread
From: Roland McGrath @ 2002-12-09 12:50 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers

> LD_ASSUME_KERNEL doesn't work for static binaries, the following patch makes
> it work even for them (so you can influence what libraries it will use
> during NSS lookups or ICONV).

Ok, we need that.  I think it needs to be __secure_getenv, though.
I also wonder why this stuff is in linux/i386 instead of linux/.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Make LD_ASSUME_KERNEL working even for static binaries
       [not found]   ` <20021209162539.J27455@devserv.devel.redhat.com>
@ 2002-12-09 13:43     ` Ulrich Drepper
  2002-12-09 13:45       ` Roland McGrath
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Drepper @ 2002-12-09 13:43 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Roland McGrath, Glibc hackers

Jakub Jelinek wrote:

> I'm not sure either way. LD_ASSUME_KERNEL in ld.so ATM is not limited to
> non-suid.

I don't think it is necessary to use __secure_getenv.  It doesn't let
the user directly make decisions about what DSO is used.  And if the
DSOs with support are vulnerable to something the new DSOs are not there
are other ways to get to this.

-- 
--------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Make LD_ASSUME_KERNEL working even for static binaries
  2002-12-09 13:43     ` Ulrich Drepper
@ 2002-12-09 13:45       ` Roland McGrath
  0 siblings, 0 replies; 5+ messages in thread
From: Roland McGrath @ 2002-12-09 13:45 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Jakub Jelinek, Glibc hackers

> I don't think it is necessary to use __secure_getenv.  It doesn't let
> the user directly make decisions about what DSO is used.  And if the
> DSOs with support are vulnerable to something the new DSOs are not there
> are other ways to get to this.

Ok, that makes sense.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Make LD_ASSUME_KERNEL working even for static binaries
  2002-12-09 10:29 [PATCH] Make LD_ASSUME_KERNEL working even for static binaries Jakub Jelinek
  2002-12-09 12:50 ` Roland McGrath
@ 2002-12-10  2:31 ` Roland McGrath
  1 sibling, 0 replies; 5+ messages in thread
From: Roland McGrath @ 2002-12-10  2:31 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Glibc hackers

Thanks, I've put this in and cleaned up the duplication of the macro contents.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-12-10 10:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-09 10:29 [PATCH] Make LD_ASSUME_KERNEL working even for static binaries Jakub Jelinek
2002-12-09 12:50 ` Roland McGrath
     [not found]   ` <20021209162539.J27455@devserv.devel.redhat.com>
2002-12-09 13:43     ` Ulrich Drepper
2002-12-09 13:45       ` Roland McGrath
2002-12-10  2:31 ` Roland McGrath

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).