This is an archive of the discontinued LLVM Phabricator instance.

[hwasan] support hwasan-match-all-tag flag for callback memory access instrumentation
ClosedPublic

Authored by Enna1 on May 1 2023, 4:37 AM.

Details

Summary

Currently, hwasan-match-all-tag flag is supported in inline memory access instrumentation and outline memory access instrumentation, but not supported in callback memory access instrumentation.

  • For inline memory access instrumentation: a hwasan-match-all-tag check is added following the tag-mismtach check, if tag from pointer is mismatched with tag from shadow memory and tag from pointer is not equal with hwasan-match-all-tag, then a tag-mismatch will be report.
  • For outline memory acess instrumentation: MatchAllTag is encoded in AccessInfo, when emit HWASAN memaccess symbols, asm-printer emits assembly instructions to check if tag from pointer is equal with hwasan-match-all-tag.
  • For callback memory access instrumentation: hwasan-match-all-tag check is not implemented in __hwasan_load/__hwasan_store.

This patch implements a set of callback functions: __hwasan_[load|store][1|2|4|8|16|n]_match_all and __hwasan_load[load|store][1|2|4|8|16|n]_match_all_noabort, making hwasan-match-all-tag flag working for callback memory access instrumentation.

Diff Detail

Event Timeline

Enna1 created this revision.May 1 2023, 4:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 4:37 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
Enna1 added a comment.May 1 2023, 4:39 AM

What do you think about the two approaches. If the first approach is prefered, I'm happy to update this patch using the first approach :)

Enna1 published this revision for review.May 1 2023, 4:40 AM
Enna1 added reviewers: vitalybuka, eugenis, pcc.
Enna1 added a subscriber: MTC.
Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 4:41 AM
Enna1 edited the summary of this revision. (Show Details)May 1 2023, 5:18 AM

Do we need this feature outside kernel?

What do you think about the two approaches. If the first approach is prefered, I'm happy to update this patch using the first approach :)

It's better to handler them in hwasan_load/hwasan_store
However we don't want additional argument when we don't need them. So we need a new hwasan_load_match_all/hwasan_store_match_all used with the feature.

Enna1 updated this revision to Diff 518617.May 1 2023, 6:36 PM

implement __hwasan_load_match_all/__hwasan_store_match_all and handle hwasan-match-all-tag flag in them.

Herald added a project: Restricted Project. · View Herald TranscriptMay 1 2023, 6:36 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
Enna1 edited the summary of this revision. (Show Details)May 1 2023, 6:39 PM
vitalybuka accepted this revision.May 3 2023, 10:52 AM
vitalybuka added inline comments.
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
999

Int8ptrTy and one below

This revision is now accepted and ready to land.May 3 2023, 10:52 AM
Enna1 added inline comments.May 3 2023, 6:09 PM
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
999

Sorry, I don't get it.
Here we call ConstantInt::get(IntptrTy, 8) to create a constant int value 8, O.TypeStoreSize represents size in bits, and O.TypeStoreSize divided by 8 represents size in bytes.
We should not use Int8ptrTy here.

Enna1 updated this revision to Diff 521893.May 13 2023, 3:19 AM

do not use match-all callback for kernel mode HWASAN