This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt][asan] Make wild-pointer crash error more useful
ClosedPublic

Authored by oontvoo on Mar 9 2021, 11:56 AM.

Details

Summary

Right now, when you have an invalid memory address, asan would just crash and does not offer much useful info.
This patch attempted to give a bit more detail on the access.

Diff Detail

Event Timeline

oontvoo created this revision.Mar 9 2021, 11:56 AM
oontvoo requested review of this revision.Mar 9 2021, 11:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2021, 11:56 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
vitalybuka added a subscriber: vitalybuka.
vitalybuka added inline comments.
compiler-rt/lib/asan/asan_descriptions.cpp
473

I guess this math is confusing and applies only to
__asan_region_is_poisoned
if (!AddrIsInMem(end)) return end;

Even __asan_region_is_poisoned can return a different offset from the range, not sure what is going to happen with other callers.

e.g. if we change change the test to
memmove(dest + 0x4567890123456789, p + 0x4567890123456789, 0x4567890123456789);
Address 0x4567e92123456799 is a wild pointer - originating from address 0x602000000010, offset = 0x4567890123456789
which is not true any more

We can't get access begin from this addr/size in general.
I propose just to print only bad address and access size to avoid confusion.

oontvoo marked an inline comment as done.Mar 11 2021, 9:16 AM
oontvoo added inline comments.
compiler-rt/lib/asan/asan_descriptions.cpp
473

Good point. Thanks!

oontvoo updated this revision to Diff 329987.Mar 11 2021, 9:16 AM
oontvoo marked an inline comment as done.

updated diff

vitalybuka added inline comments.Mar 11 2021, 11:40 AM
compiler-rt/lib/asan/asan_descriptions.cpp
470–472

maybe

oontvoo added inline comments.Mar 11 2021, 12:36 PM
compiler-rt/test/asan/TestCases/wild_pointer.cpp
11

@vitalybuka : btw, do you know why this inclusion doesn't work here? (ie., if I uncomment it, it'd cause "file not found" error)
Am I missing something obvious? Other tests (eg., lsan/TestCases/use_registers.cpp) use this helper just fine.

vitalybuka added inline comments.Mar 11 2021, 1:21 PM
compiler-rt/test/asan/TestCases/wild_pointer.cpp
11

lsan probably somehow adds include dir
but I don't see why we need it here? (and in lsan as well)

Why not just printf("Expected bad addr: %p", p+offset)

oontvoo updated this revision to Diff 330111.Mar 11 2021, 5:17 PM
oontvoo marked an inline comment as done.

updated diff

vitalybuka accepted this revision.Mar 11 2021, 6:11 PM
vitalybuka added inline comments.
compiler-rt/test/asan/TestCases/wild_pointer.cpp
2–4

-m64 is not enough it tests are being executed on 32bit platform

This revision is now accepted and ready to land.Mar 11 2021, 6:11 PM
oontvoo updated this revision to Diff 330124.Mar 11 2021, 6:48 PM
oontvoo marked an inline comment as done.

updated diff

compiler-rt/test/asan/TestCases/wild_pointer.cpp
2–4

Cool! I didn't know asan-64-bits was a thing!

This revision was landed with ongoing or failed builds.Mar 11 2021, 6:49 PM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Mar 11 2021, 7:00 PM

This makes clang crash when building the adam runtime O_o: http://45.33.8.238/linux/41534/step_4.txt

That's a clang bug, but it als

o breaks the build. So I'm afraid you'll have to revert this until that clang crash is fixed :/

o breaks the build. So I'm afraid you'll have to revert this until that clang crash is fixed :/

Thanks. I've reverted it. Will wait and reland later

oontvoo reopened this revision.Mar 11 2021, 7:15 PM
This revision is now accepted and ready to land.Mar 11 2021, 7:15 PM

Broke the test on Windows: https://lab.llvm.org/buildbot/#/builders/127/builds/7495

C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\test\asan\TestCases\wild_pointer.cpp:20:11: error: CHECK: expected string not found in input
// CHECK: Expected bad addr: [[ADDR:0x[0-9,a-f]+]]
          ^
<stdin>:1:1: note: scanning from here
Expected bad addr: 4567998FA7CF6839

I guess Windows has a different printf format.

Please fix.

Broke the test on Windows: https://lab.llvm.org/buildbot/#/builders/127/builds/7495

C:\b\slave\sanitizer-windows\llvm-project\compiler-rt\test\asan\TestCases\wild_pointer.cpp:20:11: error: CHECK: expected string not found in input
// CHECK: Expected bad addr: [[ADDR:0x[0-9,a-f]+]]
          ^
<stdin>:1:1: note: scanning from here
Expected bad addr: 4567998FA7CF6839

I guess Windows has a different printf format.

Please fix.

I've sent https://reviews.llvm.org/D98570

(Dont have a windows to test it, but I *think* it should work. PTAL Thanks!)