public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: libc-alpha@sourceware.org
Subject: [PATCH v4 07/10] Use <startup.h> in __libc_init_secure
Date: Mon, 18 Jan 2021 16:25:05 +0000	[thread overview]
Message-ID: <be1b797ea8c1930e49d4e034b5414ff20effc1c3.1610986541.git.szabolcs.nagy@arm.com> (raw)
In-Reply-To: <cover.1610986541.git.szabolcs.nagy@arm.com>

From: "H.J. Lu" <hjl.tools@gmail.com>

Since __libc_init_secure is called before ARCH_SETUP_TLS, it must use
"int $0x80" for system calls in i386 static PIE.  Add startup_getuid,
startup_geteuid, startup_getgid and startup_getegid to <startup.h>.
Update __libc_init_secure to use them.
---
 elf/enbl-secure.c                      |  6 +++---
 sysdeps/generic/startup.h              | 26 +++++++++++++++++++++++
 sysdeps/unix/sysv/linux/i386/startup.h | 29 ++++++++++++++++++++++++--
 3 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/elf/enbl-secure.c b/elf/enbl-secure.c
index ffd7938605..9e47526bd3 100644
--- a/elf/enbl-secure.c
+++ b/elf/enbl-secure.c
@@ -23,7 +23,7 @@
 #if BUILD_PIE_DEFAULT
 # pragma GCC visibility push(hidden)
 #endif
-#include <unistd.h>
+#include <startup.h>
 #include <libc-internal.h>
 
 /* If nonzero __libc_enable_secure is already set.  */
@@ -35,6 +35,6 @@ void
 __libc_init_secure (void)
 {
   if (__libc_enable_secure_decided == 0)
-    __libc_enable_secure = (__geteuid () != __getuid ()
-			    || __getegid () != __getgid ());
+    __libc_enable_secure = (startup_geteuid () != startup_getuid ()
+			    || startup_getegid () != startup_getgid ());
 }
diff --git a/sysdeps/generic/startup.h b/sysdeps/generic/startup.h
index 56c899a65e..04f20cde47 100644
--- a/sysdeps/generic/startup.h
+++ b/sysdeps/generic/startup.h
@@ -19,5 +19,31 @@
 /* Targets should override this file if the default definitions below
    will not work correctly very early before TLS is initialized.  */
 
+#include <unistd.h>
+
 /* Use macro instead of inline function to avoid including <stdio.h>.  */
 #define _startup_fatal(message) __libc_fatal ((message))
+
+static inline uid_t
+startup_getuid (void)
+{
+  return __getuid ();
+}
+
+static inline uid_t
+startup_geteuid (void)
+{
+  return __geteuid ();
+}
+
+static inline gid_t
+startup_getgid (void)
+{
+  return __getgid ();
+}
+
+static inline gid_t
+startup_getegid (void)
+{
+  return __getegid ();
+}
diff --git a/sysdeps/unix/sysv/linux/i386/startup.h b/sysdeps/unix/sysv/linux/i386/startup.h
index 3eb4cc43a2..dee7a4f1d3 100644
--- a/sysdeps/unix/sysv/linux/i386/startup.h
+++ b/sysdeps/unix/sysv/linux/i386/startup.h
@@ -17,11 +17,12 @@
    <https://www.gnu.org/licenses/>.  */
 
 #if BUILD_PIE_DEFAULT
-# include <abort-instr.h>
-
 /* Can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE.  */
 # define I386_USE_SYSENTER 0
 
+# include <sysdep.h>
+# include <abort-instr.h>
+
 __attribute__ ((__noreturn__))
 static inline void
 _startup_fatal (const char *message __attribute__ ((unused)))
@@ -31,6 +32,30 @@ _startup_fatal (const char *message __attribute__ ((unused)))
   ABORT_INSTRUCTION;
   __builtin_unreachable ();
 }
+
+static inline uid_t
+startup_getuid (void)
+{
+  return (uid_t) INTERNAL_SYSCALL_CALL (getuid32);
+}
+
+static inline uid_t
+startup_geteuid (void)
+{
+  return (uid_t) INTERNAL_SYSCALL_CALL (geteuid32);
+}
+
+static inline gid_t
+startup_getgid (void)
+{
+  return (gid_t) INTERNAL_SYSCALL_CALL (getgid32);
+}
+
+static inline gid_t
+startup_getegid (void)
+{
+  return (gid_t) INTERNAL_SYSCALL_CALL (getegid32);
+}
 #else
 # include_next <startup.h>
 #endif
-- 
2.17.1


  parent reply	other threads:[~2021-01-18 16:25 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 16:22 [PATCH v4 00/10] fix ifunc with static pie [BZ #27072] Szabolcs Nagy
2021-01-18 16:23 ` [PATCH v4 01/10] configure: Require PI_STATIC_AND_HIDDEN for static pie Szabolcs Nagy
2021-01-18 16:23 ` [PATCH v4 02/10] libmvec: Add extra-test-objs to test-extras Szabolcs Nagy
2021-01-18 20:04   ` Adhemerval Zanella
2021-01-18 16:23 ` [PATCH v4 03/10] elf: Make the tunable struct definition internal only Szabolcs Nagy
2021-01-18 16:24 ` [PATCH v4 04/10] elf: Avoid RELATIVE relocs in __tunables_init Szabolcs Nagy
2021-01-18 16:24 ` [PATCH v4 05/10] Use hidden visibility for early static PIE code Szabolcs Nagy
2021-01-18 21:49   ` Adhemerval Zanella
2021-01-18 16:24 ` [PATCH v4 06/10] elf: Avoid RELATIVE relocation for _dl_sysinfo Szabolcs Nagy
2021-01-19 13:51   ` Adhemerval Zanella
2021-01-19 14:25     ` V2 " H.J. Lu
2021-01-19 14:35       ` Adhemerval Zanella
2021-01-18 16:25 ` Szabolcs Nagy [this message]
2021-01-19 13:56   ` [PATCH v4 07/10] Use <startup.h> in __libc_init_secure Adhemerval Zanella
2021-01-18 16:25 ` [PATCH v4 08/10] csu: Move static pie self relocation later [BZ #27072] Szabolcs Nagy
2021-01-19 14:07   ` Adhemerval Zanella
2021-01-19 14:35     ` Szabolcs Nagy
2021-01-19 14:36       ` Adhemerval Zanella
2021-01-19 14:48         ` H.J. Lu
2021-01-19 15:24           ` Szabolcs Nagy
2021-01-19 15:32             ` H.J. Lu
2021-01-19 16:47               ` H.J. Lu
2021-01-19 17:03                 ` Szabolcs Nagy
2021-01-19 17:10                   ` H.J. Lu
2021-01-19 17:25                     ` Fāng-ruì Sòng
2021-01-19 17:33                       ` H.J. Lu
2021-01-19 17:38                         ` Fāng-ruì Sòng
2021-01-19 17:38                     ` Szabolcs Nagy
2021-01-19 17:42                       ` H.J. Lu
2021-01-19 17:47                         ` Szabolcs Nagy
2021-01-19 17:53                           ` H.J. Lu
2021-01-19 17:59                             ` H.J. Lu
2021-01-18 16:25 ` [PATCH v4 09/10] x86: Check ifunc resolver with CPU_FEATURE_USABLE " Szabolcs Nagy
2021-01-19 14:11   ` Adhemerval Zanella
2021-01-19 14:37     ` V2 " H.J. Lu
2021-01-21 16:33       ` H.J. Lu
2021-01-18 16:26 ` [PATCH v4 10/10] Make libc symbols hidden in static PIE Szabolcs Nagy
2021-01-18 21:37 ` [PATCH v4 00/10] fix ifunc with static pie [BZ #27072] Adhemerval Zanella
2021-01-19 18:25   ` Szabolcs Nagy
2021-01-19 19:41     ` H.J. Lu
2021-01-19 20:16       ` Adhemerval Zanella
2021-01-19 21:38         ` H.J. Lu
2021-01-20 11:29           ` Adhemerval Zanella
2021-01-20 12:38             ` Szabolcs Nagy
2021-01-20 12:49               ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be1b797ea8c1930e49d4e034b5414ff20effc1c3.1610986541.git.szabolcs.nagy@arm.com \
    --to=szabolcs.nagy@arm.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).