From f84f83702c5139d0ba02b0c6f02ebfcf9be7e96e Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 6 Apr 2023 16:00:51 +0000 Subject: [PATCH] Fix for overwriting pointer info size Fix for overwriting pointer info size provided by caller of hsa_amd_pointer_info. Change-Id: I2e5d73ab9ba1a32bc9b4d112bc29b4a99fd8b3b5 [ROCm/ROCR-Runtime commit: c5bf7eb112054cf411c597c6dcdc0c8c3915490c] --- .../runtime/hsa-runtime/core/runtime/runtime.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index b5ae773d40..162b8a7e24 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -818,6 +818,8 @@ hsa_status_t Runtime::PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, voi // check output struct has an initialized size. if (info->size == 0) return HSA_STATUS_ERROR_INVALID_ARGUMENT; + retInfo.size = Min(size_t(info->size), sizeof(hsa_amd_pointer_info_t)); + bool returnListData = ((alloc != nullptr) && (num_agents_accessible != nullptr) && (accessible != nullptr)); @@ -831,8 +833,8 @@ hsa_status_t Runtime::PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, voi // The type will be HSA_EXT_POINTER_TYPE_UNKNOWN if so. auto err = hsaKmtQueryPointerInfo(ptr, &thunkInfo); if (err != HSAKMT_STATUS_SUCCESS || thunkInfo.Type == HSA_POINTER_UNKNOWN) { - memset(info, 0, sizeof(*info)); - info->type = HSA_EXT_POINTER_TYPE_UNKNOWN; + retInfo.type = HSA_EXT_POINTER_TYPE_UNKNOWN; + memcpy(info, &retInfo, retInfo.size); return HSA_STATUS_SUCCESS; } @@ -891,8 +893,6 @@ hsa_status_t Runtime::PtrInfo(const void* ptr, hsa_amd_pointer_info_t* info, voi retInfo.type = HSA_EXT_POINTER_TYPE_UNKNOWN; } - retInfo.size = Min(size_t(info->size), sizeof(hsa_amd_pointer_info_t)); - // IPC and Graphics memory may come from a node that does not have an agent in this process. // Ex. ROCR_VISIBLE_DEVICES or peer GPU is not supported by ROCm. retInfo.agentOwner.handle = 0;