[NTOS:MM] Unconditionally purge cache on image section creation.

This commit is contained in:
Jérôme Gardou 2021-01-27 17:02:43 +01:00
parent c1c51e31e4
commit ea354c4bc7

View file

@ -2470,20 +2470,6 @@ ExeFmtpAllocateSegments(IN ULONG NrSegments)
return Segments;
}
static NTSTATUS
MmMapViewOfSegment(PMMSUPPORT AddressSpace,
BOOLEAN AsImage,
PMM_SECTION_SEGMENT Segment,
PVOID* BaseAddress,
SIZE_T ViewSize,
ULONG Protect,
LONGLONG ViewOffset,
ULONG AllocationType);
static NTSTATUS
MmUnmapViewOfSegment(PMMSUPPORT AddressSpace,
PVOID BaseAddress);
static
NTSTATUS
NTAPI
@ -2538,45 +2524,14 @@ ExeFmtpReadFile(IN PVOID File,
return STATUS_INSUFFICIENT_RESOURCES;
}
if (FileObject->SectionObjectPointer->DataSectionObject)
Status = MiSimpleRead(FileObject, &FileOffset, Buffer, BufferSize, TRUE, &Iosb);
UsedSize = (ULONG)Iosb.Information;
if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
{
PVOID SegmentMap = NULL;
/* Get the data from the file mapping instead */
MmLockAddressSpace(MmGetKernelAddressSpace());
Status = MmMapViewOfSegment(MmGetKernelAddressSpace(),
FALSE,
FileObject->SectionObjectPointer->DataSectionObject,
&SegmentMap,
BufferSize,
PAGE_READONLY,
FileOffset.QuadPart,
0);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
if (!NT_SUCCESS(Status))
return Status;
RtlCopyMemory(Buffer, SegmentMap, BufferSize);
UsedSize = BufferSize;
MmLockAddressSpace(MmGetKernelAddressSpace());
MmUnmapViewOfSegment(MmGetKernelAddressSpace(), SegmentMap);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}
else
{
Status = MiSimpleRead(FileObject, &FileOffset, Buffer, BufferSize, TRUE, &Iosb);
UsedSize = (ULONG)Iosb.Information;
if(NT_SUCCESS(Status) && UsedSize < OffsetAdjustment)
{
Status = STATUS_IN_PAGE_ERROR;
ASSERT(!NT_SUCCESS(Status));
}
Status = STATUS_IN_PAGE_ERROR;
ASSERT(!NT_SUCCESS(Status));
}
if(NT_SUCCESS(Status))
@ -3175,10 +3130,7 @@ MmCreateImageSection(PSECTION *SectionObject,
MiReleasePfnLock(OldIrql);
/* Purge the cache */
if (CcIsFileCached(FileObject))
{
CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, NULL);
}
CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, NULL);
StatusExeFmt = ExeFmtpCreateImageSection(FileObject, ImageSectionObject);