This is an archive of the discontinued LLVM Phabricator instance.

[sanitizers][windows] Global/LocalAlloc interception and tests
AbandonedPublic

Authored by mcgov on Dec 30 2019, 12:26 PM.

Details

Summary

GlobalAlloc and LocalAlloc are windows allocators that are frequently used in some older code bases. This adds interception and tests for those allocators with similar restrictions to the HeapAlloc and RtlHeapAllocate interceptors: moveable memory is not yet supported.

patch by Brijesh Rakholiya <Brijesh.Rakholia@microsoft.com> and Ian Kronquist <Ian.Kronquist@microsoft.com>

Diff Detail

Event Timeline

mcgov created this revision.Dec 30 2019, 12:26 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 30 2019, 12:26 PM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
mcgov edited the summary of this revision. (Show Details)Dec 30 2019, 12:28 PM
mcgov updated this revision to Diff 235635.Dec 30 2019, 12:44 PM

clang formatted the patch

mstorsjo added inline comments.Dec 30 2019, 12:44 PM
compiler-rt/lib/asan/asan_malloc_win.cc
22

Removing <stddef.h> here breaks building with mingw, as it's necessary for the size_t type.

If I readd it here, it builds fine for me, but I presume it's removed for a reason?

FWIW, do note that this file is named .cpp in the latest git master; it looks like this diff has been made against an older tree?

Also, it's useful if the uploaded diffs are made with extra context (diff -U999)

mcgov edited the summary of this revision. (Show Details)Dec 30 2019, 12:49 PM
mcgov planned changes to this revision.Dec 30 2019, 12:51 PM
mcgov marked an inline comment as done.

Planning to rebase this patch on master instead of release/9.x

compiler-rt/lib/asan/asan_malloc_win.cc
22

Ah yes this was against release/9.x but I will recreate it against master.

mcgov updated this revision to Diff 235662.Dec 30 2019, 4:53 PM

rebased to master

Builds fine in my MinGW configuration now, thanks!

compiler-rt/lib/asan/asan_malloc_win.cpp
407 ↗(On Diff #235662)

I'm getting conflicts here when I try to apply the patch locally on master, not sure what that stems from...

rnk added inline comments.Jan 3 2020, 4:11 PM
compiler-rt/lib/asan/asan_malloc_win.cpp
57 ↗(On Diff #235662)

I guess I prefer the spelling __declspec, since it's in the implementer's namespace.

95 ↗(On Diff #235662)

Most of the changes in this file are from clang-format. I don't mind a few, but this is too many. Can you revert the non-functional whitespace changes far from the code you are editing? You can use git checkout -p to speed this up.

I also encourage you to run run check-sanitizer on Linux. The ASan codebase has its own linter script that doesn't run on Windows, and sometimes disagrees with clang-format.

compiler-rt/lib/interception/interception_win.cpp
524 ↗(On Diff #235662)

So far this seems like the only functional change in this file.

compiler-rt/test/asan/TestCases/Windows/globalalloc_flags_fallback.cpp
4 ↗(On Diff #235662)

What is the main blocker for making these tests work for 64-bit? Fixing the hotpatching interceptors?

Chromium stopped using 32-bit ASan because the address space limitations were prohibitive. I think the sanitizer-windows bot only builds x64 these days, so if we can port these, that would help make sure they are covered.

mcgov abandoned this revision.Jan 8 2020, 9:33 AM
mcgov marked an inline comment as done.
mcgov added a subscriber: iakronqu.
mcgov added inline comments.
compiler-rt/lib/asan/asan_malloc_win.cpp
95 ↗(On Diff #235662)

I can do all this when I reactivate the review. I'm going to abandon this one for now and return to the Global/Local Alloc work after a few other changes are submitted.

We have a set of patches that will fix
a) the cmake issues causing both the asan and asan_dynamic libs to be built with MT.
b) Interceptor issues preventing us from supporting _DEBUG runtimes
c) remove dependence on HeapValidate for control-flow in these interceptors since it throws debug breakpoints under a debugger when the result is false (and that function also throws assertions with M[TD]d).

After some discussion with @iakronqu I'm going to pull this review for now and add these interceptors back until after these other patches are submitted.