summaryrefslogtreecommitdiffstats
path: root/libc/misc
diff options
context:
space:
mode:
Diffstat (limited to 'libc/misc')
-rw-r--r--libc/misc/internals/Makefile2
-rw-r--r--libc/misc/internals/__uClibc_main.c79
-rw-r--r--libc/misc/pthread/weaks.c24
-rw-r--r--libc/misc/time/time.c8
-rw-r--r--libc/misc/wchar/wchar.c22
5 files changed, 97 insertions, 38 deletions
diff --git a/libc/misc/internals/Makefile b/libc/misc/internals/Makefile
index 803181a8f..fee3eca70 100644
--- a/libc/misc/internals/Makefile
+++ b/libc/misc/internals/Makefile
@@ -27,6 +27,8 @@ include $(TOPDIR)Rules.mak
CSRC=__uClibc_main.c tempname.c errno.c __errno_location.c __h_errno_location.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
+__uClibc_main.o: CFLAGS += $(SSP_DISABLE_FLAGS)
+
OBJS=$(COBJS)
OBJ_LIST=../../obj.misc.internals
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index c9f3d0e40..1ed05c6b2 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -3,7 +3,7 @@
* Erik Andersen 2002-2004
*
* __uClibc_main is the routine to be called by all the arch-specific
- * versions of crt0.S in uClibc.
+ * versions of crt1.S in uClibc.
*
* It is meant to handle any special initialization needed by the library
* such as setting the global variable(s) __environ (environ) and
@@ -26,9 +26,10 @@
#include <sys/stat.h>
#include <sys/sysmacros.h>
#ifdef __UCLIBC_HAS_SSP__
-extern void __guard_setup(void);
-#endif
+#include <ssp-internal.h>
+unsigned long __guard = 0UL;
+#endif
/*
* Prototypes.
@@ -106,6 +107,62 @@ static int __check_suid(void)
return 1;
}
+#ifdef __UCLIBC_HAS_SSP__
+static __always_inline void __guard_setup(void)
+{
+ if (__guard != 0UL)
+ return;
+
+#ifndef __SSP_QUICK_CANARY__
+
+ size_t size;
+
+# ifdef __SSP_USE_ERANDOM__
+ {
+ int mib[3];
+ /* Random is another depth in Linux, hence an array of 3. */
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_RANDOM;
+ mib[2] = RANDOM_ERANDOM;
+
+ size = sizeof(unsigned long);
+ if (SYSCTL(mib, 3, &__guard, &size, NULL, 0) != (-1))
+ if (__guard != 0UL)
+ return;
+ }
+# endif /* ifdef __SSP_USE_ERANDOM__ */
+ {
+ int fd;
+
+# ifdef __SSP_USE_ERANDOM__
+ /*
+ * Attempt to open kernel pseudo random device if one exists before
+ * opening urandom to avoid system entropy depletion.
+ */
+ if ((fd = OPEN("/dev/erandom", O_RDONLY)) == (-1))
+# endif
+ fd = OPEN("/dev/urandom", O_RDONLY);
+ if (fd != (-1)) {
+ size = READ(fd, (char *) &__guard, sizeof(__guard));
+ CLOSE(fd);
+ if (size == sizeof(__guard))
+ return;
+ }
+ }
+#endif /* ifndef __SSP_QUICK_CANARY__ */
+
+ /* Start with the "terminator canary". */
+ __guard = 0xFF0A0D00UL;
+
+ /* Everything failed? Or we are using a weakened model of the
+ * terminator canary */
+ {
+ struct timeval tv;
+ GETTIMEOFDAY(&tv, NULL);
+ __guard ^= tv.tv_usec ^ tv.tv_sec;
+ }
+}
+#endif /* __UCLIBC_HAS_SSP__ */
/* __uClibc_init completely initialize uClibc so it is ready to use.
*
@@ -117,7 +174,7 @@ static int __check_suid(void)
* uClibc is the address of __uClibc_init
*
* In all other cases we call it from the main stub
- * __uClibc_start_main.
+ * __uClibc_main.
*/
void __uClibc_init(void)
@@ -133,7 +190,7 @@ void __uClibc_init(void)
__pagesize = PAGE_SIZE;
#ifdef __UCLIBC_HAS_THREADS__
- /* Before we start initialzing uClibc we have to call
+ /* Before we start initializing uClibc we have to call
* __pthread_initialize_minimal so we can use pthread_locks
* whenever they are needed.
*/
@@ -141,6 +198,10 @@ void __uClibc_init(void)
__pthread_initialize_minimal();
#endif
+#ifdef __UCLIBC_HAS_SSP__
+ __guard_setup ();
+#endif
+
#ifdef __UCLIBC_HAS_LOCALE__
/* Initialize the global locale structure. */
if (likely(_locale_init!=NULL))
@@ -162,8 +223,8 @@ void attribute_hidden (*__app_fini)(void) = NULL;
void attribute_hidden (*__rtld_fini)(void) = NULL;
-/* __uClibc_start_main is the new main stub for uClibc. This function is
- * called from crt0 (version 0.9.16 or newer), after ALL shared libraries
+/* __uClibc_main is the new main stub for uClibc. This function is
+ * called from crt1 (version 0.9.28 or newer), after ALL shared libraries
* are initialized, just before we call the application's main function.
*/
void __attribute__ ((__noreturn__))
@@ -246,10 +307,6 @@ __uClibc_main(int (*main)(int, char **, char **), int argc,
}
#endif
-#ifdef __UCLIBC_HAS_SSP__
- __guard_setup ();
-#endif
-
/* Note: It is possible that any initialization done above could
* have resulted in errno being set nonzero, so set it to 0 before
* we call main.
diff --git a/libc/misc/pthread/weaks.c b/libc/misc/pthread/weaks.c
index 8486dc203..6767cfffb 100644
--- a/libc/misc/pthread/weaks.c
+++ b/libc/misc/pthread/weaks.c
@@ -24,6 +24,18 @@
static int __pthread_return_0 __P ((void));
static int __pthread_return_1 __P ((void));
+static int
+__pthread_return_0 (void)
+{
+ return 0;
+}
+
+static int
+__pthread_return_1 (void)
+{
+ return 1;
+}
+
/**********************************************************************/
/* Weaks for application/library use.
*
@@ -105,15 +117,3 @@ weak_alias (__pthread_return_0, __pthread_mutex_trylock)
weak_alias (__pthread_return_0, __pthread_mutex_unlock)
/**********************************************************************/
-
-static int
-__pthread_return_0 (void)
-{
- return 0;
-}
-
-static int
-__pthread_return_1 (void)
-{
- return 1;
-}
diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c
index 57ef2217a..914277698 100644
--- a/libc/misc/time/time.c
+++ b/libc/misc/time/time.c
@@ -713,15 +713,15 @@ struct tm *__time_localtime_tzi(register const time_t *__restrict timer,
/**********************************************************************/
#ifdef L_mktime
-/* Another name for `mktime'. */
-/* time_t timelocal(struct tm *tp) */
-weak_alias(mktime,timelocal);
-
time_t mktime(struct tm *timeptr)
{
return _time_mktime(timeptr, 1);
}
+/* Another name for `mktime'. */
+/* time_t timelocal(struct tm *tp) */
+weak_alias(mktime,timelocal);
+
#endif
/**********************************************************************/
#ifdef L_timegm
diff --git a/libc/misc/wchar/wchar.c b/libc/misc/wchar/wchar.c
index d1383c99f..e3553166d 100644
--- a/libc/misc/wchar/wchar.c
+++ b/libc/misc/wchar/wchar.c
@@ -261,9 +261,6 @@ int mbsinit(const mbstate_t *ps)
/**********************************************************************/
#ifdef L_mbrlen
-size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps)
- __attribute__ ((__weak__, __alias__("__mbrlen")));
-
size_t __mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps)
{
static mbstate_t mbstate; /* Rely on bss 0-init. */
@@ -271,6 +268,9 @@ size_t __mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps)
return mbrtowc(NULL, s, n, (ps != NULL) ? ps : &mbstate);
}
+size_t mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps)
+ __attribute__ ((__weak__, __alias__("__mbrlen")));
+
#endif
/**********************************************************************/
#ifdef L_mbrtowc
@@ -679,10 +679,6 @@ size_t _wchar_wcsntoutf8s(char *__restrict s, size_t n,
/* WARNING: We treat len as SIZE_MAX when dst is NULL! */
-size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
- size_t NMC, size_t len, mbstate_t *__restrict ps)
- __attribute__ ((__weak__, __alias__("__mbsnrtowcs")));
-
size_t __mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
size_t NMC, size_t len, mbstate_t *__restrict ps)
{
@@ -782,6 +778,10 @@ size_t __mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
return len - count;
}
+size_t mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
+ size_t NMC, size_t len, mbstate_t *__restrict ps)
+ __attribute__ ((__weak__, __alias__("__mbsnrtowcs")));
+
#endif
/**********************************************************************/
#ifdef L___wcsnrtombs
@@ -791,10 +791,6 @@ size_t __mbsnrtowcs(wchar_t *__restrict dst, const char **__restrict src,
/* Note: We completely ignore ps in all currently supported conversions.
* TODO: Check for valid state anyway? */
-size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
- size_t NWC, size_t len, mbstate_t *__restrict ps)
- __attribute__ ((__weak__, __alias__("__wcsnrtombs")));
-
size_t __wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
size_t NWC, size_t len, mbstate_t *__restrict ps)
{
@@ -904,6 +900,10 @@ size_t __wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
return len - count;
}
+size_t wcsnrtombs(char *__restrict dst, const wchar_t **__restrict src,
+ size_t NWC, size_t len, mbstate_t *__restrict ps)
+ __attribute__ ((__weak__, __alias__("__wcsnrtombs")));
+
#endif
/**********************************************************************/
#ifdef L_wcswidth