Skip to content

[DevASAN] Fix missing check for null shadow pointer #19574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions libdevice/sanitizer/asan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ inline uptr MemToShadow_PVC(uptr addr, uint32_t as,
return shadow_ptr;
} else if (as == ADDRESS_SPACE_LOCAL) { // local
const auto shadow_offset = launch_info->LocalShadowOffset;
if (shadow_offset == 0) {
const auto wid = WorkGroupLinearId();
if (shadow_offset == 0 || wid >= ASAN_MAX_WG_LOCAL) {
return 0;
}

// The size of SLM is 128KB on PVC
constexpr unsigned SLM_SIZE = 128 * 1024;
const auto wid = WorkGroupLinearId();

uptr shadow_ptr = shadow_offset + ((wid * SLM_SIZE) >> ASAN_SHADOW_SCALE) +
((addr & (SLM_SIZE - 1)) >> ASAN_SHADOW_SCALE);
Expand Down Expand Up @@ -494,6 +494,9 @@ void ReportMisalignError(uptr addr, uint32_t as, bool is_recover,
const DebugInfo *debug) {

auto *shadow = (__SYCL_GLOBAL__ s8 *)MemToShadow(addr, as, debug);
if (!shadow)
return;

while (*shadow >= 0) {
++shadow;
}
Expand Down Expand Up @@ -710,6 +713,9 @@ __asan_set_shadow_static_local(uptr ptr, size_t size,
// Set red zone
{
auto shadow_address = MemToShadow(ptr + aligned_size, ADDRESS_SPACE_LOCAL);
if (!shadow_address)
return;

auto count = (size_with_redzone - aligned_size) >> ASAN_SHADOW_SCALE;

ASAN_DEBUG(__spirv_ocl_printf(__mem_set_shadow_local, shadow_address,
Expand All @@ -726,6 +732,9 @@ __asan_set_shadow_static_local(uptr ptr, size_t size,
auto user_end = ptr + size;
auto *shadow_end =
(__SYCL_GLOBAL__ s8 *)MemToShadow(user_end, ADDRESS_SPACE_LOCAL);
if (!shadow_end)
return;

auto value = user_end - RoundDownTo(user_end, ASAN_SHADOW_GRANULARITY) + 1;
*shadow_end = value;

Expand All @@ -748,7 +757,11 @@ __asan_unpoison_shadow_static_local(uptr ptr, size_t size,
ASAN_DEBUG(__spirv_ocl_printf(__mem_unpoison_shadow_static_local_begin));

auto shadow_begin = MemToShadow(ptr + size, ADDRESS_SPACE_LOCAL);
if (!shadow_begin)
return;
auto shadow_end = MemToShadow(ptr + size_with_redzone, ADDRESS_SPACE_LOCAL);
if (!shadow_end)
return;

ASAN_DEBUG(
__spirv_ocl_printf(__mem_set_shadow_local, shadow_begin, shadow_end, 0));
Expand Down
5 changes: 4 additions & 1 deletion libdevice/sanitizer/tsan_rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ static __SYCL_CONSTANT__ const char __tsan_print_cleanup_local[] =

DEVICE_EXTERN_C_NOINLINE void __tsan_cleanup_static_local(uptr addr,
size_t size) {
if (GetCurrentSid() == -1)
return;

// Update shadow memory of local memory only on first work-item
if (__spirv_LocalInvocationId_x() + __spirv_LocalInvocationId_y() +
__spirv_LocalInvocationId_z() ==
Expand All @@ -505,7 +508,7 @@ static __SYCL_CONSTANT__ const char __tsan_print_report_arg_count_incorrect[] =

DEVICE_EXTERN_C_NOINLINE void __tsan_cleanup_dynamic_local(uptr ptr,
uint32_t num_args) {
if (!TsanLaunchInfo->LocalShadowOffset)
if (!TsanLaunchInfo->LocalShadowOffset || GetCurrentSid() == -1)
return;

if (num_args != TsanLaunchInfo->NumLocalArgs) {
Expand Down