0

我正在运行基于 Linux x86_64 构建的 clang 4.0.0 asan。我使用 clang++ -fsanitize=address 构建了我的代码。

我无法抑制 asan 在我的代码之外报告的以下内存问题:(我已经删节了堆栈跟踪并修改了一些文件路径)

==104630==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200019367c at pc 0x2aaaaadc0d85 bp 0x7fffffff7e90 sp 0x7fffffff7640
READ of size 16 at 0x60200019367c thread T0
#0 0x2aaaaadc0d84 in __asan_memcpy /path/to/llvm-4.0.0.src/projects/compiler-rt/lib/asan/asan_interceptors.cc:453
#1 0x5b74a8 in _ZNSt3__116allocator_traitsINS_9allocatorIiEEE20__construct_backwardIiEENS_9enable_ifIXaaoosr7is_sameIS2_NS1_IT_EEEE5valuentsr15__has_constructIS2_PS6_S6_EE5valuesr31is_trivially_move_constructibleIS6_EE5valueEvE4typeERS2_S8_S8_RS8_ /path/to/clang/clang-4.0.0/rawbin/../include/c++/v1/memory:1676:17
#2 0x5b74a8 in std::__1::vector<int, std::__1::allocator<int> >::__swap_out_circular_buffer(std::__1::__split_buffer<int, std::__1::allocator<int>&>&) /path/to/clang/clang-4.0.0/rawbin/../include/c++/v1/vector:886
#3 0x5b648a in void std::__1::vector<int, std::__1::allocator<int> >::__push_back_slow_path<int const&>(int const&) /path/to/clang/clang-4.0.0/rawbin/../include/c++/v1/vector:1574:5
#4 0x1d8d2ba in std::__1::vector<int, std::__1::allocator<int> >::push_back(int const&) /path/to/clang/clang-4.0.0/rawbin/../include/c++/v1/vector:1591:9
#5 0x1d8d2ba in bar::baz(a_type const*, int const*, std::__1::vector<int, std::__1::allocator<int> >&) /path/to/installed/3rd/party/library/that/i/did/not/build/foo.cc:394

我按照此处的说明进行操作,并且通过在其中输入乱码并看到打印到我的终端上的“AddressSanitizer:无法解析抑制”来验证我的 .supp 正在被读取。我在 compiler-rt-4.0.0.src/lib/asan/asan_interceptors.cc 中查看了 __asan_memcpy 的 src

452 void *__asan_memcpy(void *to, const void *from, uptr size) {
453   ASAN_MEMCPY_IMPL(nullptr, to, from, size);
454 }

我认为“nullptr”是我的问题。我按照宏轨迹找到了这些行

 68       AsanInterceptorContext *_ctx = (AsanInterceptorContext *)ctx;     \
 69       bool suppressed = false;                                          \
 70       if (_ctx) {                                                       \
 71         suppressed = IsInterceptorSuppressed(_ctx->interceptor_name);   \
 72         if (!suppressed && HaveStackTraceBasedSuppressions()) {         \
 73           GET_STACK_TRACE_FATAL_HERE;                                   \
 74           suppressed = IsStackTraceSuppressed(&stack);                  \
 75         }                                                               \
 76       }                                                                 \
 77       if (!suppressed) {                                                \
 78         GET_CURRENT_PC_BP_SP;                                           \
 79         ReportGenericError(pc, bp, sp, __bad, isWrite, __size, 0, false);\
 80       } 

由于 ctx 始终为“nullptr”,因此“if (_ctx)”的计算结果始终为 false,这意味着我将无法抑制我的内存错误。这是设计的,还是错误的?

快速浏览一下我今天拉下来的最新的 compiler-rt src (git hash 286b899df64bb82a2da253114653adaf15da2fce, git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@323510 91177308-0d34 -0410-b5e6-96231b3b80d8) 显示最新的 asan 实现存在相同的情况,所以我认为更新到最新的 asan rtl 不会有帮助。

4

0 回答 0