From 1ed823a477e67c9be0ea5aa32132fb4c8324181d Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Fri, 17 Mar 2023 08:16:45 +0000 Subject: [PATCH] SWDEV-374363 - hipImportExternalMemory/Semaphore should return error when the Memory/Semaphore handle desc type is invalid Change-Id: If122b05d87cc65974a797da69c134e2ac264d1db --- hipamd/src/hip_memory.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hipamd/src/hip_memory.cpp b/hipamd/src/hip_memory.cpp index 0e4f097ba8..edbe0ae367 100644 --- a/hipamd/src/hip_memory.cpp +++ b/hipamd/src/hip_memory.cpp @@ -109,6 +109,11 @@ hipError_t hipImportExternalMemory( HIP_RETURN(hipErrorInvalidValue); } + if ((memHandleDesc->type < hipExternalMemoryHandleTypeOpaqueFd) || + (memHandleDesc->type > hipExternalMemoryHandleTypeD3D11ResourceKmt)) { + HIP_RETURN(hipErrorInvalidValue); + } + size_t sizeBytes = memHandleDesc->size; amd::Context& amdContext = *hip::getCurrentDevice()->asContext(); @@ -173,6 +178,12 @@ hipError_t hipImportExternalSemaphore(hipExternalSemaphore_t* extSem_out, if (extSem_out == nullptr || semHandleDesc == nullptr) { HIP_RETURN(hipErrorInvalidValue); } + + if ((semHandleDesc->type < hipExternalSemaphoreHandleTypeOpaqueFd) || + (semHandleDesc->type > hipExternalSemaphoreHandleTypeD3D12Fence)) { + HIP_RETURN(hipErrorInvalidValue); + } + amd::Device* device = hip::getCurrentDevice()->devices()[0]; #ifdef _WIN32