Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AddressSanitizer Suppression

I am trying to suppress a warning from the address sanitizer in clang/gcc

My source file looks like this:

int foo(){
  double bar[] = {7,8};
  return bar[3];
}

int main(){
  return foo();
}

and obviously there is an overflow at line 3.

the suppression file (myasan.supp) contains:

interceptor_via_fun:foo

compiling (clang also creates a warning) and running:

clang -O0 -g -fsanitize=address -fno-omit-frame-pointer sanitizerTest.c
ASAN_SYMBOLIZER_PATH=/software/clang/7.0.0/bin/llvm-symbolizer  ASAN_OPTIONS=suppressions=myasan.supp ./a.out

but the address sanitizer still complains about the overflow.

==8119==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffeab4e75f8 at pc 0x0000004008bf bp 0x7ffeab4e75b0 sp 0x7ffeab4e75a8
READ of size 8 at 0x7ffeab4e75f8 thread T0
#0 0x4008be in foo() /tmp/asan/sanitizerTest.c:3
#1 0x400919 in main /tmp/asan/sanitizerTest.c:7
#2 0x7f549fbfb82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
#3 0x400718 in _start (/tmp/asan/a.out+0x400718)

Compiler is clang7. I tested clang6, gcc7 as well.

Any idea how to make this work?

like image 674
user1928546 Avatar asked Oct 02 '18 08:10

user1928546


People also ask

What is AddressSanitizer error?

AddressSanitizer is a fast memory error detector. It consists of a compiler instrumentation module and a run-time library. The tool can detect the following types of bugs: Out-of-bounds accesses to heap, stack and globals.

How do I turn off AddressSanitizer?

Stack Use After Return (UAR) AddressSanitizer can optionally detect stack use after return problems. This is available by default, or explicitly ( -fsanitize-address-use-after-return=runtime ). To disable this check at runtime, set the environment variable ASAN_OPTIONS=detect_stack_use_after_return=0 .

What is C++ AddressSanitizer?

Starting in Visual Studio 2019 version 16.9, the Microsoft C/C++ compiler (MSVC) and IDE supports the AddressSanitizer. AddressSanitizer (ASan) is a compiler and runtime technology that exposes many hard-to-find bugs with zero false positives: Alloc/dealloc mismatches and new / delete type mismatches.

How does AddressSanitizer work?

AddressSanitizer dedicates one-eighth of the virtual address space to its shadow memory and uses a direct mapping with a scale and offset to translate an applica- tion address to its corresponding shadow address. Given the application memory address Addr, the address of the shadow byte is computed as (Addr>>3)+Offset.


1 Answers

Quote from the ASan documentation:

This suppression mechanism should only be used for suppressing issues in external code; it does not work on code recompiled with AddressSanitizer.

Offhand, I think it only works across shared object boundaries.

To suppress: in your own code add __attribute__((no_sanitize("address"))) to the function declaration or use a compile-time blacklist:

$ cat myasan.blacklist
fun:foo
$ clang -fsanitize=address -fsanitize-blacklist=myasan.blacklist -w sanitizerTest.c
$ ./a.out
$ 
like image 127
Nick Lewycky Avatar answered Oct 02 '22 23:10

Nick Lewycky