Check getauxval on systems that have it when checking for setuid execution.
authorPauli <paul.dale@oracle.com>
Fri, 17 Aug 2018 04:35:37 +0000 (14:35 +1000)
committerPauli <paul.dale@oracle.com>
Mon, 20 Aug 2018 01:12:26 +0000 (11:12 +1000)
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/6993)

crypto/uid.c

index 4e1890f2d285172aef45102f574c435c5fa23517..b2bfee32b562ec5ef5942356dd43a15d095f0c23 100644 (file)
@@ -31,12 +31,18 @@ int OPENSSL_issetugid(void)
 # include OPENSSL_UNISTD
 # include <sys/types.h>
 
+# if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
+#  if __GLIBC_PREREQ(2, 16)
+#   include <sys/auxv.h>
+#  endif
+# endif
+
 int OPENSSL_issetugid(void)
 {
-    if (getuid() != geteuid())
-        return 1;
-    if (getgid() != getegid())
-        return 1;
-    return 0;
+# ifdef AT_SECURE
+    return getauxval(AT_SECURE) != 0;
+# else
+    return getuid() != geteuid() || getgid() != getegid();
+# endif
 }
 #endif