summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2014-08-18 07:56:08 -0400
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2014-08-18 15:19:46 +0200
commit94246e65e20b5390d53858447526b231ef1afd67 (patch)
tree3b7f55ab2a0b43cc72c114a1b68253174fd0bfe1
parent8c93ff92c37e2ed577c593236d24d09d7dcaa3ab (diff)
libc: add issetugid()
issetugid() returns 1 if the process environment or memory address space is considered tainted, and returns 0 otherwise. This happens, for example, when a process's privileges are elevated by the setuid or setgid flags on an executable belonging to root. This function first appeard in OpenBSD 2.0 and is needed for the LibreSSL. This patch follows the same logic as the equivalent musl commit. For more information see the commit message at http://git.musl-libc.org/cgit/musl/commit/?id=ddddec106fd17c3aca3287005d21e92f742aa9d4 Signed-off-by: Anthony G. Basile <blueness@gentoo.org> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rw-r--r--include/unistd.h14
-rw-r--r--libc/misc/file/issetugid.c10
-rw-r--r--libc/misc/internals/__uClibc_main.c11
3 files changed, 35 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
index 540062a42..967e058a3 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1168,6 +1168,20 @@ extern long int syscall (long int __sysno, ...) __THROW;
#endif /* Use misc. */
+/* Are we in a secure process environment or are we dealing with setuid
+ * stuff? This value is returned by issetugid().
+ */
+extern int _pe_secure;
+libc_hidden_proto(_pe_secure)
+
+#ifdef __USE_BSD
+/* issetugid() returns 1 if the process environment or memory address space
+ is considered tainted, and returns 0 otherwise. This happens, for example,
+ when a process's privileges are elevated by the setuid or setgid flags on
+ an executable belonging to root.
+*/
+extern int issetugid(void);
+#endif
#if (defined __USE_MISC || defined __USE_XOPEN_EXTENDED) && !defined F_LOCK
/* NOTE: These declarations also appear in <fcntl.h>; be sure to keep both
diff --git a/libc/misc/file/issetugid.c b/libc/misc/file/issetugid.c
new file mode 100644
index 000000000..6756a1e85
--- /dev/null
+++ b/libc/misc/file/issetugid.c
@@ -0,0 +1,10 @@
+/* Copyright (C) 2013 Gentoo Foundation
+ * Licensed under LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
+ */
+
+#include <unistd.h>
+
+int issetugid(void)
+{
+ return _pe_secure;
+}
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index a37751f2d..1f1e601e8 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -40,6 +40,14 @@
#include <locale.h>
#endif
+/* Are we in a secure process environment or are we dealing
+ * with setuid stuff? If we are dynamically linked, then we
+ * already have _dl_secure, otherwise we need to re-examine
+ * auxvt[] below.
+ */
+int _pe_secure = 0;
+libc_hidden_data_def(_pe_secure)
+
#ifndef SHARED
void *__libc_stack_end = NULL;
@@ -391,7 +399,10 @@ void __uClibc_main(int (*main)(int, char **, char **), int argc,
__check_one_fd (STDIN_FILENO, O_RDONLY | O_NOFOLLOW);
__check_one_fd (STDOUT_FILENO, O_RDWR | O_NOFOLLOW);
__check_one_fd (STDERR_FILENO, O_RDWR | O_NOFOLLOW);
+ _pe_secure = 1 ;
}
+ else
+ _pe_secure = 0 ;
#endif
__uclibc_progname = *argv;