This is an archive of the discontinued LLVM Phabricator instance.

[ASAN] Make sure we are only processing lifetime markers with offset 0 to alloca
ClosedPublic

Authored by lxfind on Oct 10 2020, 9:15 AM.

Details

Summary

This patch addresses https://bugs.llvm.org/show_bug.cgi?id=47787 (and hence https://bugs.llvm.org/show_bug.cgi?id=47767 as well).
In latter instrumentation code, we always use the beginning of the alloca as the base for instrumentation, ignoring any offset into the alloca.
Because of that, we should only instrument a lifetime marker if it's actually pointing to the beginning of the alloca.

Diff Detail

Event Timeline

lxfind created this revision.Oct 10 2020, 9:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 10 2020, 9:15 AM
lxfind requested review of this revision.Oct 10 2020, 9:15 AM
vitalybuka accepted this revision.Oct 12 2020, 3:16 AM
vitalybuka added inline comments.
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1083

Similar problem is if the size of lifetime is smaller then alloca.
Would you like to handle that case, here or in the another patch?

llvm/test/Instrumentation/AddressSanitizer/alloca-offset-lifetime.ll
1

Would you like to try to use llvm/utils/update_test_checks.py

This revision is now accepted and ready to land.Oct 12 2020, 3:16 AM
lxfind added inline comments.Oct 12 2020, 9:51 AM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1083

Is that a problem though? A lifetime marker should always be accurate, that is, if the marker indicates that only part of the region is alive, it should be ok to just mark that region alive?

lxfind added inline comments.Oct 13 2020, 10:20 AM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1083

I will land this as it is for now. But please do let me know your thoughts on what we want to do when the size doesn't match.

This revision was landed with ongoing or failed builds.Oct 13 2020, 10:22 AM
This revision was automatically updated to reflect the committed changes.
vitalybuka added inline comments.Oct 13 2020, 11:01 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1083

if marker can point with offset, skipping the beginning of the alloca, then I assume sooner or later something may generate code which will set size smaller then alloca, skipping the tail of it.

vitalybuka added inline comments.Oct 13 2020, 11:16 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1089–1091
lxfind added inline comments.Oct 13 2020, 11:18 PM
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
1083

Not sure if I follow, but my point is if the lifetime points to the beginning of the alloca, the generated instrumentation code will always be correct, and hence it's fine even the size may be smaller than the alloca size.