Skip to content

Commit 1b67298

Browse files
committed
[NTOSKRNL] Map the VACB in kernel space before inserting it in lists.
The avoids race conditions where attempts to read from disk to not fully initialized VACB were performed. Also, added more debug prints in such situations. CORE-14349
1 parent 42df468 commit 1b67298

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

ntoskrnl/cc/copy.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ CcReadVirtualAddress (
110110
_SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER)
111111
{
112112
Status = _SEH2_GetExceptionCode();
113+
DPRINT1("MmProbeAndLockPages failed with: %lx for %p (%p, %p)\n", Status, Mdl, Vacb, Vacb->BaseAddress);
113114
KeBugCheck(CACHE_MANAGER);
114115
} _SEH2_END;
115116

@@ -186,6 +187,7 @@ CcWriteVirtualAddress (
186187
_SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER)
187188
{
188189
Status = _SEH2_GetExceptionCode();
190+
DPRINT1("MmProbeAndLockPages failed with: %lx for %p (%p, %p)\n", Status, Mdl, Vacb, Vacb->BaseAddress);
189191
KeBugCheck(CACHE_MANAGER);
190192
} _SEH2_END;
191193

ntoskrnl/cc/view.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,17 @@ CcRosCreateVacb (
752752
InitializeListHead(&current->CacheMapVacbListEntry);
753753
InitializeListHead(&current->DirtyVacbListEntry);
754754
InitializeListHead(&current->VacbLruListEntry);
755+
756+
CcRosVacbIncRefCount(current);
757+
758+
Status = CcRosMapVacbInKernelSpace(current);
759+
if (!NT_SUCCESS(Status))
760+
{
761+
CcRosVacbDecRefCount(current);
762+
ExFreeToNPagedLookasideList(&VacbLookasideList, current);
763+
return Status;
764+
}
765+
755766
CcRosAcquireVacbLock(current, NULL);
756767
KeAcquireGuardedMutex(&ViewLock);
757768

@@ -784,9 +795,10 @@ CcRosCreateVacb (
784795
current);
785796
}
786797
#endif
798+
CcRosVacbDecRefCount(*Vacb);
787799
CcRosReleaseVacbLock(*Vacb);
788800
KeReleaseGuardedMutex(&ViewLock);
789-
ExFreeToNPagedLookasideList(&VacbLookasideList, *Vacb);
801+
CcRosInternalFreeVacb(*Vacb);
790802
*Vacb = current;
791803
CcRosAcquireVacbLock(current, NULL);
792804
return STATUS_SUCCESS;
@@ -813,7 +825,6 @@ CcRosCreateVacb (
813825
}
814826
KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, oldIrql);
815827
InsertTailList(&VacbLruListHead, &current->VacbLruListEntry);
816-
CcRosVacbIncRefCount(current);
817828
KeReleaseGuardedMutex(&ViewLock);
818829

819830
MI_SET_USAGE(MI_USAGE_CACHE);
@@ -838,17 +849,6 @@ CcRosCreateVacb (
838849
/* Reference it to allow release */
839850
CcRosVacbIncRefCount(current);
840851

841-
Status = CcRosMapVacbInKernelSpace(current);
842-
if (!NT_SUCCESS(Status))
843-
{
844-
RemoveEntryList(&current->CacheMapVacbListEntry);
845-
RemoveEntryList(&current->VacbLruListEntry);
846-
CcRosReleaseVacb(SharedCacheMap, current, FALSE,
847-
FALSE, FALSE);
848-
CcRosVacbDecRefCount(current);
849-
ExFreeToNPagedLookasideList(&VacbLookasideList, current);
850-
}
851-
852852
return Status;
853853
}
854854

0 commit comments

Comments
 (0)