mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[NTOS:MM] Fix use-after-free error
The VAD / memory area can get deleted when calling MmUnmapViewOfSegment, so it must not be used after that.
This commit is contained in:
+10
-4
@@ -3670,13 +3670,16 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
|
||||
{
|
||||
PMM_SECTION_SEGMENT Segment = MemoryArea->SectionData.Segment;
|
||||
PMMVAD Vad = &MemoryArea->VadNode;
|
||||
PCONTROL_AREA ControlArea = Vad->ControlArea;
|
||||
PFILE_OBJECT FileObject;
|
||||
SIZE_T ViewSize;
|
||||
LARGE_INTEGER ViewOffset;
|
||||
ViewOffset.QuadPart = MemoryArea->SectionData.ViewOffset;
|
||||
|
||||
|
||||
InterlockedIncrement64(Segment->ReferenceCount);
|
||||
|
||||
ViewSize = PAGE_SIZE + ((Vad->EndingVpn - Vad->StartingVpn) << PAGE_SHIFT);
|
||||
|
||||
Status = MmUnmapViewOfSegment(AddressSpace, BaseAddress);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
@@ -3685,6 +3688,10 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
|
||||
ASSERT(NT_SUCCESS(Status));
|
||||
}
|
||||
|
||||
/* These might be deleted now */
|
||||
Vad = NULL;
|
||||
MemoryArea = NULL;
|
||||
|
||||
if (FlagOn(*Segment->Flags, MM_PHYSICALMEMORY_SEGMENT))
|
||||
{
|
||||
/* Don't bother */
|
||||
@@ -3706,11 +3713,10 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
|
||||
|
||||
/*
|
||||
* Flush only when last mapping is deleted.
|
||||
* FIXME: Why Vad->ControlArea == NULL?
|
||||
* FIXME: Why ControlArea == NULL? Or rather: is ControlArea ever not NULL here?
|
||||
*/
|
||||
if (Vad->ControlArea == NULL || Vad->ControlArea->NumberOfMappedViews == 1)
|
||||
if (ControlArea == NULL || ControlArea->NumberOfMappedViews == 1)
|
||||
{
|
||||
ViewSize = PAGE_SIZE + ((Vad->EndingVpn - Vad->StartingVpn) << PAGE_SHIFT);
|
||||
while (ViewSize > 0)
|
||||
{
|
||||
ULONG FlushSize = min(ViewSize, PAGE_ROUND_DOWN(MAXULONG));
|
||||
|
||||
Reference in New Issue
Block a user