Search code examples
c++address-sanitizergrpc-c++

Triggering ASan using an example from the grpc library


I started studying the grpc library from here https://grpc.io/docs/languages/cpp/quickstart/. I compiled the library on my Linux computer, following exactly all the steps indicated. I then compiled a tutorial from examples/cpp/helloworld/ and ran greeter_server and then greeter_client. Everything worked perfectly!

Next, I put together the same example, telling the compiler to use the address sanitizer. After that I started the server - it started normally. Then I launched the client and at this time, both on the client side and on the server side, I saw many messages from address sanitizer with the title

==2563==ERROR: AddressSanitizer: use-after-poison on address ...

I doubt that the library or examples from grpc have memory problems. But then why does ASan work? What I did wrong?


Solution

  • First of all here is some background. Poisoning is a special technique which allows application code to inform Asan that some memory region should be treated as inaccessible (until it's unpoisoned). Some parts of grpc use poisoning to enable Asan to detect more errors (grep case-insensitively for asan_poison to locate them).

    Poisoning errors are unfortunately hard to diagnose but here is my understanding of what's going on.

    You compiled grpc itself without Asan support and tests with it. So all asan_unpoison calls inside grpc effectively became no-ops but asan_poison calls in headers included by the test were enabled. So some poisons were not paired by corresponding unpoisons which caused the false positives that you see.

    As a solution you should recompile grpc with Asan enabled.