[0.4.9][NTOS:MM] Fix BSOD0x1E

Port back
0.4.12-dev-973-g d29e216f99
[NTOSKRNL] In MmCreateImageSection, properly check whether cache was initialized
This fixes a crash that occurs if nul is typed in cmd.exe (BSOD0x1E)
----------
Port back also some unrelated formatting-improvements within section.c, e.g.: return(xyz) -> return xyz
A *partial* port of
0.4.15-dev-1793-g b7eb0fddf3
This commit is contained in:
Joachim Henze 2023-02-28 03:58:59 +01:00
parent 9452ddd565
commit c461964dcc

View file

@ -2800,7 +2800,7 @@ MmCreatePhysicalMemorySection(VOID)
PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY; PhysSection->AllocationAttributes |= SEC_PHYSICALMEMORY;
PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT; PhysSection->Segment->Flags &= ~MM_PAGEFILE_SEGMENT;
return(STATUS_SUCCESS); return STATUS_SUCCESS;
} }
NTSTATUS NTSTATUS
@ -2833,7 +2833,7 @@ MmInitSectionImplementation(VOID)
MmCreatePhysicalMemorySection(); MmCreatePhysicalMemorySection();
return(STATUS_SUCCESS); return STATUS_SUCCESS;
} }
NTSTATUS NTSTATUS
@ -2946,7 +2946,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(Status); return Status;
} }
/* /*
* Initialize it * Initialize it
@ -3005,7 +3005,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
{ {
ObDereferenceObject(Section); ObDereferenceObject(Section);
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(STATUS_SECTION_NOT_EXTENDED); return STATUS_SECTION_NOT_EXTENDED;
} }
} }
@ -3025,7 +3025,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
{ {
ObDereferenceObject(Section); ObDereferenceObject(Section);
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(Status); return Status;
} }
/* /*
@ -3041,7 +3041,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
//KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE); //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
ObDereferenceObject(Section); ObDereferenceObject(Section);
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(STATUS_NO_MEMORY); return STATUS_NO_MEMORY;
} }
Section->Segment = Segment; Section->Segment = Segment;
Segment->ReferenceCount = 1; Segment->ReferenceCount = 1;
@ -3098,7 +3098,7 @@ MmCreateDataFileSection(PROS_SECTION_OBJECT *SectionObject,
#endif #endif
//KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE); //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
*SectionObject = Section; *SectionObject = Section;
return(STATUS_SUCCESS); return STATUS_SUCCESS;
} }
/* /*
@ -3745,7 +3745,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
return STATUS_INVALID_FILE_FOR_SECTION; return STATUS_INVALID_FILE_FOR_SECTION;
#ifndef NEWCC #ifndef NEWCC
if (FileObject->SectionObjectPointer->SharedCacheMap == NULL) if (!CcIsFileCached(FileObject))
{ {
DPRINT1("Denying section creation due to missing cache initialization\n"); DPRINT1("Denying section creation due to missing cache initialization\n");
return STATUS_INVALID_FILE_FOR_SECTION; return STATUS_INVALID_FILE_FOR_SECTION;
@ -3767,7 +3767,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(Status); return Status;
} }
/* /*
@ -3788,7 +3788,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
{ {
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
ObDereferenceObject(Section); ObDereferenceObject(Section);
return(STATUS_NO_MEMORY); return STATUS_NO_MEMORY;
} }
RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT)); RtlZeroMemory(ImageSectionObject, sizeof(MM_IMAGE_SECTION_OBJECT));
@ -3812,7 +3812,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT); ExFreePoolWithTag(ImageSectionObject, TAG_MM_SECTION_SEGMENT);
ObDereferenceObject(Section); ObDereferenceObject(Section);
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(Status); return Status;
} }
Section->ImageSection = ImageSectionObject; Section->ImageSection = ImageSectionObject;
@ -3828,7 +3828,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
ExFreePool(ImageSectionObject); ExFreePool(ImageSectionObject);
ObDereferenceObject(Section); ObDereferenceObject(Section);
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(Status); return Status;
} }
if (NULL != InterlockedCompareExchangePointer(&FileObject->SectionObjectPointer->ImageSectionObject, if (NULL != InterlockedCompareExchangePointer(&FileObject->SectionObjectPointer->ImageSectionObject,
@ -3861,7 +3861,7 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
{ {
ObDereferenceObject(Section); ObDereferenceObject(Section);
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return(Status); return Status;
} }
ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject; ImageSectionObject = FileObject->SectionObjectPointer->ImageSectionObject;
@ -3884,13 +3884,14 @@ MmCreateImageSection(PROS_SECTION_OBJECT *SectionObject,
#endif #endif
//KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE); //KeSetEvent((PVOID)&FileObject->Lock, IO_NO_INCREMENT, FALSE);
*SectionObject = Section; *SectionObject = Section;
return(Status); return Status;
} }
static NTSTATUS static NTSTATUS
MmMapViewOfSegment(PMMSUPPORT AddressSpace, MmMapViewOfSegment(
PMMSUPPORT AddressSpace,
PROS_SECTION_OBJECT Section, PROS_SECTION_OBJECT Section,
PMM_SECTION_SEGMENT Segment, PMM_SECTION_SEGMENT Segment,
PVOID* BaseAddress, PVOID* BaseAddress,
@ -3946,7 +3947,7 @@ MmMapViewOfSegment(PMMSUPPORT AddressSpace,
{ {
DPRINT1("Mapping between 0x%p and 0x%p failed (%X).\n", DPRINT1("Mapping between 0x%p and 0x%p failed (%X).\n",
(*BaseAddress), (char*)(*BaseAddress) + ViewSize, Status); (*BaseAddress), (char*)(*BaseAddress) + ViewSize, Status);
return(Status); return Status;
} }
ObReferenceObject((PVOID)Section); ObReferenceObject((PVOID)Section);
@ -3962,7 +3963,7 @@ MmMapViewOfSegment(PMMSUPPORT AddressSpace,
MmInitializeRegion(&MArea->Data.SectionData.RegionListHead, MmInitializeRegion(&MArea->Data.SectionData.RegionListHead,
ViewSize, 0, Protect); ViewSize, 0, Protect);
return(STATUS_SUCCESS); return STATUS_SUCCESS;
} }
@ -4084,7 +4085,7 @@ MmUnmapViewOfSegment(PMMSUPPORT AddressSpace,
BaseAddress); BaseAddress);
if (MemoryArea == NULL) if (MemoryArea == NULL)
{ {
return(STATUS_UNSUCCESSFUL); return STATUS_UNSUCCESSFUL;
} }
Section = MemoryArea->Data.SectionData.Section; Section = MemoryArea->Data.SectionData.Section;
@ -4129,7 +4130,7 @@ MmUnmapViewOfSegment(PMMSUPPORT AddressSpace,
} }
MmUnlockSectionSegment(Segment); MmUnlockSectionSegment(Segment);
ObDereferenceObject(Section); ObDereferenceObject(Section);
return(Status); return Status;
} }
NTSTATUS NTSTATUS
@ -4226,7 +4227,7 @@ MiRosUnmapViewOfSection(IN PEPROCESS Process,
/* Notify debugger */ /* Notify debugger */
if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress); if (ImageBaseAddress && !SkipDebuggerNotify) DbgkUnMapViewOfSection(ImageBaseAddress);
return(STATUS_SUCCESS); return STATUS_SUCCESS;
} }
@ -4446,7 +4447,7 @@ NtQuerySection(
ObDereferenceObject(Section); ObDereferenceObject(Section);
return(Status); return Status;
} }
/********************************************************************** /**********************************************************************
@ -4602,14 +4603,14 @@ MmMapViewOfSection(IN PVOID SectionObject,
if ((*BaseAddress) != NULL) if ((*BaseAddress) != NULL)
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
return(STATUS_CONFLICTING_ADDRESSES); return STATUS_CONFLICTING_ADDRESSES;
} }
/* Otherwise find a gap to map the image. */ /* Otherwise find a gap to map the image. */
ImageBase = (ULONG_PTR)MmFindGap(AddressSpace, PAGE_ROUND_UP(ImageSize), MM_VIRTMEM_GRANULARITY, FALSE); ImageBase = (ULONG_PTR)MmFindGap(AddressSpace, PAGE_ROUND_UP(ImageSize), MM_VIRTMEM_GRANULARITY, FALSE);
if (ImageBase == 0) if (ImageBase == 0)
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
return(STATUS_CONFLICTING_ADDRESSES); return STATUS_CONFLICTING_ADDRESSES;
} }
/* Remember that we loaded image at a different base address */ /* Remember that we loaded image at a different base address */
NotAtBase = TRUE; NotAtBase = TRUE;
@ -4632,7 +4633,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
return(Status); return Status;
} }
} }
@ -4675,7 +4676,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
if ((ViewOffset % PAGE_SIZE) != 0) if ((ViewOffset % PAGE_SIZE) != 0)
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
return(STATUS_MAPPED_ALIGNMENT); return STATUS_MAPPED_ALIGNMENT;
} }
if ((*ViewSize) == 0) if ((*ViewSize) == 0)
@ -4702,7 +4703,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
return(Status); return Status;
} }
} }
@ -4788,9 +4789,6 @@ MmCanFileBeTruncated (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
return TRUE; return TRUE;
} }
/* /*
* @implemented * @implemented
*/ */
@ -4840,7 +4838,8 @@ MmFlushImageSection (IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
/* /*
* @implemented * @implemented
*/ */
NTSTATUS NTAPI NTSTATUS
NTAPI
MmMapViewInSystemSpace (IN PVOID SectionObject, MmMapViewInSystemSpace (IN PVOID SectionObject,
OUT PVOID * MappedBase, OUT PVOID * MappedBase,
IN OUT PSIZE_T ViewSize) IN OUT PSIZE_T ViewSize)
@ -4877,7 +4876,6 @@ MmMapViewInSystemSpace (IN PVOID SectionObject,
MmLockSectionSegment(Section->Segment); MmLockSectionSegment(Section->Segment);
Status = MmMapViewOfSegment(AddressSpace, Status = MmMapViewOfSegment(AddressSpace,
Section, Section,
Section->Segment, Section->Segment,