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