From 5b72582474eb3858337ad250ce89ee1f1e96ba95 Mon Sep 17 00:00:00 2001 From: Ioannis Assiouras Date: Thu, 25 Jan 2024 13:45:59 +0000 Subject: [PATCH] SWDEV-443018 - Restrict input range for value argument in hipPointerSetAttribute Change-Id: I17b6448bf49aed49315a0b4c1426dcbe011735d9 --- hipamd/src/hip_memory.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hipamd/src/hip_memory.cpp b/hipamd/src/hip_memory.cpp index 8dc0e176bd..482ca6cf66 100644 --- a/hipamd/src/hip_memory.cpp +++ b/hipamd/src/hip_memory.cpp @@ -3688,6 +3688,10 @@ hipError_t ihipPointerSetAttribute(const void* value, hipPointer_attribute attri if (attribute != HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS) { return hipErrorInvalidValue; } + const unsigned int syncMemops = *reinterpret_cast(value); + if (syncMemops != 0 && syncMemops != 1) { + return hipErrorInvalidValue; + } size_t offset = 0; amd::Memory* memObj = getMemoryObject(ptr, offset); @@ -3695,8 +3699,7 @@ hipError_t ihipPointerSetAttribute(const void* value, hipPointer_attribute attri return hipErrorInvalidDevicePointer; } - memObj->getUserData().sync_mem_ops_ - = static_cast(*(reinterpret_cast(value))); + memObj->getUserData().sync_mem_ops_ = static_cast(syncMemops); return hipSuccess; }