This is an archive of the discontinued LLVM Phabricator instance.

MSan: introduce the conservative assembly handling mode.
AcceptedPublic

Authored by glider on Mar 29 2018, 8:35 AM.

Details

Summary

The default assembly handling mode may introduce false positives in the cases when MSan doesn't understand that the assembly call initializes the memory pointed to by one of its arguments.
We introduce the conservative mode, which initializes every memory location passed into the assembly statement.

Diff Detail

Event Timeline

glider created this revision.Mar 29 2018, 8:35 AM
glider added inline comments.Mar 29 2018, 8:36 AM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
2734

I didn't touch this comment, as it remains more or less valid.

eugenis accepted this revision.Mar 29 2018, 2:00 PM

This approach can not handle arrays - it would unpoison only the first element. It could be confusing for the user, but not really worse than the current state. Please mention this in the comment and/or the flag description.

I think it's OK to enable this feature by default.

lib/Transforms/Instrumentation/MemorySanitizer.cpp
3080

Move this above visitInstruction.

3110

Origin is meaningless for unpoisoned memory. All this does is potentially destroy origin info for adjacent memory in case of a less than 4 byte store.

This revision is now accepted and ready to land.Mar 29 2018, 2:00 PM
glider marked an inline comment as done.Apr 3 2018, 2:41 AM

I think it's OK to enable this feature by default.

I wouldn't haste with that. First, this approach is not strictly better than the existing one, e.g. it may unpoison the memory that wasn't touched in the assembly.
Second, turning this on may break the clients, so we'd better do that in a separate changelist.

lib/Transforms/Instrumentation/MemorySanitizer.cpp
3110

Ack.

glider marked an inline comment as done.Apr 18 2018, 9:48 AM

FWIW, we couldn't enable this mode in KMSAN by default.
Turned out people are passing all sorts of random pointers into inline assembly in the kernel (sometimes those arguments are unused by the assembly itself), and unpoisoning those just triggers page faults.
Guess it's worth looking into instrumenting the assembly with calls, so that we can check the pointers at runtime.