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