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
This commit is contained in:
Satyanvesh Dittakavi
2024-02-21 16:37:06 +00:00
والد 4c28f4aefd
کامیت 821ae6a103
@@ -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<hipArray*>(ptr)) == hip::hipArraySet.end()) {
*reinterpret_cast<uint32_t*>(data) = 0;
return hipErrorInvalidValue;
}
cl_mem dstMemObj = reinterpret_cast<cl_mem>((static_cast<hipArray*>(ptr))->data);
if (!is_valid(dstMemObj)) {
*reinterpret_cast<uint32_t*>(data) = 0;