076f82
commit be9240c84c67de44959905a829141576965a0588
076f82
Author: Fangrui Song <maskray@google.com>
076f82
Date:   Tue Apr 19 15:52:27 2022 -0700
076f82
076f82
    elf: Remove __libc_init_secure
076f82
    
076f82
    After 73fc4e28b9464f0e13edc719a5372839970e7ddb,
076f82
    __libc_enable_secure_decided is always 0 and a statically linked
076f82
    executable may overwrite __libc_enable_secure without considering
076f82
    AT_SECURE.
076f82
    
076f82
    The __libc_enable_secure has been correctly initialized in _dl_aux_init,
076f82
    so just remove __libc_enable_secure_decided and __libc_init_secure.
076f82
    This allows us to remove some startup_get*id functions from
076f82
    22b79ed7f413cd980a7af0cf258da5bf82b6d5e5.
076f82
    
076f82
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
076f82
    (cherry picked from commit 3e9acce8c50883b6cd8a3fb653363d9fa21e1608)
076f82
076f82
diff --git a/csu/libc-start.c b/csu/libc-start.c
076f82
index d01e57ea59ceb880..a2fc2f6f9665a48f 100644
076f82
--- a/csu/libc-start.c
076f82
+++ b/csu/libc-start.c
076f82
@@ -285,9 +285,6 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
076f82
         }
076f82
     }
076f82
 
076f82
-  /* Initialize very early so that tunables can use it.  */
076f82
-  __libc_init_secure ();
076f82
-
076f82
   __tunables_init (__environ);
076f82
 
076f82
   ARCH_INIT_CPU_FEATURES ();
076f82
diff --git a/elf/enbl-secure.c b/elf/enbl-secure.c
076f82
index 9e47526bd3e444e1..1208610bd0670c74 100644
076f82
--- a/elf/enbl-secure.c
076f82
+++ b/elf/enbl-secure.c
076f82
@@ -26,15 +26,5 @@
076f82
 #include <startup.h>
076f82
 #include <libc-internal.h>
076f82
 
076f82
-/* If nonzero __libc_enable_secure is already set.  */
076f82
-int __libc_enable_secure_decided;
076f82
 /* Safest assumption, if somehow the initializer isn't run.  */
076f82
 int __libc_enable_secure = 1;
076f82
-
076f82
-void
076f82
-__libc_init_secure (void)
076f82
-{
076f82
-  if (__libc_enable_secure_decided == 0)
076f82
-    __libc_enable_secure = (startup_geteuid () != startup_getuid ()
076f82
-			    || startup_getegid () != startup_getgid ());
076f82
-}
076f82
diff --git a/include/libc-internal.h b/include/libc-internal.h
076f82
index 749dfb919ce4a62d..44fcb6bdf8751c1c 100644
076f82
--- a/include/libc-internal.h
076f82
+++ b/include/libc-internal.h
076f82
@@ -21,9 +21,6 @@
076f82
 
076f82
 #include <hp-timing.h>
076f82
 
076f82
-/* Initialize the `__libc_enable_secure' flag.  */
076f82
-extern void __libc_init_secure (void);
076f82
-
076f82
 /* Discover the tick frequency of the machine if something goes wrong,
076f82
    we return 0, an impossible hertz.  */
076f82
 extern int __profile_frequency (void);
076f82
diff --git a/include/unistd.h b/include/unistd.h
076f82
index 7849562c4272e2c9..5824485629793ccb 100644
076f82
--- a/include/unistd.h
076f82
+++ b/include/unistd.h
076f82
@@ -180,7 +180,6 @@ libc_hidden_proto (__sbrk)
076f82
    and some functions contained in the C library ignore various
076f82
    environment variables that normally affect them.  */
076f82
 extern int __libc_enable_secure attribute_relro;
076f82
-extern int __libc_enable_secure_decided;
076f82
 rtld_hidden_proto (__libc_enable_secure)
076f82
 
076f82
 
076f82
diff --git a/sysdeps/generic/startup.h b/sysdeps/generic/startup.h
076f82
index 04f20cde474cea89..c3be5430bd8bbaa6 100644
076f82
--- a/sysdeps/generic/startup.h
076f82
+++ b/sysdeps/generic/startup.h
076f82
@@ -23,27 +23,3 @@
076f82
 
076f82
 /* Use macro instead of inline function to avoid including <stdio.h>.  */
076f82
 #define _startup_fatal(message) __libc_fatal ((message))
076f82
-
076f82
-static inline uid_t
076f82
-startup_getuid (void)
076f82
-{
076f82
-  return __getuid ();
076f82
-}
076f82
-
076f82
-static inline uid_t
076f82
-startup_geteuid (void)
076f82
-{
076f82
-  return __geteuid ();
076f82
-}
076f82
-
076f82
-static inline gid_t
076f82
-startup_getgid (void)
076f82
-{
076f82
-  return __getgid ();
076f82
-}
076f82
-
076f82
-static inline gid_t
076f82
-startup_getegid (void)
076f82
-{
076f82
-  return __getegid ();
076f82
-}
076f82
diff --git a/sysdeps/mach/hurd/enbl-secure.c b/sysdeps/mach/hurd/enbl-secure.c
076f82
deleted file mode 100644
076f82
index 3e9a6b888d56754b..0000000000000000
076f82
--- a/sysdeps/mach/hurd/enbl-secure.c
076f82
+++ /dev/null
076f82
@@ -1,30 +0,0 @@
076f82
-/* Define and initialize the `__libc_enable_secure' flag.  Hurd version.
076f82
-   Copyright (C) 1998-2021 Free Software Foundation, Inc.
076f82
-   This file is part of the GNU C Library.
076f82
-
076f82
-   The GNU C Library is free software; you can redistribute it and/or
076f82
-   modify it under the terms of the GNU Lesser General Public
076f82
-   License as published by the Free Software Foundation; either
076f82
-   version 2.1 of the License, or (at your option) any later version.
076f82
-
076f82
-   The GNU C Library is distributed in the hope that it will be useful,
076f82
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
076f82
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
076f82
-   Lesser General Public License for more details.
076f82
-
076f82
-   You should have received a copy of the GNU Lesser General Public
076f82
-   License along with the GNU C Library; if not, see
076f82
-   <https://www.gnu.org/licenses/>.  */
076f82
-
076f82
-/* There is no need for this file in the Hurd; it is just a placeholder
076f82
-   to prevent inclusion of the sysdeps/generic version.
076f82
-   In the shared library, the `__libc_enable_secure' variable is defined
076f82
-   by the dynamic linker in dl-sysdep.c and set there.
076f82
-   In the static library, it is defined in init-first.c and set there.  */
076f82
-
076f82
-#include <libc-internal.h>
076f82
-
076f82
-void
076f82
-__libc_init_secure (void)
076f82
-{
076f82
-}
076f82
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
076f82
index a430aae085527163..4dc9017ec8754a1a 100644
076f82
--- a/sysdeps/mach/hurd/i386/init-first.c
076f82
+++ b/sysdeps/mach/hurd/i386/init-first.c
076f82
@@ -38,10 +38,6 @@ extern void __init_misc (int, char **, char **);
076f82
 unsigned long int __hurd_threadvar_stack_offset;
076f82
 unsigned long int __hurd_threadvar_stack_mask;
076f82
 
076f82
-#ifndef SHARED
076f82
-int __libc_enable_secure;
076f82
-#endif
076f82
-
076f82
 extern int __libc_argc attribute_hidden;
076f82
 extern char **__libc_argv attribute_hidden;
076f82
 extern char **_dl_argv;
076f82
diff --git a/sysdeps/unix/sysv/linux/i386/startup.h b/sysdeps/unix/sysv/linux/i386/startup.h
076f82
index dee7a4f1d3d420be..192c765361c17ed1 100644
076f82
--- a/sysdeps/unix/sysv/linux/i386/startup.h
076f82
+++ b/sysdeps/unix/sysv/linux/i386/startup.h
076f82
@@ -32,30 +32,6 @@ _startup_fatal (const char *message __attribute__ ((unused)))
076f82
   ABORT_INSTRUCTION;
076f82
   __builtin_unreachable ();
076f82
 }
076f82
-
076f82
-static inline uid_t
076f82
-startup_getuid (void)
076f82
-{
076f82
-  return (uid_t) INTERNAL_SYSCALL_CALL (getuid32);
076f82
-}
076f82
-
076f82
-static inline uid_t
076f82
-startup_geteuid (void)
076f82
-{
076f82
-  return (uid_t) INTERNAL_SYSCALL_CALL (geteuid32);
076f82
-}
076f82
-
076f82
-static inline gid_t
076f82
-startup_getgid (void)
076f82
-{
076f82
-  return (gid_t) INTERNAL_SYSCALL_CALL (getgid32);
076f82
-}
076f82
-
076f82
-static inline gid_t
076f82
-startup_getegid (void)
076f82
-{
076f82
-  return (gid_t) INTERNAL_SYSCALL_CALL (getegid32);
076f82
-}
076f82
 #else
076f82
 # include_next <startup.h>
076f82
 #endif