
11b3a0c2c5db
115412c37195
#explicit zero 1131456ac632
#brk 1158ebc243ea
#random 115323b39f7e
#undefined 116a91d9dddb
#merge 11a042b5a0ba
#vla formatting 119ec639de1b
#pthread 1149571a0a49
#read only 11149cc5ccb8
#zero 112e613ccbe7
#fork mmap 11e239c7dff8
#memprot pthread 110b03d92b7f
#xor 11de08419b82
#junk 11897d4903e2
#guard 11648cd68ca3
#ptrhread guard 110bc4dbcbd2
#stack rand 10aa9cc05d07
10a8cdbb6352
#explicit zero 10b28302c668
#brk 109f8be7d07c
#random 10cb91a7ee3a
#undefined 1008279e2fdd
#merge 106a18bd565d
#vla formatting 102f392c2d08
#pthread 108bbce1bc50
#read only 10725f61db82
#zero 104cd257135f
#fork mmap 109220cf622b
#memprot pthread 108ef71d1ffd
#memprot exit 100eaef1abbd
#xor 1064f1cc2148
#junk 105c42a527cf
#guard 105cc8c34e60
#pthread guard 107f61cc8a1c
#stack rand 9abdf523d26
9e4b9b31e6f
#explicit zero 9a3a22a63d2
#brk 97444dbc3cf
#random 9dcd3b72ac9
#undefined 9543e1df342
#merge 9611e5691f7
#vla formatting 98de97ce864
#pthread 9a475717042
#read only 97f0947cc0e
#zero 9e9751d3370
#fork mmap 983cd86d0d5
#memprot pthread 91ebb165455
#memprot exit 9488ba483cf
#xor 9f9351d884b
#junk 985e5bca0a5
#move Signed-off-by: Tad <tad@spotco.us>
60 lines
2.3 KiB
Diff
60 lines
2.3 KiB
Diff
From 49571a0a496539b9af763b8ef30c5b5db57c8be7 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Micay <danielmicay@gmail.com>
|
|
Date: Sat, 1 Oct 2016 05:11:44 -0400
|
|
Subject: [PATCH] make __stack_chk_guard read-only at runtime
|
|
|
|
Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
|
|
---
|
|
libc/bionic/__libc_init_main_thread.cpp | 15 ++++++++++++---
|
|
1 file changed, 12 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp
|
|
index 56a8488888..7c8256cd67 100644
|
|
--- a/libc/bionic/__libc_init_main_thread.cpp
|
|
+++ b/libc/bionic/__libc_init_main_thread.cpp
|
|
@@ -28,6 +28,9 @@
|
|
|
|
#include "libc_init_common.h"
|
|
|
|
+#include <limits.h>
|
|
+#include <sys/mman.h>
|
|
+
|
|
#include <async_safe/log.h>
|
|
|
|
#include "private/KernelArgumentBlock.h"
|
|
@@ -35,17 +38,20 @@
|
|
#include "private/bionic_defs.h"
|
|
#include "private/bionic_elf_tls.h"
|
|
#include "private/bionic_globals.h"
|
|
-#include "private/bionic_ssp.h"
|
|
#include "pthread_internal.h"
|
|
|
|
extern "C" pid_t __getpid();
|
|
extern "C" int __set_tid_address(int* tid_address);
|
|
|
|
// Declared in "private/bionic_ssp.h".
|
|
-uintptr_t __stack_chk_guard = 0;
|
|
+__attribute__((aligned(PAGE_SIZE)))
|
|
+uintptr_t __stack_chk_guard[PAGE_SIZE / sizeof(uintptr_t)] = {0};
|
|
|
|
static pthread_internal_t main_thread;
|
|
|
|
+void __libc_init_global_stack_chk_guard(KernelArgumentBlock& args) {
|
|
+}
|
|
+
|
|
// Setup for the main thread. For dynamic executables, this is called by the
|
|
// linker _before_ libc is mapped in memory. This means that all writes to
|
|
// globals from this function will apply to linker-private copies and will not
|
|
@@ -122,7 +128,10 @@ extern "C" void __libc_init_main_thread_late() {
|
|
// The TLS stack guard is set from the global, so ensure that we've initialized the global
|
|
// before we initialize the TLS. Dynamic executables will initialize their copy of the global
|
|
// stack protector from the one in the main thread's TLS.
|
|
- __libc_safe_arc4random_buf(&__stack_chk_guard, sizeof(__stack_chk_guard));
|
|
+ __libc_safe_arc4random_buf(&__stack_chk_guard[0], sizeof(__stack_chk_guard[0]));
|
|
+ if (mprotect(__stack_chk_guard, sizeof(__stack_chk_guard), PROT_READ) == -1) {
|
|
+ async_safe_fatal("mprotect __stack_chk_guard: %s", strerror(errno));
|
|
+ }
|
|
__init_tcb_stack_guard(__get_bionic_tcb());
|
|
|
|
__init_thread(&main_thread);
|