https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2fe4e71383e0196bb8157…
commit 2fe4e71383e0196bb815745469da05dd9137b3eb
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Thu Aug 16 13:41:16 2018 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Thu Aug 16 13:41:16 2018 +0200
[NTOSKRNL] Store page file minimum size and use it to prevent page file shrinking
---
ntoskrnl/include/internal/mm.h | 10 +++++-----
ntoskrnl/mm/pagefile.c | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/ntoskrnl/include/internal/mm.h b/ntoskrnl/include/internal/mm.h
index 38b34cd74f..9739d62709 100644
--- a/ntoskrnl/include/internal/mm.h
+++ b/ntoskrnl/include/internal/mm.h
@@ -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;
diff --git a/ntoskrnl/mm/pagefile.c b/ntoskrnl/mm/pagefile.c
index 15d8ae0033..784495d444 100644
--- a/ntoskrnl/mm/pagefile.c
+++ b/ntoskrnl/mm/pagefile.c
@@ -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;