fix: Fixed out-of-bounds write to usageInfos array with residency task count

Related-To: NEO-12952

Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
Slawomir Milczarek
2025-07-03 17:02:07 +00:00
committed by Compute-Runtime-Automation
parent 0fca7fb998
commit 76090f041d
2 changed files with 10 additions and 0 deletions

View File

@@ -176,6 +176,10 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation>, NEO::NonCopyableAn
MOCKABLE_VIRTUAL bool isResident(uint32_t contextId) const { return GraphicsAllocation::objectNotResident != getResidencyTaskCount(contextId); }
bool isAlwaysResident(uint32_t contextId) const { return GraphicsAllocation::objectAlwaysResident == getResidencyTaskCount(contextId); }
void updateResidencyTaskCount(TaskCountType newTaskCount, uint32_t contextId) {
if (contextId >= usageInfos.size()) {
DEBUG_BREAK_IF(true);
return;
}
if (usageInfos[contextId].residencyTaskCount != GraphicsAllocation::objectAlwaysResident || newTaskCount == GraphicsAllocation::objectNotResident) {
usageInfos[contextId].residencyTaskCount = newTaskCount;
}

View File

@@ -138,6 +138,12 @@ TEST(GraphicsAllocationTest, givenResidentGraphicsAllocationWhenCheckIfResidency
EXPECT_TRUE(graphicsAllocation.isResidencyTaskCountBelow(currentResidencyTaskCount + 1u, 0u));
}
TEST(GraphicsAllocationTest, givenResidentGraphicsAllocationWhenUpdatingResidencyTaskCountForUnusedContextIdThenDoEarlyReturn) {
MockGraphicsAllocation graphicsAllocation;
auto contextId = static_cast<uint32_t>(graphicsAllocation.usageInfos.size());
graphicsAllocation.updateResidencyTaskCount(1u, contextId);
}
TEST(GraphicsAllocationTest, givenAllocationTypeWhenCheckingCpuAccessRequiredThenReturnTrue) {
for (uint32_t i = 0; i < static_cast<uint32_t>(AllocationType::count); i++) {
auto allocType = static_cast<AllocationType>(i);