[compiler-rt] r252071 - Asan: utility function to determine first wrongly poisoned byte in
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 4 11:56:03 PST 2015
Author: aizatsky
Date: Wed Nov 4 13:56:03 2015
New Revision: 252071
URL: http://llvm.org/viewvc/llvm-project?rev=252071&view=rev
Log:
Asan: utility function to determine first wrongly poisoned byte in
container.
Differential Revision: http://reviews.llvm.org/D14341
Modified:
compiler-rt/trunk/include/sanitizer/common_interface_defs.h
compiler-rt/trunk/lib/asan/asan_poisoning.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_interface_internal.h
compiler-rt/trunk/test/asan/TestCases/contiguous_container.cc
Modified: compiler-rt/trunk/include/sanitizer/common_interface_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/include/sanitizer/common_interface_defs.h?rev=252071&r1=252070&r2=252071&view=diff
==============================================================================
--- compiler-rt/trunk/include/sanitizer/common_interface_defs.h (original)
+++ compiler-rt/trunk/include/sanitizer/common_interface_defs.h Wed Nov 4 13:56:03 2015
@@ -105,6 +105,12 @@ extern "C" {
int __sanitizer_verify_contiguous_container(const void *beg, const void *mid,
const void *end);
+ // Similar to __sanitizer_verify_contiguous_container but returns the address
+ // of the first improperly poisoned byte otherwise. Returns null if the area
+ // is poisoned properly.
+ const void *__sanitizer_contiguous_container_find_bad_address(
+ const void *beg, const void *mid, const void *end);
+
// Print the stack trace leading to this call. Useful for debugging user code.
void __sanitizer_print_stack_trace();
Modified: compiler-rt/trunk/lib/asan/asan_poisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=252071&r1=252070&r2=252071&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Wed Nov 4 13:56:03 2015
@@ -375,10 +375,10 @@ void __sanitizer_annotate_contiguous_con
}
}
-int __sanitizer_verify_contiguous_container(const void *beg_p,
- const void *mid_p,
- const void *end_p) {
- if (!flags()->detect_container_overflow) return 1;
+const void *__sanitizer_contiguous_container_find_bad_address(
+ const void *beg_p, const void *mid_p, const void *end_p) {
+ if (!flags()->detect_container_overflow)
+ return nullptr;
uptr beg = reinterpret_cast<uptr>(beg_p);
uptr end = reinterpret_cast<uptr>(end_p);
uptr mid = reinterpret_cast<uptr>(mid_p);
@@ -395,17 +395,24 @@ int __sanitizer_verify_contiguous_contai
uptr r3_end = end;
for (uptr i = r1_beg; i < r1_end; i++)
if (AddressIsPoisoned(i))
- return 0;
+ return reinterpret_cast<const void *>(i);
for (uptr i = r2_beg; i < mid; i++)
if (AddressIsPoisoned(i))
- return 0;
+ return reinterpret_cast<const void *>(i);
for (uptr i = mid; i < r2_end; i++)
if (!AddressIsPoisoned(i))
- return 0;
+ return reinterpret_cast<const void *>(i);
for (uptr i = r3_beg; i < r3_end; i++)
if (!AddressIsPoisoned(i))
- return 0;
- return 1;
+ return reinterpret_cast<const void *>(i);
+ return nullptr;
+}
+
+int __sanitizer_verify_contiguous_container(const void *beg_p,
+ const void *mid_p,
+ const void *end_p) {
+ return __sanitizer_contiguous_container_find_bad_address(beg_p, mid_p,
+ end_p) == nullptr;
}
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_interface_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_interface_internal.h?rev=252071&r1=252070&r2=252071&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_interface_internal.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_interface_internal.h Wed Nov 4 13:56:03 2015
@@ -53,6 +53,9 @@ extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE
int __sanitizer_verify_contiguous_container(const void *beg, const void *mid,
const void *end);
-} // extern "C"
+ SANITIZER_INTERFACE_ATTRIBUTE
+ const void *__sanitizer_contiguous_container_find_bad_address(
+ const void *beg, const void *mid, const void *end);
+ } // extern "C"
#endif // SANITIZER_INTERFACE_INTERNAL_H
Modified: compiler-rt/trunk/test/asan/TestCases/contiguous_container.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/contiguous_container.cc?rev=252071&r1=252070&r2=252071&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/contiguous_container.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/contiguous_container.cc Wed Nov 4 13:56:03 2015
@@ -26,10 +26,18 @@ void TestContainer(size_t capacity) {
for (size_t idx = size; idx < capacity; idx++)
assert(__asan_address_is_poisoned(beg + idx));
assert(__sanitizer_verify_contiguous_container(beg, mid, end));
- if (mid != beg)
+ assert(NULL ==
+ __sanitizer_contiguous_container_find_bad_address(beg, mid, end));
+ if (mid != beg) {
assert(!__sanitizer_verify_contiguous_container(beg, mid - 1, end));
- if (mid != end)
+ assert(mid - 1 == __sanitizer_contiguous_container_find_bad_address(
+ beg, mid - 1, end));
+ }
+ if (mid != end) {
assert(!__sanitizer_verify_contiguous_container(beg, mid + 1, end));
+ assert(mid == __sanitizer_contiguous_container_find_bad_address(
+ beg, mid + 1, end));
+ }
}
// Don't forget to unpoison the whole thing before destroing/reallocating.
More information about the llvm-commits
mailing list