This is an archive of the discontinued LLVM Phabricator instance.

Mmap interceptor providing mprotect support
ClosedPublic

Authored by devnexen on Mar 22 2018, 5:00 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

devnexen created this revision.Mar 22 2018, 5:00 AM
Herald added subscribers: Restricted Project, llvm-commits, kubamracek. · View Herald TranscriptMar 22 2018, 5:00 AM

After that, next step would be trying to fix Android support. sorry for all the work I give you @vitalybuka

devnexen updated this revision to Diff 139432.Mar 22 2018, 6:02 AM
vitalybuka requested changes to this revision.Mar 22 2018, 2:11 PM
vitalybuka added inline comments.
lib/sanitizer_common/sanitizer_common_interceptors.inc
280 ↗(On Diff #139432)

Just put this into INTERCEPTOR
No need to have COMMON_INTERCEPTOR_MPROTECT_IMPL before we have overrides

6925 ↗(On Diff #139432)

Oh, it didn't actually worked.

test/sanitizer_common/TestCases/Linux/mmap_write_exec.cpp
15 ↗(On Diff #139432)

Please extend tests with:

  1. env_tool_opts=detect_write_exec=0 and // CHECK-DISABLED-NOT: writable-executable
  2. correct call to mprotect without warning.
  3. add //CHECK for [[@LINE
  4. Move all correct mprotec and mpap to the end and CHECK-NOT: writable-executable to make sure there is no 3rd report
This revision now requires changes to proceed.Mar 22 2018, 2:11 PM
devnexen updated this revision to Diff 139539.Mar 22 2018, 5:45 PM
devnexen added inline comments.
test/sanitizer_common/TestCases/Linux/mmap_write_exec.cpp
15 ↗(On Diff #139432)

When I set to respectively LINE-3, LINE-2 ... does not work ... any clue eventually ?

vitalybuka added inline comments.Mar 22 2018, 5:48 PM
test/sanitizer_common/TestCases/Linux/mmap_write_exec.cpp
21 ↗(On Diff #139539)

CHECK-DISABLED-NOT: #0 is unnecacary
you still need to keep // CHECK: for reports

15 ↗(On Diff #139432)

you are matching sanitizer_common_interceptors.in file.
you should match mmap_write_exec.cpp:[[@LINE....

devnexen added inline comments.Mar 22 2018, 6:08 PM
test/sanitizer_common/TestCases/Linux/mmap_write_exec.cpp
15 ↗(On Diff #139432)

Oh right I missed this ...

devnexen updated this revision to Diff 139546.Mar 22 2018, 6:14 PM
vitalybuka added inline comments.Mar 22 2018, 11:53 PM
test/sanitizer_common/TestCases/Linux/mmap_write_exec.cpp
15 ↗(On Diff #139546)

For check-not I'd use simple rule, e.g. just "-NOT: Sanitizer"
With complex rule there is a check that it can get always true if we change format.

20 ↗(On Diff #139546)

there is no point in checking "-NOT:" twice here
one above covers everything

devnexen added inline comments.Mar 23 2018, 12:04 AM
test/sanitizer_common/TestCases/Linux/mmap_write_exec.cpp
20 ↗(On Diff #139546)

Oh ok good to know.

devnexen updated this revision to Diff 139561.Mar 23 2018, 12:10 AM
vitalybuka accepted this revision.Mar 23 2018, 1:41 PM
vitalybuka edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Mar 23 2018, 1:41 PM
vitalybuka added inline comments.Mar 23 2018, 1:51 PM
test/sanitizer_common/TestCases/Linux/mmap_write_exec.cpp
2 ↗(On Diff #139561)

"FileCheck %s" was lost

This revision was automatically updated to reflect the committed changes.

Hi, this probably broke on Darwin, https://smooshbase.apple.com/ci/view/BuildCzar/job/apple-clang-master-RA-stage1-cmake-incremental/44333/console:

duplicate symbol _wrap_mprotect in:
    projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.watchossim.dir/asan_interceptors.cc.o
    projects/compiler-rt/lib/asan/CMakeFiles/RTAsan_dynamic.watchossim.dir/asan_malloc_mac.cc.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Can you take a look?

Seems sanitizer_malloc_mac.inc already intercepts mprotect.

Would need to protect the common interception and still catching the flags in the mac part maybe.

vitalybuka reopened this revision.Mar 23 2018, 2:48 PM

reverted r328375

This revision is now accepted and ready to land.Mar 23 2018, 2:48 PM

Thanks. If you don't have a macOS machine, you can email me a patch and I can test it out for you.

devnexen updated this revision to Diff 139659.Mar 23 2018, 3:01 PM

Fix Apple build, as mprotect is already intercepted. We check the flags in apple case too.

Thanks. If you don't have a macOS machine, you can email me a patch and I can test it out for you.

I tested with an weak apple machine I reproduced your linkage issues and do not get them after the changes.

vitalybuka requested changes to this revision.Mar 23 2018, 3:20 PM
vitalybuka added inline comments.
lib/sanitizer_common/sanitizer_malloc_mac.inc
76 ↗(On Diff #139659)

It does not look right.
We have now two conditional interceptors.

I think better approach to instert some mmaloc hook into the common interceptor
and make it empty on all platforms and put "if (addr == malloc_zones && prot == PROT_READ) {" into the mac one.

This revision now requires changes to proceed.Mar 23 2018, 3:20 PM
devnexen added inline comments.Mar 23 2018, 3:27 PM
lib/sanitizer_common/sanitizer_malloc_mac.inc
76 ↗(On Diff #139659)

Sure fair point I tried to avoid too much changes. Will update.

devnexen updated this revision to Diff 139678.Mar 23 2018, 4:50 PM
vitalybuka added inline comments.Mar 23 2018, 4:58 PM
lib/sanitizer_common/sanitizer_malloc_mac.inc
309 ↗(On Diff #139678)

please move this into some cc file. e.g sanitizer_mac.cc

devnexen updated this revision to Diff 139699.Mar 23 2018, 11:04 PM

Refactoring MmapMallocZones

This revision was not accepted when it landed; it landed in state Needs Review.Mar 24 2018, 12:49 AM
This revision was automatically updated to reflect the committed changes.