[NTOS:CC] Protect CcFlushCache call with a mutex

Fix crash when the function was called concurrently for the same file by BTRFS driver.
CORE-19664
This commit is contained in:
Thamatip Chitpong 2024-07-25 23:09:17 +07:00
parent 0899f4b2b1
commit cf4138fa24
2 changed files with 8 additions and 2 deletions

View file

@ -1142,6 +1142,8 @@ CcFlushCache (
IoStatus->Information = 0;
}
KeAcquireGuardedMutex(&SharedCacheMap->FlushCacheLock);
/*
* We flush the VACBs that we find here.
* If there is no (dirty) VACB, it doesn't mean that there is no data to flush, so we call Mm to be sure.
@ -1161,7 +1163,7 @@ CcFlushCache (
if (!NT_SUCCESS(Status))
{
CcRosReleaseVacb(SharedCacheMap, vacb, FALSE, FALSE);
goto quit;
break;
}
DirtyVacb = TRUE;
@ -1191,7 +1193,7 @@ CcFlushCache (
}
if (!NT_SUCCESS(Status))
goto quit;
break;
if (IoStatus)
IoStatus->Information += MmIosb.Information;
@ -1211,6 +1213,8 @@ CcFlushCache (
FlushStart -= FlushStart % VACB_MAPPING_GRANULARITY;
}
KeReleaseGuardedMutex(&SharedCacheMap->FlushCacheLock);
quit:
if (IoStatus)
{
@ -1319,6 +1323,7 @@ CcRosInitializeFileCache (
KeInitializeSpinLock(&SharedCacheMap->CacheMapLock);
InitializeListHead(&SharedCacheMap->CacheMapVacbListHead);
InitializeListHead(&SharedCacheMap->BcbList);
KeInitializeGuardedMutex(&SharedCacheMap->FlushCacheLock);
SharedCacheMap->Flags = SHARED_CACHE_MAP_IN_CREATION;

View file

@ -193,6 +193,7 @@ typedef struct _ROS_SHARED_CACHE_MAP
LIST_ENTRY CacheMapVacbListHead;
BOOLEAN PinAccess;
KSPIN_LOCK CacheMapLock;
KGUARDED_MUTEX FlushCacheLock;
#if DBG
BOOLEAN Trace; /* enable extra trace output for this cache map and it's VACBs */
#endif