In addition:
- optionally add global flag to capture compile intent for UAR: __asan_detect_use_after_return_always. The global is a SANITIZER_WEAK_ATTRIBUTE.
Differential D103304
Update and improve compiler-rt tests for -mllvm -asan_use_after_return=(never|[runtime]|always). kda on May 28 2021, 1:56 AM. Authored by
Details
In addition:
Diff Detail
Event Timeline
Comment Actions remove commmented out lines.
Comment Actions Not this time around. I would rather finish this round, then attempt to "lazy allocate". Comment Actions Are you suggesting renaming this flag now or later? Comment Actions
Comment Actions __asan_detect_use_after_return, any variant of it, is not entirely correct. First, using the presence of the global is better than its value, because the linker will pick a random instance in case they disagree, while &(...) != nullptr gives reliable OR semantics. Second, this does not handle dlopen out of the box. It can be almost fixed by calling something from a library constructor (like __asan_init) and passing the address/value of the UAR setting, but even that is not 100% correct as code from a library may run before any of that library's constructors. It will also require late-initialization of fake stack on all existing threads at the time of dlopen. Lazy init would work, but need to make sure that fake stack init is async signal safe, because the first use in a thread may be in a signal context. Another option is to make sure that unused fake stack is cheap, and initialize it always. I don't know if that is the case right now. Having said all this, the implementation in this revision will kind of work in most cases, and the worst consequence of a mistake is some performance loss, so I'm fine with the change as is. Comment Actions Other then comment at asan_rtl.cpp:39 LGTM We discussed this disadvantages with @kda already offline.
Comment Actions @kda This change has broken our internal builds on macOS. I'm not sure why it hasn't broken the public ones. If you add a new weak symbol it needs to be added to lib/asan/weak_symbols.txt so that the linker on macOS knowns it's okay for the symbol to not be defined. We'll put up a patch to fix this shortly. Comment Actions Hi, this seems to not build on macOS, see http://45.33.8.238/macm1/10715/step_4.txt or http://45.33.8.238/mac/32177/summary.html Please take a look and revert for now if it takes a while to fix. Comment Actions Oh, I see that that was already reported over an hour ago. Reverted for now in 5c600dc6d4b75bc71dc3033f37ea187b3fd454d7 Comment Actions @kda Seeing as this patch was reverted it doesn't make sense for me to put up a patch to fix it. If you try to reland this please update lib/asan/weak_symbols.txt as I mentioned in previous comments. Comment Actions FWIW, this patch also broke building for windows. Weak symbols overall is a tricky area on windows, and I don't think this particular usage (the asan lib having a weak undefined symbol, which the executable may or may not proivide) works with windows DLLs at all. Comment Actions @mstorsjo Is there a short-term work around? Comment Actions I'm not well versed in the asan internals to know all the tricks that are used so far, but if this mechanism is a new thing and we've done without it so far and seems hard to do, can we just ifdef it out on windows and keep doing things like they were before there? Comment Actions Looks like this relanded. It still doesn't build on mac: http://45.33.8.238/macm1/10837/step_4.txt Please take a look and revert for now if it takes a while to fix. Comment Actions Yes, it was a problem on my end, all good now. Why is this a weak symbol? Most asan symbols aren't, and it looks like the mac and win troubles are due to you making this a weak symbol. Comment Actions discussion begins: https://reviews.llvm.org/D103304#2794683 Comment Actions I looked at Lazy approach and it's simpler then I thought. Asan already contains all needed pieces. Cloning of GetFakeStackFast -> GetFakeStackFastAlways which does not check __asan_option_detect_stack_use_after_return should be enough. static FakeStack *GetFakeStackFast() { if (FakeStack *fs = GetTLSFakeStack()) return fs; if (!__asan_option_detect_stack_use_after_return) return nullptr; return GetFakeStack(); } static FakeStack *GetFakeStackFastAlways() { if (FakeStack *fs = GetTLSFakeStack()) return fs; return GetFakeStack(); } And same for all callers. Comment Actions Oh, I missed
I'll re-land reverted changes back. Comment Actions Regarding below, I had this previously: https://reviews.llvm.org/differential/changeset/?ref=2601358 The problem I don't know how to navigate is that GetFakeStackFast is only called from one place (at runtime, the other is for testing only). How do I have the runtime code pick the Always version of GetFakeStackFast without examining the global? Comment Actions Correct, at that time I thought we are doing WEAK asan_use_after_return_mode, for which new fictions are not needed.
No, AddressSanitizer.cpp Always branch will call only __asan_stack_malloc_always_<class_id> functions Runtime branch will continue to call __asan_stack_malloc_<class_id> Comment Actions
Comment Actions Thanks. LGTM with some nits.
|
Flawless change should be in a separate patch.
Also this is slow pass, one per thread. I don't think we care about performance of this branch, so I would prefer we avoid extending API where unnecessary.