This patch implements __hwasan_memset_match_all, __hwasan_memcpy_match_all and __hwasan_memmove_match_all, making hwasan-match-all-tag flag working for hwasan versions of memset, memcpy and memmove.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
D149580 and this patch implement hwasan-match-all-tag flag support for hwasan callback memaccess instrumentation and memset, memcpy, memmove meminstrinsic calls.
And with D149580 and this patch, if hwasan-match-all-tag is set, calls to __hwasan_load, __hwasan_store, ____hwasan_memset, __hwasan_memcpy and __hwasan_memmove will be replaced with their match_all versions: __hwasan_load_match_all, __hwasan_store_match_all, __hwasan_memset_match_all, __hwasan_memcpy_match_all and __hwasan_memmove_match_all.
When HWAddressSanitizer compiling in kernel mode, hwasan-match-all-tag is implicitly set to 0xFF.
I'm not familiar with kernel mode HWASAN.
But from https://github.com/torvalds/linux/blob/master/mm/kasan/sw_tags.c#L88, I see pointers tagged with 0xff is already ignored in __hwasan_load, __hwasan_store.
So should we distinguish kernel mode HWASAN and user-space HWASAN for hwasan-match-all-tag flag ? :
- for user-space HWASAN, when hwasan-match-all-tag flag is set, we emit calls to __hwasan_load_match_all, __hwasan_memset_match_all, etc.
- for kernel mode HWASAN, hwasan-match-all-tag is implicitly set to 0xFF, we emit calls to __hwasan_load, __hwasan_memset, etc.
Or if hwasan-match-all-tag is set, no matter user-space HWASAN or kernel mode HWASAN, we always emit calls to __hwasan_load_match_all,__hwasan_memset_match_all, and implement __hwasan_load_match_all, __hwasan_memset_match_all in kernel HWASAN runtime ?
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
664–685 | Introduced in https://reviews.llvm.org/D122724, for supporting HWAddressSanitizer compiling in kernel mode | |
llvm/test/Instrumentation/HWAddressSanitizer/mem-intrinsics.ll | ||
18–21 | -hwasan-kernel implicit set match-all-tag to 0xff. call ptr @__hwasan_memset_match_all call ptr @memset_match_all Just happen to pass these checks. |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
674 | Can you make use of this constructor template <size_t N> /*implicit*/ constexpr ArrayRef(const std::array<T, N> &Arr) FunctionType *HWAsanMemTransferFnTy = FunctionType::get( Int8PtrTy, ArrayRef(HWAsanMemTransferArgTys), false); | |
674 |
sorry, copied wrong one template <size_t N> /*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
|
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
674 | Sorry, I'm not sure if this is exactly what you meant: FunctionType *HWAsanMemTransferFnTy; if (UseMatchAllCallback) { HWAsanMemTransferFnTy = FunctionType::get( Int8PtrTy, {Int8PtrTy, Int8PtrTy, IntptrTy, Int8Ty}, false); } else { HWAsanMemTransferFnTy = FunctionType::get( Int8PtrTy, {Int8PtrTy, Int8PtrTy, IntptrTy}, false); } |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
674 | yes, this also looks good if (UseMatchAllCallback) { HWAsanMemTransferFnTy = FunctionType::get( Int8PtrTy, {Int8PtrTy, Int8PtrTy, IntptrTy, Int8Ty}, false); HWAsanMemsetFnTy = FunctionType::get( Int8PtrTy, {Int8PtrTy, Int32Ty, IntptrTy, Int8Ty}, false); } else { } |
Can you make use of this constructor