[NTOSKRNL] Store page file minimum size and use it to prevent page file shrinking

This commit is contained in:
Pierre Schweitzer 2018-08-16 13:41:16 +02:00
parent bfc6a7957c
commit 2fe4e71383
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B
2 changed files with 27 additions and 5 deletions

View 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;

View 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;