support kernels with no SYS_open syscall, only SYS_openat
[musl] / src / env / __libc_start_main.c
index ac37492..d7481c2 100644 (file)
@@ -1,8 +1,11 @@
 #include <elf.h>
+#include <poll.h>
+#include <fcntl.h>
+#include "syscall.h"
+#include "atomic.h"
 #include "libc.h"
 
 void __init_tls(size_t *);
-void __init_security(size_t *);
 
 #ifndef SHARED
 static void dummy() {}
@@ -11,11 +14,17 @@ extern void (*const __init_array_start)() __attribute__((weak));
 extern void (*const __init_array_end)() __attribute__((weak));
 #endif
 
+static void dummy1(void *p) {}
+weak_alias(dummy1, __init_ssp);
+
 #define AUX_CNT 38
 
 extern size_t __hwcap, __sysinfo;
 extern char *__progname, *__progname_full;
 
+#ifndef SHARED
+static
+#endif
 void __init_libc(char **envp, char *pn)
 {
        size_t i, *auxv, aux[AUX_CNT] = { 0 };
@@ -33,7 +42,17 @@ void __init_libc(char **envp, char *pn)
        }
 
        __init_tls(aux);
-       __init_security(aux);
+       __init_ssp((void *)aux[AT_RANDOM]);
+
+       if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID]
+               && !aux[AT_SECURE]) return;
+
+       struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} };
+       __syscall(SYS_poll, pfd, 3, 0);
+       for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL)
+               if (__sys_open("/dev/null", O_RDWR)<0)
+                       a_crash();
+       libc.secure = 1;
 }
 
 int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)