[NTOSKRNL] Store page file minimum size and use it to prevent page file shrinking
authorPierre Schweitzer <pierre@reactos.org>
Thu, 16 Aug 2018 11:41:16 +0000 (13:41 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Thu, 16 Aug 2018 11:41:16 +0000 (13:41 +0200)
ntoskrnl/include/internal/mm.h
ntoskrnl/mm/pagefile.c

index 38b34cd..9739d62 100644 (file)
@@ -426,15 +426,15 @@ extern MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
 /* Page file information */
 typedef struct _MMPAGING_FILE
 {
-    PFILE_OBJECT FileObject;
-    HANDLE FileHandle;
-    LARGE_INTEGER MaximumSize;
     LARGE_INTEGER CurrentSize;
+    LARGE_INTEGER MaximumSize;
+    LARGE_INTEGER MinimumSize;
     PFN_NUMBER FreePages;
     PFN_NUMBER UsedPages;
-    PRTL_BITMAP AllocMap;
-    KSPIN_LOCK AllocMapLock;
+    PFILE_OBJECT FileObject;
     UNICODE_STRING PageFileName;
+    PRTL_BITMAP AllocMap;
+    HANDLE FileHandle;
 }
 MMPAGING_FILE, *PMMPAGING_FILE;
 
index 15d8ae0..784495d 100644 (file)
@@ -634,6 +634,27 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
             return STATUS_NOT_FOUND;
         }
 
+        /* Don't allow page file shrinking */
+        if (PagingFile->MinimumSize.QuadPart > SafeMinimumSize.QuadPart)
+        {
+            KeReleaseGuardedMutex(&MmPageFileCreationLock);
+            ObDereferenceObject(FileObject);
+            ZwClose(FileHandle);
+            ExFreePoolWithTag(Dacl, 'lcaD');
+            ExFreePoolWithTag(Buffer, TAG_MM);
+            return STATUS_INVALID_PARAMETER_2;
+        }
+
+        if (SafeMaximumSize.QuadPart < PagingFile->MaximumSize.QuadPart)
+        {
+            KeReleaseGuardedMutex(&MmPageFileCreationLock);
+            ObDereferenceObject(FileObject);
+            ZwClose(FileHandle);
+            ExFreePoolWithTag(Dacl, 'lcaD');
+            ExFreePoolWithTag(Buffer, TAG_MM);
+            return STATUS_INVALID_PARAMETER_3;
+        }
+
         /* FIXME: implement parameters checking and page file extension */
         UNIMPLEMENTED;
 
@@ -721,6 +742,7 @@ NtCreatePagingFile(IN PUNICODE_STRING FileName,
     PagingFile->FileObject = FileObject;
     PagingFile->MaximumSize.QuadPart = SafeMaximumSize.QuadPart;
     PagingFile->CurrentSize.QuadPart = SafeMinimumSize.QuadPart;
+    PagingFile->MinimumSize.QuadPart = SafeMinimumSize.QuadPart;
     PagingFile->FreePages = (ULONG)(SafeMinimumSize.QuadPart / PAGE_SIZE);
     PagingFile->UsedPages = 0;
     PagingFile->PageFileName = PageFileName;