WSL: ASAN doesn't work

steven@localhost ~
$ cat test2.c
int main(int argc, char **argv)
{
        return 0;
}
steven@localhost ~
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.5-2ubuntu1~14.04.1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1)
steven@localhost ~
$ gcc -fsanitize=address -O0 -ggdb -o test2 test2.c
steven@localhost ~
$ ./test2
==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
    #0 0x7ff5fcc8231d==1910== AddressSanitizer CHECK failed: ../../../../src/libsanitizer/sanitizer_common/sanitizer_linux.cc:403 "((IsOnOf(*current_++, 's', 'p'))) != (0)" (0x0, 0x0)
^C
steven@localhost ~
$

Note that the ASAN printouts would have kept printing if I hadn’t aborted with Ctrl-C.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 30 (2 by maintainers)

Most upvoted comments

must run bash -c " echo 0 > /proc/sys/kernel/yama/ptrace_scope" for this to work under 1803

Setting /proc/sys/kernel/yama/ptrace_scope to 0 works around the issue; I’ve filed #3053.

I would recommend opening a new issue for the PR_SET_PTRACER problem. If you set /proc/sys/kernel/yama/ptrace_scope to 0 does it start working? Looks like it is also mentioned in #2258 but not as a blocker.

Using 17115 and my previous example now works

=================================================================
==4724==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffffb45db52 at pc 0x7f872991c904 bp 0x7ffffb45db20 sp 0x7ffffb45d2c8
WRITE of size 4 at 0x7ffffb45db52 thread T0
    #0 0x7f872991c903 in __asan_memcpy (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x8c903)
    #1 0x40094d in main (/home/sshuser/test+0x40094d)
    #2 0x7f87294e082f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #3 0x4007e8 in _start (/home/sshuser/test+0x4007e8)

Address 0x7ffffb45db52 is located in stack of thread T0 at offset 34 in frame
    #0 0x4008c5 in main (/home/sshuser/test+0x4008c5)

  This frame has 1 object(s):
    [32, 34) 'arr' <== Memory access at offset 34 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow ??:0 __asan_memcpy
Shadow bytes around the buggy address:
  0x10007f683b10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683b20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683b30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683b40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683b50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10007f683b60: 00 00 00 00 00 00 f1 f1 f1 f1[02]f4 f4 f4 f3 f3
  0x10007f683b70: f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683b80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683b90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683ba0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10007f683bb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
==4724==ABORTING

I also tested it with TSAN and MSAN as well as clang and well were fine. It was also fast in all cases without doing any changes to the system.

So I think this can now be closed. This is truly a great achievement.

I changed ASAN to accept Window’s proc maps format. But it is still unusable. ASAN maps 20TB of virtual memory and it kills WSL. It is so slow that asan init code takes hours. Probably the same issue as https://github.com/Microsoft/BashOnWindows/issues/1671