[NTOS/MM] Properly handle page faults in regions marked with
authorJérôme Gardou <jerome.gardou@reactos.org>
Fri, 2 Nov 2018 17:23:16 +0000 (18:23 +0100)
committerJérôme Gardou <zefklop@users.noreply.github.com>
Sat, 3 Nov 2018 11:50:16 +0000 (12:50 +0100)
PAGE_NOACCESS or PAGE_GUARD

ROSTESTS-110

ntoskrnl/mm/section.c

index 4a03514..298fc5f 100644 (file)
@@ -1410,6 +1410,29 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
                           &MemoryArea->Data.SectionData.RegionListHead,
                           Address, NULL);
     ASSERT(Region != NULL);
+
+    /* Check for a NOACCESS mapping */
+    if (Region->Protect & PAGE_NOACCESS)
+    {
+        return STATUS_ACCESS_VIOLATION;
+    }
+
+    if (Region->Protect & PAGE_GUARD)
+    {
+        /* Remove it */
+        Status = MmAlterRegion(AddressSpace, (PVOID)MA_GetStartingAddress(MemoryArea),
+                &MemoryArea->Data.SectionData.RegionListHead,
+                Address, PAGE_SIZE, Region->Type, Region->Protect & ~PAGE_GUARD,
+                MmAlterViewAttributes);
+
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT1("Removing PAGE_GUARD protection failed : 0x%08x.\n", Status);
+        }
+
+        return STATUS_GUARD_PAGE_VIOLATION;
+    }
+
     /*
      * Lock the segment
      */