From 113cc9ae2a7d21c6ddb3e80d6c2c6a4cfffb8536 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 15 Aug 2022 20:50:13 +0000 Subject: [PATCH] SWDEV-344168 - hipVmm functionality memory check fix Change-Id: Ia1de96ac9dbcbfb6a94a234aec3bf6cb51961799 --- hipamd/src/hip_memory.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hipamd/src/hip_memory.cpp b/hipamd/src/hip_memory.cpp index 241f18afbb..edf5192f5f 100644 --- a/hipamd/src/hip_memory.cpp +++ b/hipamd/src/hip_memory.cpp @@ -2543,7 +2543,8 @@ hipError_t ihipMemset_validate(void* dst, int64_t value, size_t valueSize, // dst ptr is host ptr hence error return hipErrorInvalidValue; } - if (memory->getSize() < (offset + sizeBytes)) { + // Return error if sizeBytes passed to memcpy is more than the actual size allocated + if (sizeBytes > (memory->getSize() - offset)){ return hipErrorInvalidValue; } return hipSuccess; @@ -2744,7 +2745,8 @@ hipError_t ihipMemset3D_validate(hipPitchedPtr pitchedDevPtr, int value, hipExte if (memory == nullptr) { return hipErrorInvalidValue; } - if ((sizeBytes + offset) > memory->getSize()) { + // Return error if sizeBytes passed to memcpy is more than the actual size allocated + if (sizeBytes > (memory->getSize() - offset)){ return hipErrorInvalidValue; } if (pitchedDevPtr.pitch == memory->getUserData().pitch_) {