00db10
Partial backport (without the test) of:
00db10
00db10
commit 1c1243b6fc33c029488add276e56570a07803bfd
00db10
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
00db10
Date:   Tue Mar 7 20:52:04 2017 +0530
00db10
00db10
    Ignore and remove LD_HWCAP_MASK for AT_SECURE programs (bug #21209)
00db10
    
00db10
    The LD_HWCAP_MASK environment variable may alter the selection of
00db10
    function variants for some architectures.  For AT_SECURE process it
00db10
    means that if an outdated routine has a bug that would otherwise not
00db10
    affect newer platforms by default, LD_HWCAP_MASK will allow that bug
00db10
    to be exploited.
00db10
    
00db10
    To be on the safe side, ignore and disable LD_HWCAP_MASK for setuid
00db10
    binaries.
00db10
    
00db10
            [BZ #21209]
00db10
            * elf/rtld.c (process_envvars): Ignore LD_HWCAP_MASK for
00db10
            AT_SECURE processes.
00db10
            * sysdeps/generic/unsecvars.h: Add LD_HWCAP_MASK.
00db10
            * elf/tst-env-setuid.c (test_parent): Test LD_HWCAP_MASK.
00db10
            (test_child): Likewise.
00db10
            * elf/Makefile (tst-env-setuid-ENV): Add LD_HWCAP_MASK.
00db10
00db10
Index: b/elf/rtld.c
00db10
===================================================================
00db10
--- a/elf/rtld.c
00db10
+++ b/elf/rtld.c
00db10
@@ -2688,7 +2688,8 @@ process_envvars (enum mode *modep)
00db10
 
00db10
 	case 10:
00db10
 	  /* Mask for the important hardware capabilities.  */
00db10
-	  if (memcmp (envline, "HWCAP_MASK", 10) == 0)
00db10
+	  if (!__libc_enable_secure
00db10
+	      && memcmp (envline, "HWCAP_MASK", 10) == 0)
00db10
 	    GLRO(dl_hwcap_mask) = __strtoul_internal (&envline[11], NULL,
00db10
 						      0, 0);
00db10
 	  break;
00db10
Index: b/sysdeps/generic/unsecvars.h
00db10
===================================================================
00db10
--- a/sysdeps/generic/unsecvars.h
00db10
+++ b/sysdeps/generic/unsecvars.h
00db10
@@ -9,6 +9,7 @@
00db10
   "LD_DEBUG\0"								      \
00db10
   "LD_DEBUG_OUTPUT\0"							      \
00db10
   "LD_DYNAMIC_WEAK\0"							      \
00db10
+  "LD_HWCAP_MASK\0"							      \
00db10
   "LD_LIBRARY_PATH\0"							      \
00db10
   "LD_ORIGIN_PATH\0"							      \
00db10
   "LD_PRELOAD\0"							      \