From 821ae6a10337a87550f2050efc3e36b746a7ee5f Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Wed, 21 Feb 2024 16:37:06 +0000 Subject: [PATCH] SWDEV-426272 - hipPointerGetAttribute shouldn't segfault when host ptr is passed Check the pointer if its present in the arrayset before trying to dereference it as it can cause access violation if the pointer is allocated using malloc Change-Id: Ida72b9015dc22269fc1fbe0728e66e3de29fda3d --- hipamd/src/hip_memory.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hipamd/src/hip_memory.cpp b/hipamd/src/hip_memory.cpp index 482ca6cf66..624885a022 100644 --- a/hipamd/src/hip_memory.cpp +++ b/hipamd/src/hip_memory.cpp @@ -3725,6 +3725,12 @@ hipError_t ihipPointerGetAttributes(void* data, hipPointer_attribute attribute, ((CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_USE_HOST_PTR) & memObj->getMemFlags())? hipMemoryTypeHost : hipMemoryTypeDevice; } else { // checks for array type + // ptr must be a host allocation using malloc since memObj is null and is + // not found in hipArraySet. + if (hip::hipArraySet.find(static_cast(ptr)) == hip::hipArraySet.end()) { + *reinterpret_cast(data) = 0; + return hipErrorInvalidValue; + } cl_mem dstMemObj = reinterpret_cast((static_cast(ptr))->data); if (!is_valid(dstMemObj)) { *reinterpret_cast(data) = 0;