Skip to content

Reland "[sanitizer] Add CHECKs to validate calculated TLS range" #108122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler-rt/lib/msan/msan_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
}
UnpoisonParam(2);
RunMallocHooks(allocated, size);
Printf("%p %zu\n", allocated, size);
return allocated;
}

Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res,
// This may happen inside the DTOR of main thread, so just ignore it.
tls_size = 0;
}
if (tls_size) {
CHECK_LE(tls_beg, reinterpret_cast<uptr>(res));
CHECK_LT(reinterpret_cast<uptr>(res), tls_beg + tls_size);
}
dtv->beg = tls_beg;
dtv->size = tls_size;
return dtv;
Expand Down
5 changes: 3 additions & 2 deletions compiler-rt/test/asan/TestCases/Linux/stress_dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// RUN: %clangxx_asan -x c -DSO_NAME=f1 %s -shared -o %t-f1.so -fPIC
// RUN: %clangxx_asan -x c -DSO_NAME=f2 %s -shared -o %t-f2.so -fPIC
// RUN: %clangxx_asan %s -ldl -pthread -o %t
// RUN: %run %t 0 3
// RUN: %run %t 2 3
// RUN: %env_asan_opts=verbosity=2 %run not %t 0 3
// RUN: %env_asan_opts=verbosity=2 %run %t 2 3
// RUN: %env_asan_opts=verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_asan_opts=verbosity=2:intercept_tls_get_addr=1 %run %t 10 2 2>&1 | FileCheck %s
// RUN: %env_asan_opts=verbosity=2:intercept_tls_get_addr=0 %run %t 10 2 2>&1 | FileCheck %s --check-prefix=CHECK0
Expand All @@ -29,6 +29,7 @@
// CHECK-NOT: num_live_dtls 5
//
// CHECK0-NOT: __tls_get_addr

/*
cc=your-compiler

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %clangxx -O0 -g %s -o %t && %run %t
// RUN: %clangxx -O0 -g %s -o %t && %run %env_tool_opts=verbosity=2 %t

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <grp.h>

Expand Down
Loading