Skip to content

Commit 08cdf07

Browse files
authored
[DeviceAsan] Enlarge nullpointer redzone to better detect problem (#2243)
1 parent d312d69 commit 08cdf07

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

source/loader/layers/sanitizer/asan_report.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ void ReportGenericError(const DeviceSanitizerReport &Report,
103103
// Try to demangle the kernel name
104104
KernelName = DemangleName(KernelName);
105105

106-
getContext()->logger.always("\n====ERROR: DeviceSanitizer: {} on {}",
106+
getContext()->logger.always("\n====ERROR: DeviceSanitizer: {} on {} ({})",
107107
ToString(Report.ErrorType),
108-
ToString(Report.MemoryType));
108+
ToString(Report.MemoryType),
109+
(void *)Report.Address);
109110
getContext()->logger.always(
110111
"{} of size {} at kernel <{}> LID({}, {}, {}) GID({}, "
111112
"{}, {})",

source/loader/layers/sanitizer/asan_shadow.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ ur_result_t ShadowMemoryCPU::Setup() {
5050
ShadowEnd = ShadowBegin + ShadowSize;
5151

5252
// Set shadow memory for null pointer
53-
auto URes = EnqueuePoisonShadow({}, 0, 1, kNullPointerRedzoneMagic);
53+
// For CPU, we use a typical page size of 4K bytes.
54+
constexpr size_t NullptrRedzoneSize = 4096;
55+
auto URes = EnqueuePoisonShadow({}, 0, NullptrRedzoneSize,
56+
kNullPointerRedzoneMagic);
5457
if (URes != UR_RESULT_SUCCESS) {
5558
getContext()->logger.error("EnqueuePoisonShadow(NullPointerRZ): {}",
5659
URes);
@@ -111,9 +114,12 @@ ur_result_t ShadowMemoryGPU::Setup() {
111114
}
112115

113116
// Set shadow memory for null pointer
117+
// For GPU, wu use up to 1 page of shadow memory
118+
const size_t NullptrRedzoneSize =
119+
GetVirtualMemGranularity(Context, Device) << ASAN_SHADOW_SCALE;
114120
ManagedQueue Queue(Context, Device);
115-
116-
Result = EnqueuePoisonShadow(Queue, 0, 1, kNullPointerRedzoneMagic);
121+
Result = EnqueuePoisonShadow(Queue, 0, NullptrRedzoneSize,
122+
kNullPointerRedzoneMagic);
117123
if (Result != UR_RESULT_SUCCESS) {
118124
getContext()->logger.error("EnqueuePoisonShadow(NullPointerRZ): {}",
119125
Result);

0 commit comments

Comments
 (0)