This is an archive of the discontinued LLVM Phabricator instance.

tsan: strerror_r interceptor incorrectly handles result pointers to immutable storage
ClosedPublic

Authored by vitalybuka on Nov 23 2016, 12:52 PM.

Details

Summary

This fixes sanitizer issue #696: when the GNU version of strerror_r returns a result pointer that doesn't match the input buffer, that result pointer is in fact a pointer to some immutable storage that is part of the library (namely sys_errlist). TSAN is currently recording a write to this location, which is incorrect.

Event Timeline

toddlipcon retitled this revision from to tsan: strerror_r interceptor incorrectly handles result pointers to immutable storage.
toddlipcon updated this object.
toddlipcon added a reviewer: eugenis.
toddlipcon set the repository for this revision to rL LLVM.

As a drive-by contributor, I didn't really know how to write a test for this. But I verified in my application that this fixes a false positive.

eugenis edited edge metadata.Nov 23 2016, 2:21 PM

For a test, look at test/tsan/race_on_puts.cc
The same template with strerror_r called in two threads should do the trick.

lib/sanitizer_common/sanitizer_common_interceptors.inc
3230

else COMMON_INTERCEPTOR_INITIALIZE_RANGE ( same args )
This would count as an initializing write for MSan, but not for TSan.

test comment (the previous one went to the spam folder in gmail)

I have some other high priority work for the next couple weeks, so may be a while before I can get back to this patch and add a test. If someone else is interested in carrying it over the finish line in the meantime, please feel free, otherwise I'm likely to pick it up in mid December or January.

vitalybuka commandeered this revision.Jun 6 2017, 5:56 PM
vitalybuka added a reviewer: toddlipcon.
vitalybuka updated this revision to Diff 101653.Jun 6 2017, 5:58 PM

Add tests.

vitalybuka updated this revision to Diff 101655.Jun 6 2017, 5:59 PM

Clang-format

vitalybuka marked an inline comment as done.Jun 6 2017, 6:00 PM
eugenis added inline comments.Jun 6 2017, 6:30 PM
test/msan/Linux/strerror_r.c
15

I'd remove these pointer checks, they rely on libc implementation details.

test/tsan/strerror_r.cc
19

Is the barrier really needed?
Again, I'd remove the assert at line 20.

vitalybuka updated this revision to Diff 101660.Jun 6 2017, 6:37 PM

Remove barrier and pointers checks

vitalybuka marked 2 inline comments as done.Jun 6 2017, 6:37 PM
eugenis accepted this revision.Jun 6 2017, 6:42 PM

LGTM

This revision is now accepted and ready to land.Jun 6 2017, 6:42 PM
vitalybuka updated this revision to Diff 101661.Jun 6 2017, 6:45 PM

Remove "UNSUPPORTED: android" and _GNU_SOURCE

vitalybuka closed this revision.Jun 7 2017, 10:57 AM

Somehow I missed review URL in my patch description, so closing manually.
https://llvm.org/svn/llvm-project/compiler-rt/trunk@304858