From 0a6ac3c0207fb16b949013073c5d0b376e362f3b Mon Sep 17 00:00:00 2001 From: Aryan Salmanpour Date: Mon, 5 Oct 2020 16:33:32 -0400 Subject: [PATCH] Fix a seg fault when unallocated mem handle passed to hipIpcOpenMemHandle API also validate the flag argument passed to hipIpcOpenMemHandle API and return error if it is not equal to "hipIpcMemLazyEnablePeerAccess" (defined to 0) and it is the only supported flag currenlty for this API. SWDEV-253462 Change-Id: Ie1c8b79c680a29dc72bf262cf53ae5e011fb1247 [ROCm/clr commit: 89964dbbd42db2ba95c8f1188fff650ed0bcfd9e] --- projects/clr/hipamd/rocclr/hip_memory.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/projects/clr/hipamd/rocclr/hip_memory.cpp b/projects/clr/hipamd/rocclr/hip_memory.cpp index 8fd9b05cdb..02e973eaec 100755 --- a/projects/clr/hipamd/rocclr/hip_memory.cpp +++ b/projects/clr/hipamd/rocclr/hip_memory.cpp @@ -1970,7 +1970,7 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne amd::Device* device = nullptr; ihipIpcMemHandle_t* ihandle = nullptr; - if (dev_ptr == nullptr) { + if (dev_ptr == nullptr || flags != hipIpcMemLazyEnablePeerAccess) { HIP_RETURN(hipErrorInvalidValue); } @@ -1978,6 +1978,10 @@ hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigne device = hip::getCurrentDevice()->devices()[0]; ihandle = reinterpret_cast(&handle); + if (ihandle->psize == 0) { + HIP_RETURN(hipErrorInvalidValue); + } + if(!device->IpcAttach(&(ihandle->ipc_handle), ihandle->psize, flags, dev_ptr)) { DevLogPrintfError("cannot attach ipc_handle: with ipc_size: %u flags: %u", ihandle->psize, flags); HIP_RETURN(hipErrorInvalidDevicePointer);