mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-10-01 01:35:54 -04:00
181519cf38
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>
85 lines
2.9 KiB
Diff
85 lines
2.9 KiB
Diff
From 0eaef1abbdcbf40c990fcba1bd91401bdd38a9c5 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Micay <danielmicay@gmail.com>
|
|
Date: Wed, 27 Jan 2016 18:02:15 -0500
|
|
Subject: [PATCH] add XOR mangling mitigation for thread-local dtors
|
|
|
|
---
|
|
libc/bionic/__cxa_thread_atexit_impl.cpp | 8 +++++---
|
|
libc/bionic/libc_init_common.cpp | 2 ++
|
|
libc/private/bionic_globals.h | 1 +
|
|
3 files changed, 8 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/libc/bionic/__cxa_thread_atexit_impl.cpp b/libc/bionic/__cxa_thread_atexit_impl.cpp
|
|
index 99077c101d..74608513ef 100644
|
|
--- a/libc/bionic/__cxa_thread_atexit_impl.cpp
|
|
+++ b/libc/bionic/__cxa_thread_atexit_impl.cpp
|
|
@@ -13,15 +13,17 @@
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
+#include <stdint.h>
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <private/bionic_defs.h>
|
|
+#include <private/bionic_globals.h>
|
|
|
|
#include "pthread_internal.h"
|
|
|
|
class thread_local_dtor {
|
|
public:
|
|
- void (*func) (void *);
|
|
+ uintptr_t func;
|
|
void *arg;
|
|
void *dso_handle; // unused...
|
|
thread_local_dtor* next;
|
|
@@ -35,7 +37,7 @@ __BIONIC_WEAK_FOR_NATIVE_BRIDGE
|
|
int __cxa_thread_atexit_impl(void (*func) (void *), void *arg, void *dso_handle) {
|
|
thread_local_dtor* dtor = new thread_local_dtor();
|
|
|
|
- dtor->func = func;
|
|
+ dtor->func = __libc_globals->dtor_cookie ^ reinterpret_cast<uintptr_t>(func);
|
|
dtor->arg = arg;
|
|
dtor->dso_handle = dso_handle;
|
|
|
|
@@ -54,7 +56,7 @@ extern "C" __LIBC_HIDDEN__ void __cxa_thread_finalize() {
|
|
thread_local_dtor* current = thread->thread_local_dtors;
|
|
thread->thread_local_dtors = current->next;
|
|
|
|
- current->func(current->arg);
|
|
+ (reinterpret_cast<void (*)(void*)>(__libc_globals->dtor_cookie ^ current->func))(current->arg);
|
|
if (__loader_remove_thread_local_dtor != nullptr) {
|
|
__loader_remove_thread_local_dtor(current->dso_handle);
|
|
}
|
|
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
|
|
index b229cda2fd..e928c02f1b 100644
|
|
--- a/libc/bionic/libc_init_common.cpp
|
|
+++ b/libc/bionic/libc_init_common.cpp
|
|
@@ -44,6 +44,7 @@
|
|
#include <async_safe/log.h>
|
|
|
|
#include "private/WriteProtected.h"
|
|
+#include "private/bionic_arc4random.h"
|
|
#include "private/bionic_defs.h"
|
|
#include "private/bionic_globals.h"
|
|
#include "private/bionic_tls.h"
|
|
@@ -65,6 +66,7 @@ void __libc_init_globals() {
|
|
__libc_globals.mutate([](libc_globals* globals) {
|
|
__libc_init_vdso(globals);
|
|
__libc_init_setjmp_cookie(globals);
|
|
+ arc4random_buf(&globals->dtor_cookie, sizeof(globals->dtor_cookie));
|
|
});
|
|
}
|
|
|
|
diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h
|
|
index d73079e33d..4c296037b1 100644
|
|
--- a/libc/private/bionic_globals.h
|
|
+++ b/libc/private/bionic_globals.h
|
|
@@ -43,6 +43,7 @@
|
|
|
|
struct libc_globals {
|
|
vdso_entry vdso[VDSO_END];
|
|
+ long dtor_cookie;
|
|
long setjmp_cookie;
|
|
|
|
// In order to allow a complete switch between dispatch tables without
|