summaryrefslogtreecommitdiff
path: root/src/env
diff options
context:
space:
mode:
Diffstat (limited to 'src/env')
-rw-r--r--src/env/__init_tls.c5
-rw-r--r--src/env/__libc_start_main.c3
-rw-r--r--src/env/__stack_chk_fail.c11
-rw-r--r--src/env/secure_getenv.c8
4 files changed, 23 insertions, 4 deletions
diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c
index 5f12500c..a93141ed 100644
--- a/src/env/__init_tls.c
+++ b/src/env/__init_tls.c
@@ -67,7 +67,7 @@ void *__copy_tls(unsigned char *mem)
}
#endif
dtv[0] = libc.tls_cnt;
- td->dtv = td->dtv_copy = dtv;
+ td->dtv = dtv;
return td;
}
@@ -115,7 +115,8 @@ static void static_init_tls(size_t *aux)
& (main_tls.align-1);
#ifdef TLS_ABOVE_TP
main_tls.offset = GAP_ABOVE_TP;
- main_tls.offset += -GAP_ABOVE_TP & (main_tls.align-1);
+ main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image)
+ & (main_tls.align-1);
#else
main_tls.offset = main_tls.size;
#endif
diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
index 8fbe5262..c5b277bd 100644
--- a/src/env/__libc_start_main.c
+++ b/src/env/__libc_start_main.c
@@ -69,7 +69,8 @@ weak_alias(libc_start_init, __libc_start_init);
typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
static lsm2_fn libc_start_main_stage2;
-int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
+int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv,
+ void (*init_dummy)(), void(*fini_dummy)(), void(*ldso_dummy)())
{
char **envp = argv+argc+1;
diff --git a/src/env/__stack_chk_fail.c b/src/env/__stack_chk_fail.c
index e32596d1..e5352602 100644
--- a/src/env/__stack_chk_fail.c
+++ b/src/env/__stack_chk_fail.c
@@ -9,7 +9,16 @@ void __init_ssp(void *entropy)
if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t));
else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245;
- __pthread_self()->CANARY = __stack_chk_guard;
+#if UINTPTR_MAX >= 0xffffffffffffffff
+ /* Sacrifice 8 bits of entropy on 64bit to prevent leaking/
+ * overwriting the canary via string-manipulation functions.
+ * The NULL byte is on the second byte so that off-by-ones can
+ * still be detected. Endianness is taken care of
+ * automatically. */
+ ((char *)&__stack_chk_guard)[1] = 0;
+#endif
+
+ __pthread_self()->canary = __stack_chk_guard;
}
void __stack_chk_fail(void)
diff --git a/src/env/secure_getenv.c b/src/env/secure_getenv.c
new file mode 100644
index 00000000..72322f81
--- /dev/null
+++ b/src/env/secure_getenv.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include "libc.h"
+
+char *secure_getenv(const char *name)
+{
+ return libc.secure ? NULL : getenv(name);
+}