This is an archive of the discontinued LLVM Phabricator instance.

[esan] Add handling of large stack size rlimits
ClosedPublic

Authored by bruening on May 27 2016, 12:36 PM.

Details

Summary

Adds detection of large stack size rlimits (over 1 TB or unlimited), which
results in an mmap location that our shadow mapping does not support. We
re-exec the application in this situation. Adds a test of this behavior.

Adds general detection of mmap regions outside of our app regions. In the
future we want to try to adaptively handle these but for now we abort.

Moves the existing Linux-specific mmap code into a platform-specific file
where the new rlimit code lives.

Diff Detail

Repository
rL LLVM

Event Timeline

bruening updated this revision to Diff 58825.May 27 2016, 12:36 PM
bruening retitled this revision from to [esan] Add handling of large stack size rlimits.
bruening updated this object.
bruening added a reviewer: eugenis.
bruening added subscribers: llvm-commits, aizatsky, kcc and 2 others.
eugenis added inline comments.May 27 2016, 1:07 PM
lib/esan/CMakeLists.txt
21 ↗(On Diff #58825)

You append esan_linux.cpp to the list, but it's already in it.
Also, we usually do it in the source like this:
#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_LINUX

lib/esan/esan_linux.cpp
47 ↗(On Diff #58825)

MSan handles this by mprotect-ing all regions that don't have a shadow mapping, and then the kernel takes care of the rest. Is it hard to do here because of the variable shadow scale?

lib/esan/esan_shadow.h
44 ↗(On Diff #58825)

typo: Linux

bruening added inline comments.May 27 2016, 1:18 PM
lib/esan/CMakeLists.txt
21 ↗(On Diff #58825)

This is cmake, though. This is following how tsan adds tsan_platform_linux.cc (well tsan doesn't leave the file in the main list too ;)). Is there a cmake variable set in a parent file distinguishing Linux from BSD?

lib/esan/esan_linux.cpp
47 ↗(On Diff #58825)

I don't see how that stops a MAP_FIXED mmap?

bruening added inline comments.May 27 2016, 1:21 PM
lib/esan/CMakeLists.txt
21 ↗(On Diff #58825)

Or are you suggesting to not say "assume linux" here, and have the source file say "#if SANITIZER_LINUX" if it really won't work on BSD (should prob be _posix if it works on BSD)?

eugenis added inline comments.May 27 2016, 1:26 PM
lib/esan/CMakeLists.txt
21 ↗(On Diff #58825)

Hm, I don't see why this cmake change would be necessary if the C++ source had the proper guards. The TSan thing could be legacy.

lib/esan/esan_linux.cpp
47 ↗(On Diff #58825)

Right, it does not. Actually, MSan does not check this condition well enough - it used to have a simple mapping where if was sufficient to only check the start address, but now it can let through an invalid mmap...

eugenis added inline comments.May 27 2016, 1:28 PM
lib/esan/CMakeLists.txt
21 ↗(On Diff #58825)

I'm saying that you should not need this cmake logic at all.

Regarding BSD code, I think it is generally in *_linux files, because they are so similar.

bruening updated this revision to Diff 58832.May 27 2016, 1:42 PM
bruening marked 4 inline comments as done.

Switch to using guards on the platform-specific file.

eugenis accepted this revision.May 27 2016, 1:43 PM
eugenis edited edge metadata.

LGTM

This revision is now accepted and ready to land.May 27 2016, 1:43 PM
This revision was automatically updated to reflect the committed changes.