[NTOS:MM] Acquire PsLoadedModuleResource when walking PsLoadedModuleList. CORE-16449

This commit is contained in:
Thomas Faber 2020-10-15 13:42:13 +02:00
parent a30edc324e
commit ba9bf73d48
No known key found for this signature in database
GPG key ID: 076E7C3D44720826
2 changed files with 7 additions and 3 deletions

View file

@ -1466,13 +1466,14 @@ MiFindInitializationCode(OUT PVOID *StartVa,
/* Assume failure */ /* Assume failure */
*StartVa = NULL; *StartVa = NULL;
/* Acquire the necessary lock while we loop the list */ /* Acquire the necessary locks while we loop the list */
KeEnterCriticalRegion(); KeEnterCriticalRegion();
KeWaitForSingleObject(&MmSystemLoadLock, KeWaitForSingleObject(&MmSystemLoadLock,
WrVirtualMemory, WrVirtualMemory,
KernelMode, KernelMode,
FALSE, FALSE,
NULL); NULL);
ExAcquireResourceExclusiveLite(&PsLoadedModuleResource, TRUE);
/* Loop all loaded modules */ /* Loop all loaded modules */
NextEntry = PsLoadedModuleList.Flink; NextEntry = PsLoadedModuleList.Flink;
@ -1620,7 +1621,8 @@ MiFindInitializationCode(OUT PVOID *StartVa,
NextEntry = NextEntry->Flink; NextEntry = NextEntry->Flink;
} }
/* Release the lock and return */ /* Release the locks and return */
ExReleaseResourceLite(&PsLoadedModuleResource);
KeReleaseMutant(&MmSystemLoadLock, 1, FALSE, FALSE); KeReleaseMutant(&MmSystemLoadLock, 1, FALSE, FALSE);
KeLeaveCriticalRegion(); KeLeaveCriticalRegion();
} }

View file

@ -273,7 +273,8 @@ MmInitSystem(IN ULONG Phase,
/* Initialize the balance set manager */ /* Initialize the balance set manager */
MmInitBsmThread(); MmInitBsmThread();
/* Loop the boot loaded images */ /* Loop the boot loaded images (under lock) */
ExAcquireResourceExclusiveLite(&PsLoadedModuleResource, TRUE);
for (ListEntry = PsLoadedModuleList.Flink; for (ListEntry = PsLoadedModuleList.Flink;
ListEntry != &PsLoadedModuleList; ListEntry != &PsLoadedModuleList;
ListEntry = ListEntry->Flink) ListEntry = ListEntry->Flink)
@ -284,6 +285,7 @@ MmInitSystem(IN ULONG Phase,
/* Set up the image protection */ /* Set up the image protection */
MiWriteProtectSystemImage(DataTableEntry->DllBase); MiWriteProtectSystemImage(DataTableEntry->DllBase);
} }
ExReleaseResourceLite(&PsLoadedModuleResource);
return TRUE; return TRUE;
} }