GPU/FIFO: avoid possible invalid memory accesses

1) ensure pKernelFifo->ppChidMgr[i]->pChanGrpTree is successfully
   allocated in function kfifoChidMgrConstruct_IMPL(), otherwise
   it may cause invalid memory access when calling mapFine().
2) only invoke mapDestroy() when pKernelFifo->ppChidMgr[i]->pChanGrpTree
   is not NULL in function kfifoChidMgrDestruct_IMPL(), otherwise
   it may cause invalid memory access.
3) ensure pChidMgr is valid in function kfifoGetChannelGroup_IMPL().

Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
This commit is contained in:
Jiang Liu 2024-06-06 09:07:21 +08:00
parent e45d91de02
commit 2bf606cd90

View File

@ -179,6 +179,13 @@ kfifoChidMgrConstruct_IMPL
pKernelFifo->ppChidMgr[i]->runlistId = i;
pKernelFifo->ppChidMgr[i]->pChanGrpTree = portMemAllocNonPaged(sizeof(KernelChannelGroupMap));
if (pKernelFifo->ppChidMgr[i]->pChanGrpTree == NULL)
{
status = NV_ERR_NO_MEMORY;
NV_PRINTF(LEVEL_ERROR, "Failed to allocate pFifo->pChidMgr[%d]->pChanGrpTree\n", i);
DBG_BREAKPOINT();
goto fail;
}
mapInitIntrusive(pKernelFifo->ppChidMgr[i]->pChanGrpTree);
status = _kfifoChidMgrAllocChidHeaps(pGpu, pKernelFifo, pKernelFifo->ppChidMgr[i]);
@ -216,8 +223,10 @@ kfifoChidMgrDestruct_IMPL
{
if (pKernelFifo->ppChidMgr[i] != NULL)
{
mapDestroy(pKernelFifo->ppChidMgr[i]->pChanGrpTree);
portMemFree(pKernelFifo->ppChidMgr[i]->pChanGrpTree);
if (pKernelFifo->ppChidMgr[i]->pChanGrpTree != NULL) {
mapDestroy(pKernelFifo->ppChidMgr[i]->pChanGrpTree);
portMemFree(pKernelFifo->ppChidMgr[i]->pChanGrpTree);
}
_kfifoChidMgrDestroyChidHeaps(pKernelFifo->ppChidMgr[i]);
_kfifoChidMgrDestroyChannelGroupMgr(pKernelFifo->ppChidMgr[i]);
portMemFree(pKernelFifo->ppChidMgr[i]);
@ -1550,6 +1559,7 @@ kfifoGetChannelGroup_IMPL
)
{
CHID_MGR *pChidMgr = kfifoGetChidMgr(pGpu, pKernelFifo, runlistID);
NV_ASSERT_OR_RETURN(pChidMgr != NULL, NULL);
return kfifoChidMgrGetKernelChannelGroup(pGpu, pKernelFifo, pChidMgr, grpID);
}