From f0c7f862d4da673ea3e4120918924af7a03ed0df Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Thu, 8 Feb 2018 14:15:02 +0100 Subject: [PATCH] [NTOSKRNL] Fix a ****ing bug where private cache map was deleted in CcUninitializeCacheMap() before the call to CcRosReleaseFileCache() which expects to have it to properly clean the file. So, move deletion code to CcRosReleaseFileCache() so that he's the only one to handle private map. Should hopefully fix all the recent buildbots issues (and the universe perhaps, who knows?) --- ntoskrnl/cc/fs.c | 19 ------------------- ntoskrnl/cc/view.c | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ntoskrnl/cc/fs.c b/ntoskrnl/cc/fs.c index 7be40ae82b4..38c9ae527c6 100644 --- a/ntoskrnl/cc/fs.c +++ b/ntoskrnl/cc/fs.c @@ -346,25 +346,6 @@ CcUninitializeCacheMap ( FALSE); } - /* Closing the handle, so kill the private cache map */ - if (FileObject->SectionObjectPointer->SharedCacheMap != NULL && - FileObject->PrivateCacheMap != NULL) - { - PPRIVATE_CACHE_MAP PrivateMap; - - PrivateMap = FileObject->PrivateCacheMap; - SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap; - - /* Remove it from the file */ - KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &OldIrql); - RemoveEntryList(&PrivateMap->PrivateLinks); - KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, OldIrql); - - /* And free it */ - FileObject->PrivateCacheMap = NULL; - ExFreePoolWithTag(PrivateMap, TAG_PRIVATE_CACHE_MAP); - } - Status = CcRosReleaseFileCache(FileObject); if (UninitializeCompleteEvent) { diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c index 18eaac50e8b..4823d042681 100644 --- a/ntoskrnl/cc/view.c +++ b/ntoskrnl/cc/view.c @@ -1180,7 +1180,21 @@ CcRosReleaseFileCache ( SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap; if (FileObject->PrivateCacheMap != NULL) { + KIRQL OldIrql; + PPRIVATE_CACHE_MAP PrivateMap; + + /* Closing the handle, so kill the private cache map */ + PrivateMap = FileObject->PrivateCacheMap; + + /* Remove it from the file */ + KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &OldIrql); + RemoveEntryList(&PrivateMap->PrivateLinks); + KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, OldIrql); + + /* And free it */ FileObject->PrivateCacheMap = NULL; + ExFreePoolWithTag(PrivateMap, TAG_PRIVATE_CACHE_MAP); + if (SharedCacheMap->OpenCount > 0) { SharedCacheMap->OpenCount--;