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