This is an archive of the discontinued LLVM Phabricator instance.

[MSan] Tweak CopyOrigin
ClosedPublic

Authored by stephan.yichao.zhao on Jan 12 2021, 1:58 PM.

Details

Summary
There could be some mis-alignments when copying origins not aligned.

I believe unaligned memcpy is rare so the cases do not matter too much
in practice.

1) About the change at line 50

Let dst be (void*)5,
then d=5, beg=4
so we need to write 3 (4+4-5) bytes from 5 to 7.

2) About the change around line 77.

Let dst be (void*)5,
because of lines 50-55, the bytes from 5-7 were already writen.
So the aligned copy is from 8.

Diff Detail

Event Timeline

stephan.yichao.zhao requested review of this revision.Jan 12 2021, 1:58 PM
stephan.yichao.zhao created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2021, 1:58 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
stephan.yichao.zhao edited the summary of this revision. (Show Details)
eugenis accepted this revision.Jan 12 2021, 2:36 PM

Hmm this code is a lot more approximate than I remember. The case where src % 4 != dst % 4 is quite broken, but you are right that it is not very common, and also ambiguous - when two poisoned 4-byte chunks with different origins contribute to the same 4-byte chunk in the output, the result can not be represented.

Your change makes it better, so LGTM but please check formatting.

compiler-rt/lib/msan/msan_poisoning.cpp
94

did this go through clang-format? formatting looks strange.

This revision is now accepted and ready to land.Jan 12 2021, 2:36 PM
stephan.yichao.zhao marked an inline comment as done.Jan 12 2021, 2:39 PM
stephan.yichao.zhao added inline comments.
compiler-rt/lib/msan/msan_poisoning.cpp
94

tried again. The formatter made the code like this for some reason...

eugenis added inline comments.Jan 12 2021, 2:41 PM
compiler-rt/lib/msan/msan_poisoning.cpp
94

You are right, the same happens for me. OK then. clang-format is always right.

This revision was automatically updated to reflect the committed changes.