This is an archive of the discontinued LLVM Phabricator instance.

LLVM Detailed IR tests for introduction of flag -fsanitize-address-detect-stack-use-after-return-mode.
ClosedPublic

Authored by kda on May 13 2021, 9:43 PM.

Details

Summary

Rework all tests that interact with use after return to correctly handle the case where the mode has been explicitly set to Never or Always.

for issue: https://github.com/google/sanitizers/issues/1394

Diff Detail

Event Timeline

kda created this revision.May 13 2021, 9:43 PM
kda requested review of this revision.May 13 2021, 9:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2021, 9:43 PM
vitalybuka added inline comments.May 13 2021, 11:24 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
260–282

we are going to have two conflicting flags.
Could you please just change this bool flag into Enum, probably without renaming?

static cl::opt<AsanDetectStackUseAfterReturnMode> ClUseAfterReturn("asan-use-after-return"...
0,1 should match current behavior

kda updated this revision to Diff 346805.May 20 2021, 11:27 AM
kda marked an inline comment as done.

Rework to update existing asan-use-after-return boolean to modal flag.

kda added inline comments.May 20 2021, 11:29 AM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
266–268

I added this one and the one below ('1') to avoid updating tests.
Should I just update the tests and remove these?

vitalybuka added inline comments.May 20 2021, 1:14 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
260–282

0,1 is fine
we can remove them later in a separate patch.

266–268

then maybe '2' as well?

271

it should be ASAN_OPTIONS=detect_stack_use_after_return=1

3334–3376

this comment applies to inside of the "then" branch only

Please insert corresponsing spseudo code for else branch:
void *FakeStack = __asan_stack_malloc_N(LocalStackSize);
void *LocalStackBase = (FakeStack) ? FakeStack : alloca(LocalStackSize);

3395–3407

we porbably need entire thing in the else branch
AsanStackMallocFunc[StackMallocIdx] may return NULL in runtime
so we need NoFakeStack branch as well

This is future oportunity to improve: make compiler-rt never return NULL so we can remove CreateICmpEQ and one branch

3409

do you want to uncomment and keep it?

3417

FakeStack is LLVM object which represent result of the function call
(FakeStack) is never NULL, however in runtime it can contain NULL, so we need to compile IRB.CreateICmpEQ(FakeStack, Constant::getNullValue(IntptrTy)); like above

llvm/test/Instrumentation/AddressSanitizer/stack-poisoning.ll
22

this statements checks that there is no this line in after previous check
more reliable is to add --implicit-check-not=asan_option_detect_stack_use_after_return into FileCheck arg to make sure it's not there at all

22

It would be nice to check for CreateICmpEQ
But probably D102867 is enough

llvm/test/Instrumentation/AddressSanitizer/stack_dynamic_alloca.ll
31

same

kda updated this revision to Diff 347490.May 24 2021, 1:39 PM
kda marked 8 inline comments as done.

fixes for correct code.

kda updated this revision to Diff 347491.May 24 2021, 1:42 PM

removed commented out code.

kda added inline comments.May 24 2021, 1:45 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
3409

No. I only meant it as a comment for clarity.

llvm/test/Instrumentation/AddressSanitizer/stack-poisoning.ll
22

ack.

This revision is now accepted and ready to land.May 25 2021, 3:56 PM