This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Intercept mcheck and mprobe on Linux
ClosedPublic

Authored by m.ostapenko on Apr 27 2017, 5:03 AM.

Details

Summary

This patch addresses https://github.com/google/sanitizers/issues/804. Users can use mcheck and mprobe functions to verify heap state so we should intercept them to avoid breakage of valid code.

Diff Detail

Repository
rL LLVM

Event Timeline

m.ostapenko created this revision.Apr 27 2017, 5:03 AM
ygribov added inline comments.Apr 27 2017, 5:37 AM
lib/lsan/lsan_interceptors.cc
197 ↗(On Diff #96900)

We don't seem to use enum at all (except for "return MCHECK_OK" which can be replaced with "return 0").

m.ostapenko added inline comments.Apr 27 2017, 5:44 AM
lib/lsan/lsan_interceptors.cc
197 ↗(On Diff #96900)

Ok, if you think that it would be cleaner to just use 0 here I don't mind.

Remove enum.

alekseyshl edited edge metadata.Apr 27 2017, 11:10 AM

What about mcheck_pedantic and mcheck_check_all?

What about mcheck_pedantic and mcheck_check_all?

Right, we need mcheck_pedantic as well. I'm not sure about mcheck_check_all since it checks all chunks allocated by Glibc and this is probably fine. Should we add it for consistency?

Add mcheck_pedantic.

From man, "The mcheck_pedantic() and mcheck_check_all() functions are available since glibc 2.2. The mcheck() and mprobe() functions are present since at least glibc 2.0". What about systems < 2.0? I guess, __GLIBC_PREREQ is required here.

eugenis added inline comments.Apr 27 2017, 1:48 PM
lib/sanitizer_common/sanitizer_common_interceptors.inc
6157 ↗(On Diff #96958)

I think INIT_MCHECK_MPROBE is simply unnecessary if we don't use REAL(mcheck). Compare with asan_malloc_linux.cc.

And we don't need to care about glibc version then.

Remove INIT_MCHECK_MPROBE.

alekseyshl added inline comments.May 1 2017, 8:30 AM
lib/sanitizer_common/sanitizer_common_interceptors.inc
6157 ↗(On Diff #96958)

Here, yes, but the test still need the version check for check_pedantic, right? We had this problem with getauxval, there're bots running on glibc 2.13.

eugenis added inline comments.May 1 2017, 2:00 PM
lib/sanitizer_common/sanitizer_common_interceptors.inc
6157 ↗(On Diff #96958)

Yes.

Add guards against old Glibc versions to testcase.

eugenis accepted this revision.May 2 2017, 2:24 PM

LGTM

This revision is now accepted and ready to land.May 2 2017, 2:24 PM
This revision was automatically updated to reflect the committed changes.