make tls slots accessible via teb

This commit is contained in:
Tavis Ormandy
2019-06-19 14:02:27 -07:00
parent 2f1ac6b3a2
commit bcef398300
3 changed files with 28 additions and 9 deletions
+11 -8
View File
@@ -622,16 +622,19 @@ error:
return false;
}
uintptr_t LocalStorage[1024] = {0};
bool setup_nt_threadinfo(PEXCEPTION_HANDLER ExceptionHandler)
{
static EXCEPTION_FRAME ExceptionFrame;
static NT_TIB ThreadInfo = {
.Self = &ThreadInfo,
static TEB ThreadEnvironment = {
.Tib.Self = &ThreadEnvironment.Tib,
.ThreadLocalStoragePointer = LocalStorage, // https://github.com/taviso/loadlibrary/issues/65
};
struct user_desc pebdescriptor = {
.entry_number = -1,
.base_addr = (uintptr_t) &ThreadInfo,
.limit = sizeof ThreadInfo,
.base_addr = (uintptr_t) &ThreadEnvironment,
.limit = sizeof ThreadEnvironment,
.seg_32bit = 1,
.contents = 0,
.read_exec_only = 0,
@@ -641,12 +644,12 @@ bool setup_nt_threadinfo(PEXCEPTION_HANDLER ExceptionHandler)
};
if (ExceptionHandler) {
if (ThreadInfo.ExceptionList) {
if (ThreadEnvironment.Tib.ExceptionList) {
DebugLog("Resetting ThreadInfo.ExceptionList");
}
ExceptionFrame.handler = ExceptionHandler;
ExceptionFrame.prev = NULL;
ThreadInfo.ExceptionList = &ExceptionFrame;
ExceptionFrame.handler = ExceptionHandler;
ExceptionFrame.prev = NULL;
ThreadEnvironment.Tib.ExceptionList = &ExceptionFrame;
}
if (syscall(__NR_set_thread_area, &pebdescriptor) != 0) {
+16
View File
@@ -981,6 +981,22 @@ typedef struct _NT_TIB {
PVOID Self;
} NT_TIB, *PNT_TIB;
typedef struct _CLIENT_ID {
HANDLE UniqueProcess;
HANDLE UniqueThread;
} CLIENT_ID;
typedef struct _TEB {
NT_TIB Tib;
PVOID EnvironmentPointer;
CLIENT_ID Cid;
PVOID ActiveRpcInfo;
PVOID ThreadLocalStoragePointer;
// The fields below this are deliberately omitted so that access causes a
// crash (because of the segment limit). This lets me know I have to fix
// it, otherwise the error is very difficult to track down.
} TEB, *PTEB;
struct user_desc {
unsigned int entry_number;
unsigned long base_addr;
+1 -1
View File
@@ -17,7 +17,7 @@
#endif
static int TlsIndex;
uintptr_t LocalStorage[1024];
extern uintptr_t LocalStorage[1024];
STATIC DWORD WINAPI TlsAlloc(void)
{