1 From: http://sisyphus.ru/srpm/Sisyphus/glibc/patches/10
3 I added MUDFLAP_OPTIONS to sysdeps/generic/unsecvars.h.
5 diff -Naur glibc-2.8-20080929.orig/argp/argp-help.c glibc-2.8-20080929/argp/argp-help.c
6 --- glibc-2.8-20080929.orig/argp/argp-help.c 2007-03-15 20:08:18.000000000 +0000
7 +++ glibc-2.8-20080929/argp/argp-help.c 2008-10-15 00:30:49.000000000 +0000
10 fill_in_uparams (const struct argp_state *state)
12 - const char *var = getenv ("ARGP_HELP_FMT");
13 + const char *var = __secure_getenv ("ARGP_HELP_FMT");
15 #define SKIPWS(p) do { while (isspace (*p)) p++; } while (0);
17 diff -Naur glibc-2.8-20080929.orig/catgets/catgets.c glibc-2.8-20080929/catgets/catgets.c
18 --- glibc-2.8-20080929.orig/catgets/catgets.c 2002-05-15 03:46:42.000000000 +0000
19 +++ glibc-2.8-20080929/catgets/catgets.c 2008-10-15 00:30:49.000000000 +0000
21 || (__libc_enable_secure && strchr (env_var, '/') != NULL))
24 - nlspath = getenv ("NLSPATH");
25 + nlspath = __secure_getenv ("NLSPATH");
26 if (nlspath != NULL && *nlspath != '\0')
28 /* Append the system dependent directory. */
29 diff -Naur glibc-2.8-20080929.orig/debug/pcprofile.c glibc-2.8-20080929/debug/pcprofile.c
30 --- glibc-2.8-20080929.orig/debug/pcprofile.c 2001-07-06 04:54:45.000000000 +0000
31 +++ glibc-2.8-20080929/debug/pcprofile.c 2008-10-15 00:30:49.000000000 +0000
34 /* See whether the environment variable `PCPROFILE_OUTPUT' is defined.
35 If yes, it should name a FIFO. We open it and mark ourself as active. */
36 - const char *outfile = getenv ("PCPROFILE_OUTPUT");
37 + const char *outfile = __secure_getenv ("PCPROFILE_OUTPUT");
39 if (outfile != NULL && *outfile != '\0')
41 diff -Naur glibc-2.8-20080929.orig/debug/segfault.c glibc-2.8-20080929/debug/segfault.c
42 --- glibc-2.8-20080929.orig/debug/segfault.c 2007-08-22 06:52:12.000000000 +0000
43 +++ glibc-2.8-20080929/debug/segfault.c 2008-10-15 00:30:49.000000000 +0000
45 install_handler (void)
48 - const char *sigs = getenv ("SEGFAULT_SIGNALS");
49 + const char *sigs = __secure_getenv ("SEGFAULT_SIGNALS");
52 sa.sa_handler = (void *) catch_segfault;
54 sa.sa_flags = SA_RESTART;
56 /* Maybe we are expected to use an alternative stack. */
57 - if (getenv ("SEGFAULT_USE_ALTSTACK") != 0)
58 + if (__secure_getenv ("SEGFAULT_USE_ALTSTACK") != 0)
60 void *stack_mem = malloc (2 * SIGSTKSZ);
61 struct sigaltstack ss;
65 /* Preserve the output file name if there is any given. */
66 - name = getenv ("SEGFAULT_OUTPUT_NAME");
67 + name = __secure_getenv ("SEGFAULT_OUTPUT_NAME");
68 if (name != NULL && name[0] != '\0')
70 int ret = access (name, R_OK | W_OK);
71 diff -Naur glibc-2.8-20080929.orig/elf/Versions glibc-2.8-20080929/elf/Versions
72 --- glibc-2.8-20080929.orig/elf/Versions 2008-03-08 05:42:26.000000000 +0000
73 +++ glibc-2.8-20080929/elf/Versions 2008-10-15 00:30:49.000000000 +0000
75 _dl_make_stack_executable;
76 # Only here for gdb while a better method is developed.
78 + # For sanitizing environment.
79 + __libc_security_mask;
83 diff -Naur glibc-2.8-20080929.orig/elf/dl-support.c glibc-2.8-20080929/elf/dl-support.c
84 --- glibc-2.8-20080929.orig/elf/dl-support.c 2007-06-20 03:18:16.000000000 +0000
85 +++ glibc-2.8-20080929/elf/dl-support.c 2008-10-15 00:30:49.000000000 +0000
88 _dl_aux_init (ElfW(auxv_t) *av)
90 + int security_mask = 0;
98 + if (seen & 1) break;
99 uid ^= av->a_un.a_val;
103 + if (seen & 2) break;
104 uid ^= av->a_un.a_val;
108 + if (seen & 4) break;
109 gid ^= av->a_un.a_val;
113 + if (seen & 8) break;
114 gid ^= av->a_un.a_val;
119 - __libc_enable_secure = av->a_un.a_val;
120 - __libc_enable_secure_decided = 1;
121 + security_mask |= av->a_un.a_val != 0;
123 # ifdef DL_PLATFORM_AUXV
129 - __libc_enable_secure = uid != 0 || gid != 0;
130 + security_mask |= ((uid != 0) << 1) | ((gid != 0) << 2);
131 + __libc_security_mask = security_mask;
132 + __libc_enable_secure = __libc_security_mask != 0;
133 __libc_enable_secure_decided = 1;
136 @@ -239,19 +244,19 @@
138 _dl_pagesize = __getpagesize ();
140 - _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
141 + _dl_verbose = *(__secure_getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
143 /* Initialize the data structures for the search paths for shared
145 - _dl_init_paths (getenv ("LD_LIBRARY_PATH"));
146 + _dl_init_paths (__secure_getenv ("LD_LIBRARY_PATH"));
148 - _dl_lazy = *(getenv ("LD_BIND_NOW") ?: "") == '\0';
149 + _dl_lazy = *(__secure_getenv ("LD_BIND_NOW") ?: "") == '\0';
151 - _dl_bind_not = *(getenv ("LD_BIND_NOT") ?: "") != '\0';
152 + _dl_bind_not = *(__secure_getenv ("LD_BIND_NOT") ?: "") != '\0';
154 - _dl_dynamic_weak = *(getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0';
155 + _dl_dynamic_weak = *(__secure_getenv ("LD_DYNAMIC_WEAK") ?: "") == '\0';
157 - _dl_profile_output = getenv ("LD_PROFILE_OUTPUT");
158 + _dl_profile_output = __secure_getenv ("LD_PROFILE_OUTPUT");
159 if (_dl_profile_output == NULL || _dl_profile_output[0] == '\0')
161 = &"/var/tmp\0/var/profile"[__libc_enable_secure ? 9 : 0];
163 EXTRA_UNSECURE_ENVVARS
166 + static const char restricted_envvars[] =
167 + RESTRICTED_ENVVARS;
168 const char *cp = unsecure_envvars;
170 while (cp < unsecure_envvars + sizeof (unsecure_envvars))
172 cp = (const char *) __rawmemchr (cp, '\0') + 1;
175 - if (__access ("/etc/suid-debug", F_OK) != 0)
176 - __unsetenv ("MALLOC_CHECK_");
177 + if (__libc_security_mask & 2)
179 + static const char unsecure_uid_envvars[] =
180 + UNSECURE_UID_ENVVARS;
182 + cp = unsecure_uid_envvars;
183 + while (cp < unsecure_uid_envvars + sizeof (unsecure_uid_envvars))
186 + cp = (const char *) __rawmemchr (cp, '\0') + 1;
190 + /* This loop is buggy: it will only check the first occurrence of each
191 + variable (but will correctly remove all in case of a match). This
192 + may be a problem if the list is later re-ordered or accessed by an
193 + application with something other than the glibc getenv(). */
194 + cp = restricted_envvars;
195 + while (cp < restricted_envvars + sizeof (restricted_envvars))
197 + const char *value = getenv (cp);
198 + if (value && (value[0] == '.' || strchr(value, '/')))
200 + cp = (const char *) __rawmemchr (cp, '\0') + 1;
204 #ifdef DL_PLATFORM_INIT
205 diff -Naur glibc-2.8-20080929.orig/elf/dl-sysdep.c glibc-2.8-20080929/elf/dl-sysdep.c
206 --- glibc-2.8-20080929.orig/elf/dl-sysdep.c 2008-03-08 07:28:36.000000000 +0000
207 +++ glibc-2.8-20080929/elf/dl-sysdep.c 2008-10-15 00:30:49.000000000 +0000
209 #ifdef NEED_DL_BASE_ADDR
210 ElfW(Addr) _dl_base_addr;
212 -int __libc_enable_secure attribute_relro = 0;
213 +int __libc_enable_secure attribute_relro = 1;
214 INTVARDEF(__libc_enable_secure)
215 +int __libc_security_mask attribute_relro = 0x7fffffff;
216 +INTVARDEF(__libc_security_mask)
217 int __libc_multiple_libcs = 0; /* Defining this here avoids the inclusion
219 /* This variable contains the lowest stack address ever used. */
221 # define DL_STACK_END(cookie) ((void *) (cookie))
229 _dl_sysdep_start (void **start_argptr,
230 void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
232 ElfW(Word) phnum = 0;
233 ElfW(Addr) user_entry;
235 -#ifdef HAVE_AUX_SECURE
236 + int security_mask = 0;
238 # define set_seen(tag) (tag) /* Evaluate for the side effects. */
239 -# define set_seen_secure() ((void) 0)
243 unsigned int seen = 0;
244 -# define set_seen_secure() (seen = -1)
246 # define set_seen(tag) (tag) /* Evaluate for the side effects. */
248 # define M(type) (1 << (type))
249 # define set_seen(tag) seen |= M ((tag)->a_type)
250 +# define is_seen(tag) seen & M ((tag)->a_type)
253 #ifdef NEED_DL_SYSINFO
254 @@ -135,21 +141,18 @@
255 _dl_base_addr = av->a_un.a_val;
258 -#ifndef HAVE_AUX_SECURE
261 + if (is_seen (av)) break;
262 uid ^= av->a_un.a_val;
266 + if (is_seen (av)) break;
267 gid ^= av->a_un.a_val;
271 -#ifndef HAVE_AUX_SECURE
274 - INTUSE(__libc_enable_secure) = av->a_un.a_val;
275 + security_mask |= av->a_un.a_val != 0;
278 GLRO(dl_platform) = (void *) av->a_un.a_val;
283 -#ifndef HAVE_AUX_SECURE
286 /* Fill in the values we have not gotten from the kernel through the
288 @@ -191,12 +192,12 @@
290 SEE (EGID, gid, egid);
293 - /* If one of the two pairs of IDs does not match this is a setuid
295 - INTUSE(__libc_enable_secure) = uid | gid;
298 + /* If one of the two pairs of IDs does not match
299 + this is a setuid or setgid run. */
300 + security_mask |= ((uid != 0) << 1) | ((gid != 0) << 2);
301 + INTUSE(__libc_security_mask) = security_mask;
302 + INTUSE(__libc_enable_secure) = security_mask != 0;
304 #ifndef HAVE_AUX_PAGESIZE
305 if (GLRO(dl_pagesize) == 0)
306 diff -Naur glibc-2.8-20080929.orig/elf/enbl-secure.c glibc-2.8-20080929/elf/enbl-secure.c
307 --- glibc-2.8-20080929.orig/elf/enbl-secure.c 2005-12-14 08:46:07.000000000 +0000
308 +++ glibc-2.8-20080929/elf/enbl-secure.c 2008-10-15 00:30:49.000000000 +0000
310 int __libc_enable_secure_decided;
311 /* Safest assumption, if somehow the initializer isn't run. */
312 int __libc_enable_secure = 1;
313 +int __libc_security_mask = 0x7fffffff;
316 __libc_init_secure (void)
318 if (__libc_enable_secure_decided == 0)
319 - __libc_enable_secure = (__geteuid () != __getuid ()
320 - || __getegid () != __getgid ());
322 + __libc_security_mask =
323 + ((__geteuid () != __getuid ()) << 1) |
324 + ((__getegid () != __getgid ()) << 2);
325 + __libc_enable_secure = __libc_security_mask != 0;
326 + __libc_security_mask |= __libc_enable_secure;
329 diff -Naur glibc-2.8-20080929.orig/elf/rtld.c glibc-2.8-20080929/elf/rtld.c
330 --- glibc-2.8-20080929.orig/elf/rtld.c 2008-03-08 07:29:40.000000000 +0000
331 +++ glibc-2.8-20080929/elf/rtld.c 2008-10-15 00:30:49.000000000 +0000
332 @@ -2500,6 +2500,7 @@
333 GLRO(dl_profile_output)
334 = &"/var/tmp\0/var/profile"[INTUSE(__libc_enable_secure) ? 9 : 0];
336 + if (__builtin_expect (!INTUSE(__libc_enable_secure), 1))
337 while ((envline = _dl_next_ld_env_entry (&runp)) != NULL)
340 @@ -2566,8 +2567,7 @@
342 /* Test whether we want to see the content of the auxiliary
343 array passed up from the kernel. */
344 - if (!INTUSE(__libc_enable_secure)
345 - && memcmp (envline, "SHOW_AUXV", 9) == 0)
346 + if (memcmp (envline, "SHOW_AUXV", 9) == 0)
350 @@ -2580,8 +2580,7 @@
353 /* Path where the binary is found. */
354 - if (!INTUSE(__libc_enable_secure)
355 - && memcmp (envline, "ORIGIN_PATH", 11) == 0)
356 + if (memcmp (envline, "ORIGIN_PATH", 11) == 0)
357 GLRO(dl_origin_path) = &envline[12];
360 @@ -2600,8 +2599,7 @@
364 - if (!INTUSE(__libc_enable_secure)
365 - && memcmp (envline, "DYNAMIC_WEAK", 12) == 0)
366 + if (memcmp (envline, "DYNAMIC_WEAK", 12) == 0)
367 GLRO(dl_dynamic_weak) = 1;
370 @@ -2611,8 +2609,7 @@
371 #ifdef EXTRA_LD_ENVVARS_13
374 - if (!INTUSE(__libc_enable_secure)
375 - && memcmp (envline, "USE_LOAD_BIAS", 13) == 0)
376 + if (memcmp (envline, "USE_LOAD_BIAS", 13) == 0)
378 GLRO(dl_use_load_bias) = envline[14] == '1' ? -1 : 0;
380 @@ -2624,8 +2621,7 @@
383 /* Where to place the profiling data file. */
384 - if (!INTUSE(__libc_enable_secure)
385 - && memcmp (envline, "PROFILE_OUTPUT", 14) == 0
386 + if (memcmp (envline, "PROFILE_OUTPUT", 14) == 0
387 && envline[15] != '\0')
388 GLRO(dl_profile_output) = &envline[15];
390 @@ -2669,16 +2665,39 @@
391 EXTRA_UNSECURE_ENVVARS
394 + static const char restricted_envvars[] =
395 + RESTRICTED_ENVVARS;
398 - nextp = unsecure_envvars;
400 + for (nextp = unsecure_envvars; *nextp != '\0';
401 + nextp = (char *) rawmemchr (nextp, '\0') + 1)
404 - /* We could use rawmemchr but this need not be fast. */
405 - nextp = (char *) (strchr) (nextp, '\0') + 1;
407 - while (*nextp != '\0');
409 + if (__builtin_expect (INTUSE(__libc_security_mask) & 2, 0))
411 + static const char unsecure_uid_envvars[] =
412 + UNSECURE_UID_ENVVARS;
414 + for (nextp = unsecure_uid_envvars; *nextp != '\0';
415 + nextp = (char *) rawmemchr (nextp, '\0') + 1)
421 + /* This loop is buggy: it will only check the first occurrence of each
422 + variable (but will correctly remove all in case of a match). This
423 + may be a problem if the list is later re-ordered or accessed by an
424 + application with something other than the glibc getenv(). */
425 + for (nextp = restricted_envvars; *nextp != '\0';
426 + nextp = (char *) rawmemchr (nextp, '\0') + 1)
428 + const char *value = getenv (nextp);
429 + if (value && (value[0] == '.' || strchr(value, '/')))
433 if (__access ("/etc/suid-debug", F_OK) != 0)
435 diff -Naur glibc-2.8-20080929.orig/gmon/gmon.c glibc-2.8-20080929/gmon/gmon.c
436 --- glibc-2.8-20080929.orig/gmon/gmon.c 2008-03-19 06:43:31.000000000 +0000
437 +++ glibc-2.8-20080929/gmon/gmon.c 2008-10-15 00:30:49.000000000 +0000
439 # define O_NOFOLLOW 0
442 - env = getenv ("GMON_OUT_PREFIX");
443 - if (env != NULL && !__libc_enable_secure)
444 + env = __secure_getenv ("GMON_OUT_PREFIX");
447 size_t len = strlen (env);
449 diff -Naur glibc-2.8-20080929.orig/iconv/gconv_cache.c glibc-2.8-20080929/iconv/gconv_cache.c
450 --- glibc-2.8-20080929.orig/iconv/gconv_cache.c 2007-07-28 19:00:25.000000000 +0000
451 +++ glibc-2.8-20080929/iconv/gconv_cache.c 2008-10-15 00:30:49.000000000 +0000
454 /* We cannot use the cache if the GCONV_PATH environment variable is
456 - __gconv_path_envvar = getenv ("GCONV_PATH");
457 + __gconv_path_envvar = __secure_getenv ("GCONV_PATH");
458 if (__gconv_path_envvar != NULL)
461 diff -Naur glibc-2.8-20080929.orig/include/unistd.h glibc-2.8-20080929/include/unistd.h
462 --- glibc-2.8-20080929.orig/include/unistd.h 2006-07-31 05:57:52.000000000 +0000
463 +++ glibc-2.8-20080929/include/unistd.h 2008-10-15 00:30:49.000000000 +0000
464 @@ -142,10 +142,12 @@
465 and some functions contained in the C library ignore various
466 environment variables that normally affect them. */
467 extern int __libc_enable_secure attribute_relro;
468 +extern int __libc_security_mask attribute_relro;
469 extern int __libc_enable_secure_decided;
471 /* XXX The #ifdef should go. */
472 extern int __libc_enable_secure_internal attribute_relro attribute_hidden;
473 +extern int __libc_security_mask_internal attribute_relro attribute_hidden;
477 diff -Naur glibc-2.8-20080929.orig/intl/dcigettext.c glibc-2.8-20080929/intl/dcigettext.c
478 --- glibc-2.8-20080929.orig/intl/dcigettext.c 2008-03-31 00:37:17.000000000 +0000
479 +++ glibc-2.8-20080929/intl/dcigettext.c 2008-10-15 00:30:49.000000000 +0000
480 @@ -1391,7 +1391,7 @@
482 if (!output_charset_cached)
484 - const char *value = getenv ("OUTPUT_CHARSET");
485 + const char *value = __secure_getenv ("OUTPUT_CHARSET");
487 if (value != NULL && value[0] != '\0')
489 diff -Naur glibc-2.8-20080929.orig/io/getdirname.c glibc-2.8-20080929/io/getdirname.c
490 --- glibc-2.8-20080929.orig/io/getdirname.c 2001-07-06 04:54:53.000000000 +0000
491 +++ glibc-2.8-20080929/io/getdirname.c 2008-10-15 00:30:49.000000000 +0000
494 struct stat64 dotstat, pwdstat;
496 - pwd = getenv ("PWD");
497 + pwd = __secure_getenv ("PWD");
499 && stat64 (".", &dotstat) == 0
500 && stat64 (pwd, &pwdstat) == 0
501 diff -Naur glibc-2.8-20080929.orig/libidn/toutf8.c glibc-2.8-20080929/libidn/toutf8.c
502 --- glibc-2.8-20080929.orig/libidn/toutf8.c 2005-02-22 01:25:30.000000000 +0000
503 +++ glibc-2.8-20080929/libidn/toutf8.c 2008-10-15 00:30:49.000000000 +0000
506 stringprep_locale_charset (void)
508 - const char *charset = getenv ("CHARSET"); /* flawfinder: ignore */
509 + const char *charset = __secure_getenv ("CHARSET");
511 if (charset && *charset)
513 diff -Naur glibc-2.8-20080929.orig/locale/newlocale.c glibc-2.8-20080929/locale/newlocale.c
514 --- glibc-2.8-20080929.orig/locale/newlocale.c 2008-03-31 00:37:03.000000000 +0000
515 +++ glibc-2.8-20080929/locale/newlocale.c 2008-10-15 00:30:49.000000000 +0000
520 - locpath_var = getenv ("LOCPATH");
521 + locpath_var = __secure_getenv ("LOCPATH");
522 if (locpath_var != NULL && locpath_var[0] != '\0')
524 if (__argz_create_sep (locpath_var, ':',
525 diff -Naur glibc-2.8-20080929.orig/locale/setlocale.c glibc-2.8-20080929/locale/setlocale.c
526 --- glibc-2.8-20080929.orig/locale/setlocale.c 2008-03-31 00:37:03.000000000 +0000
527 +++ glibc-2.8-20080929/locale/setlocale.c 2008-10-15 00:30:49.000000000 +0000
532 - locpath_var = getenv ("LOCPATH");
533 + locpath_var = __secure_getenv ("LOCPATH");
534 if (locpath_var != NULL && locpath_var[0] != '\0')
536 if (__argz_create_sep (locpath_var, ':',
537 diff -Naur glibc-2.8-20080929.orig/malloc/arena.c glibc-2.8-20080929/malloc/arena.c
538 --- glibc-2.8-20080929.orig/malloc/arena.c 2007-12-12 00:11:27.000000000 +0000
539 +++ glibc-2.8-20080929/malloc/arena.c 2008-10-15 00:30:49.000000000 +0000
540 @@ -494,10 +494,10 @@
546 secure = __libc_enable_secure;
548 - if (__builtin_expect (_environ != NULL, 1))
549 + if (! secure && __builtin_expect (_environ != NULL, 1))
551 char **runp = _environ;
553 @@ -520,26 +520,20 @@
559 if (memcmp (envline, "TOP_PAD_", 8) == 0)
560 mALLOPt(M_TOP_PAD, atoi(&envline[9]));
561 else if (memcmp (envline, "PERTURB_", 8) == 0)
562 mALLOPt(M_PERTURB, atoi(&envline[9]));
566 - if (! secure && memcmp (envline, "MMAP_MAX_", 9) == 0)
567 + if (memcmp (envline, "MMAP_MAX_", 9) == 0)
568 mALLOPt(M_MMAP_MAX, atoi(&envline[10]));
573 if (memcmp (envline, "TRIM_THRESHOLD_", 15) == 0)
574 mALLOPt(M_TRIM_THRESHOLD, atoi(&envline[16]));
575 else if (memcmp (envline, "MMAP_THRESHOLD_", 15) == 0)
576 mALLOPt(M_MMAP_THRESHOLD, atoi(&envline[16]));
581 diff -Naur glibc-2.8-20080929.orig/malloc/memusage.c glibc-2.8-20080929/malloc/memusage.c
582 --- glibc-2.8-20080929.orig/malloc/memusage.c 2006-12-08 17:13:24.000000000 +0000
583 +++ glibc-2.8-20080929/malloc/memusage.c 2008-10-15 00:30:49.000000000 +0000
588 - const char *env = getenv ("MEMUSAGE_PROG_NAME");
589 + const char *env = __secure_getenv ("MEMUSAGE_PROG_NAME");
590 size_t prog_len = strlen (__progname);
597 - outname = getenv ("MEMUSAGE_OUTPUT");
598 + outname = __secure_getenv ("MEMUSAGE_OUTPUT");
599 if (outname != NULL && outname[0] != '\0'
600 && (access (outname, R_OK | W_OK) == 0 || errno == ENOENT))
603 /* Determine the buffer size. We use the default if the
604 environment variable is not present. */
605 buffer_size = DEFAULT_BUFFER_SIZE;
606 - if (getenv ("MEMUSAGE_BUFFER_SIZE") != NULL)
607 + if (__secure_getenv ("MEMUSAGE_BUFFER_SIZE") != NULL)
609 buffer_size = atoi (getenv ("MEMUSAGE_BUFFER_SIZE"));
610 if (buffer_size == 0 || buffer_size > DEFAULT_BUFFER_SIZE)
614 /* Possibly enable timer-based stack pointer retrieval. */
615 - if (getenv ("MEMUSAGE_NO_TIMER") == NULL)
616 + if (__secure_getenv ("MEMUSAGE_NO_TIMER") == NULL)
618 struct sigaction act;
624 - if (!not_me && getenv ("MEMUSAGE_TRACE_MMAP") != NULL)
625 + if (!not_me && __secure_getenv ("MEMUSAGE_TRACE_MMAP") != NULL)
629 diff -Naur glibc-2.8-20080929.orig/nis/nis_defaults.c glibc-2.8-20080929/nis/nis_defaults.c
630 --- glibc-2.8-20080929.orig/nis/nis_defaults.c 2006-10-11 16:22:34.000000000 +0000
631 +++ glibc-2.8-20080929/nis/nis_defaults.c 2008-10-15 00:30:49.000000000 +0000
634 char *cptr = defaults;
636 - cptr = getenv ("NIS_DEFAULTS");
637 + cptr = __secure_getenv ("NIS_DEFAULTS");
643 char *cptr = defaults;
645 - cptr = getenv ("NIS_DEFAULTS");
646 + cptr = __secure_getenv ("NIS_DEFAULTS");
651 return searchttl (defaults);
654 - cptr = getenv ("NIS_DEFAULTS");
655 + cptr = __secure_getenv ("NIS_DEFAULTS");
660 result = searchaccess (param, result);
663 - cptr = getenv ("NIS_DEFAULTS");
664 + cptr = __secure_getenv ("NIS_DEFAULTS");
665 if (cptr != NULL && strstr (cptr, "access=") != NULL)
666 result = searchaccess (cptr, result);
668 diff -Naur glibc-2.8-20080929.orig/nis/nis_local_names.c glibc-2.8-20080929/nis/nis_local_names.c
669 --- glibc-2.8-20080929.orig/nis/nis_local_names.c 2006-04-07 06:52:01.000000000 +0000
670 +++ glibc-2.8-20080929/nis/nis_local_names.c 2008-10-15 00:30:49.000000000 +0000
674 if (__nisgroup[0] == '\0'
675 - && (cptr = getenv ("NIS_GROUP")) != NULL
676 + && (cptr = __secure_getenv ("NIS_GROUP")) != NULL
677 && strlen (cptr) < NIS_MAXNAMELEN)
679 char *cp = stpcpy (__nisgroup, cptr);
680 diff -Naur glibc-2.8-20080929.orig/nis/nis_subr.c glibc-2.8-20080929/nis/nis_subr.c
681 --- glibc-2.8-20080929.orig/nis/nis_subr.c 2007-07-28 20:43:36.000000000 +0000
682 +++ glibc-2.8-20080929/nis/nis_subr.c 2008-10-15 00:30:49.000000000 +0000
686 /* Get the search path, where we have to search "name" */
687 - path = getenv ("NIS_PATH");
688 + path = __secure_getenv ("NIS_PATH");
690 path = strdupa ("$");
692 diff -Naur glibc-2.8-20080929.orig/posix/execvp.c glibc-2.8-20080929/posix/execvp.c
693 --- glibc-2.8-20080929.orig/posix/execvp.c 2007-01-03 23:01:15.000000000 +0000
694 +++ glibc-2.8-20080929/posix/execvp.c 2008-10-15 00:30:49.000000000 +0000
699 - char *path = getenv ("PATH");
700 + char *path = __secure_getenv ("PATH");
703 pathlen = confstr (_CS_PATH, (char *) NULL, 0);
704 @@ -116,11 +116,11 @@
707 /* There is no `PATH' in the environment.
708 - The default search path is the current directory
709 - followed by the path `confstr' returns for `_CS_PATH'. */
710 + The default search path is what `confstr' returns
712 path = name + pathlen + len + 1;
714 - (void) confstr (_CS_PATH, path + 1, pathlen);
716 + (void) confstr (_CS_PATH, path, pathlen);
719 /* Copy the file name at the top. */
720 diff -Naur glibc-2.8-20080929.orig/posix/glob.c glibc-2.8-20080929/posix/glob.c
721 --- glibc-2.8-20080929.orig/posix/glob.c 2007-10-15 04:59:03.000000000 +0000
722 +++ glibc-2.8-20080929/posix/glob.c 2008-10-15 00:30:49.000000000 +0000
724 && (dirname[2] == '\0' || dirname[2] == '/')))
726 /* Look up home directory. */
727 - const char *home_dir = getenv ("HOME");
728 + const char *home_dir = __secure_getenv ("HOME");
730 if (home_dir == NULL || home_dir[0] == '\0')
732 diff -Naur glibc-2.8-20080929.orig/posix/wordexp.c glibc-2.8-20080929/posix/wordexp.c
733 --- glibc-2.8-20080929.orig/posix/wordexp.c 2007-01-25 00:43:39.000000000 +0000
734 +++ glibc-2.8-20080929/posix/wordexp.c 2008-10-15 00:30:49.000000000 +0000
736 results are unspecified. We do a lookup on the uid if
739 - home = getenv ("HOME");
740 + home = __secure_getenv ("HOME");
743 *word = w_addstr (*word, word_length, max_length, home);
744 @@ -1493,7 +1493,7 @@
748 - value = getenv (env);
749 + value = __secure_getenv (env);
751 if (value == NULL && (flags & WRDE_UNDEF))
753 @@ -2262,7 +2262,7 @@
754 /* Find out what the field separators are.
755 * There are two types: whitespace and non-whitespace.
757 - ifs = getenv ("IFS");
758 + ifs = __secure_getenv ("IFS");
761 /* IFS unset - use <space><tab><newline>. */
762 diff -Naur glibc-2.8-20080929.orig/resolv/res_hconf.c glibc-2.8-20080929/resolv/res_hconf.c
763 --- glibc-2.8-20080929.orig/resolv/res_hconf.c 2007-11-23 03:03:31.000000000 +0000
764 +++ glibc-2.8-20080929/resolv/res_hconf.c 2008-10-15 00:30:49.000000000 +0000
767 memset (&_res_hconf, '\0', sizeof (_res_hconf));
769 - hconf_name = getenv (ENV_HOSTCONF);
770 + hconf_name = __secure_getenv (ENV_HOSTCONF);
771 if (hconf_name == NULL)
772 hconf_name = _PATH_HOSTCONF;
774 @@ -323,23 +323,23 @@
778 - envval = getenv (ENV_SPOOF);
779 + envval = __secure_getenv (ENV_SPOOF);
781 arg_spoof (ENV_SPOOF, 1, envval);
783 - envval = getenv (ENV_MULTI);
784 + envval = __secure_getenv (ENV_MULTI);
786 arg_bool (ENV_MULTI, 1, envval, HCONF_FLAG_MULTI);
788 - envval = getenv (ENV_REORDER);
789 + envval = __secure_getenv (ENV_REORDER);
791 arg_bool (ENV_REORDER, 1, envval, HCONF_FLAG_REORDER);
793 - envval = getenv (ENV_TRIM_ADD);
794 + envval = __secure_getenv (ENV_TRIM_ADD);
796 arg_trimdomain_list (ENV_TRIM_ADD, 1, envval);
798 - envval = getenv (ENV_TRIM_OVERR);
799 + envval = __secure_getenv (ENV_TRIM_OVERR);
802 _res_hconf.num_trimdomains = 0;
803 diff -Naur glibc-2.8-20080929.orig/resolv/res_init.c glibc-2.8-20080929/resolv/res_init.c
804 --- glibc-2.8-20080929.orig/resolv/res_init.c 2008-04-07 17:20:25.000000000 +0000
805 +++ glibc-2.8-20080929/resolv/res_init.c 2008-10-15 00:30:49.000000000 +0000
809 /* Allow user to override the local domain definition */
810 - if ((cp = getenv("LOCALDOMAIN")) != NULL) {
811 + if ((cp = __secure_getenv("LOCALDOMAIN")) != NULL) {
812 (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
813 statp->defdname[sizeof(statp->defdname) - 1] = '\0';
816 #endif /* !RFC1535 */
819 - if ((cp = getenv("RES_OPTIONS")) != NULL)
820 + if ((cp = __secure_getenv("RES_OPTIONS")) != NULL)
821 res_setoptions(statp, cp, "env");
822 statp->options |= RES_INIT;
824 diff -Naur glibc-2.8-20080929.orig/resolv/res_query.c glibc-2.8-20080929/resolv/res_query.c
825 --- glibc-2.8-20080929.orig/resolv/res_query.c 2007-02-09 23:43:25.000000000 +0000
826 +++ glibc-2.8-20080929/resolv/res_query.c 2008-10-15 00:30:49.000000000 +0000
829 if (statp->options & RES_NOALIASES)
831 - file = getenv("HOSTALIASES");
832 + file = __secure_getenv("HOSTALIASES");
833 if (file == NULL || (fp = fopen(file, "r")) == NULL)
836 diff -Naur glibc-2.8-20080929.orig/stdlib/fmtmsg.c glibc-2.8-20080929/stdlib/fmtmsg.c
837 --- glibc-2.8-20080929.orig/stdlib/fmtmsg.c 2006-05-15 18:41:18.000000000 +0000
838 +++ glibc-2.8-20080929/stdlib/fmtmsg.c 2008-10-15 00:30:49.000000000 +0000
843 - const char *msgverb_var = getenv ("MSGVERB");
844 - const char *sevlevel_var = getenv ("SEV_LEVEL");
845 + const char *msgverb_var = __secure_getenv ("MSGVERB");
846 + const char *sevlevel_var = __secure_getenv ("SEV_LEVEL");
848 if (msgverb_var != NULL && msgverb_var[0] != '\0')
850 diff -Naur glibc-2.8-20080929.orig/sunrpc/rpc_svcout.c glibc-2.8-20080929/sunrpc/rpc_svcout.c
851 --- glibc-2.8-20080929.orig/sunrpc/rpc_svcout.c 2005-11-21 15:43:03.000000000 +0000
852 +++ glibc-2.8-20080929/sunrpc/rpc_svcout.c 2008-10-15 00:30:49.000000000 +0000
854 f_print (fout, "\t\t_rpcpmstart = 1;\n");
856 open_log_file (infile, "\t\t");
857 - f_print (fout, "\t\tif ((netid = getenv(\"NLSPROVIDER\")) == NULL) {\n");
858 + f_print (fout, "\t\tif ((netid = __secure_getenv(\"NLSPROVIDER\")) == NULL) {\n");
859 sprintf (_errbuf, "cannot get transport name");
860 print_err_message ("\t\t\t");
861 f_print (fout, "\t\t} else if ((nconf = getnetconfigent(netid)) == NULL) {\n");
862 diff -Naur glibc-2.8-20080929.orig/sysdeps/generic/unsecvars.h glibc-2.8-20080929/sysdeps/generic/unsecvars.h
863 --- glibc-2.8-20080929.orig/sysdeps/generic/unsecvars.h 2006-10-11 16:24:05.000000000 +0000
864 +++ glibc-2.8-20080929/sysdeps/generic/unsecvars.h 2008-10-15 00:32:09.000000000 +0000
866 all stuffed in a single string which means they have to be terminated
867 with a '\0' explicitly. */
868 #define UNSECURE_ENVVARS \
874 - "LD_DEBUG_OUTPUT\0" \
875 - "LD_DYNAMIC_WEAK\0" \
876 - "LD_LIBRARY_PATH\0" \
877 - "LD_ORIGIN_PATH\0" \
881 - "LD_USE_LOAD_BIAS\0" \
887 - "RESOLV_HOST_CONF\0" \
890 + "ARGP_HELP_FMT\0" \
894 + "GMON_OUT_PREFIX\0" \
895 + "HESIOD_CONFIG\0" \
902 + "LD_DEBUG_OUTPUT\0" \
903 + "LD_DYNAMIC_WEAK\0" \
904 + "LD_HWCAP_MASK\0" \
905 + "LD_LIBRARY_PATH\0" \
906 + "LD_ORIGIN_PATH\0" \
907 + "LD_POINTER_GUARD\0" \
910 + "LD_PROFILE_OUTPUT\0" \
912 + "LD_TRACE_LOADED_OBJECTS\0" \
913 + "LD_TRACE_PRELINKING\0" \
914 + "LD_USE_LOAD_BIAS\0" \
919 + "MALLOC_CHECK_\0" \
920 + "MALLOC_MMAP_MAX_\0" \
921 + "MALLOC_MMAP_THRESHOLD_\0" \
922 + "MALLOC_PERTURB_\0" \
923 + "MALLOC_TOP_PAD_\0" \
925 + "MALLOC_TRIM_THRESHOLD_\0" \
926 + "MEMUSAGE_BUFFER_SIZE\0" \
927 + "MEMUSAGE_NO_TIMER\0" \
928 + "MEMUSAGE_OUTPUT\0" \
929 + "MEMUSAGE_PROG_NAME\0" \
930 + "MEMUSAGE_TRACE_MMAP\0" \
932 + "MUDFLAP_OPTIONS\0" \
937 + "PCPROFILE_OUTPUT\0" \
938 + "POSIXLY_CORRECT\0" \
940 + "RESOLV_ADD_TRIM_DOMAINS\0" \
941 + "RESOLV_HOST_CONF\0" \
943 + "RESOLV_OVERRIDE_TRIM_DOMAINS\0" \
944 + "RESOLV_REORDER\0" \
945 + "RESOLV_SPOOF_CHECK\0" \
947 + "SEGFAULT_OUTPUT_NAME\0" \
948 + "SEGFAULT_SIGNALS\0" \
949 + "SEGFAULT_USE_ALTSTACK\0" \
954 +#define UNSECURE_UID_ENVVARS \
957 +#define RESTRICTED_ENVVARS \
964 + "LC_IDENTIFICATION\0" \
965 + "LC_MEASUREMENT\0" \
974 diff -Naur glibc-2.8-20080929.orig/sysdeps/posix/spawni.c glibc-2.8-20080929/sysdeps/posix/spawni.c
975 --- glibc-2.8-20080929.orig/sysdeps/posix/spawni.c 2006-06-04 22:16:05.000000000 +0000
976 +++ glibc-2.8-20080929/sysdeps/posix/spawni.c 2008-10-15 00:30:49.000000000 +0000
977 @@ -227,16 +227,15 @@
980 /* We have to search for FILE on the path. */
981 - path = getenv ("PATH");
982 + path = __secure_getenv ("PATH");
985 /* There is no `PATH' in the environment.
986 - The default search path is the current directory
987 - followed by the path `confstr' returns for `_CS_PATH'. */
988 + The default search path is ehat `confstr' returns
990 len = confstr (_CS_PATH, (char *) NULL, 0);
991 - path = (char *) __alloca (1 + len);
993 - (void) confstr (_CS_PATH, path + 1, len);
994 + path = (char *) __alloca (len);
995 + (void) confstr (_CS_PATH, path, len);
998 len = strlen (file) + 1;
999 diff -Naur glibc-2.8-20080929.orig/sysdeps/unix/sysv/linux/dl-librecon.h glibc-2.8-20080929/sysdeps/unix/sysv/linux/dl-librecon.h
1000 --- glibc-2.8-20080929.orig/sysdeps/unix/sysv/linux/dl-librecon.h 2004-03-05 10:14:48.000000000 +0000
1001 +++ glibc-2.8-20080929/sysdeps/unix/sysv/linux/dl-librecon.h 2008-10-15 00:30:49.000000000 +0000
1004 #define DL_OSVERSION_INIT \
1006 - char *assume_kernel = getenv ("LD_ASSUME_KERNEL"); \
1007 + char *assume_kernel = __secure_getenv ("LD_ASSUME_KERNEL"); \
1008 if (assume_kernel) \
1009 _dl_osversion_init (assume_kernel); \
1011 diff -Naur glibc-2.8-20080929.orig/sysdeps/unix/sysv/linux/i386/dl-librecon.h glibc-2.8-20080929/sysdeps/unix/sysv/linux/i386/dl-librecon.h
1012 --- glibc-2.8-20080929.orig/sysdeps/unix/sysv/linux/i386/dl-librecon.h 2004-10-14 01:53:55.000000000 +0000
1013 +++ glibc-2.8-20080929/sysdeps/unix/sysv/linux/i386/dl-librecon.h 2008-10-15 00:30:49.000000000 +0000
1015 /* Extra unsecure variables. The names are all stuffed in a single
1016 string which means they have to be terminated with a '\0' explicitly. */
1017 #define EXTRA_UNSECURE_ENVVARS \
1018 + "LD_LIBRARY_VERSION\0" \
1019 "LD_AOUT_LIBRARY_PATH\0" \
1022 diff -Naur glibc-2.8-20080929.orig/time/getdate.c glibc-2.8-20080929/time/getdate.c
1023 --- glibc-2.8-20080929.orig/time/getdate.c 2007-12-10 01:40:43.000000000 +0000
1024 +++ glibc-2.8-20080929/time/getdate.c 2008-10-15 00:30:49.000000000 +0000
1029 - datemsk = getenv ("DATEMSK");
1030 + datemsk = __secure_getenv ("DATEMSK");
1031 if (datemsk == NULL || *datemsk == '\0')
1034 diff -Naur glibc-2.8-20080929.orig/time/tzfile.c glibc-2.8-20080929/time/tzfile.c
1035 --- glibc-2.8-20080929.orig/time/tzfile.c 2007-11-06 01:03:43.000000000 +0000
1036 +++ glibc-2.8-20080929/time/tzfile.c 2008-10-15 00:30:49.000000000 +0000
1038 unsigned int len, tzdir_len;
1041 - tzdir = getenv ("TZDIR");
1042 + tzdir = __secure_getenv ("TZDIR");
1043 if (tzdir == NULL || *tzdir == '\0')
1045 tzdir = default_tzdir;
1046 diff -Naur glibc-2.8-20080929.orig/time/tzset.c glibc-2.8-20080929/time/tzset.c
1047 --- glibc-2.8-20080929.orig/time/tzset.c 2008-03-19 06:43:34.000000000 +0000
1048 +++ glibc-2.8-20080929/time/tzset.c 2008-10-15 00:30:49.000000000 +0000
1049 @@ -383,8 +383,11 @@
1053 - /* Examine the TZ environment variable. */
1054 - tz = getenv ("TZ");
1055 + /* Examine the TZ environment variable. This doesn't really have to be
1056 + a __secure_getenv() call as __tzfile_read() tries to only read files
1057 + found under a trusted directory, but this helps reduce the amount of
1058 + security-critical code. */
1059 + tz = __secure_getenv ("TZ");
1060 if (tz == NULL && !explicit)
1061 /* Use the site-wide default. This is a file name which means we
1062 would not see changes to the file if we compare only the file