From 30f71c7fc0f6404cb298841a9d2123eaca1877be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Fri, 11 Dec 2020 15:29:35 +0100 Subject: [PATCH] [NTOS] Zero data unconditionally after segment end, unless section is created with SEC_RESERVE Use a SEC_RESERVE section in Cc --- ntoskrnl/cc/view.c | 2 +- ntoskrnl/mm/section.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c index ee0ec497d40..ae6464f2b58 100644 --- a/ntoskrnl/cc/view.c +++ b/ntoskrnl/cc/view.c @@ -1286,7 +1286,7 @@ CcRosInitializeFileCache ( NULL, &SharedCacheMap->SectionSize, PAGE_READWRITE, - 0, + SEC_RESERVE, NULL, FileObject); diff --git a/ntoskrnl/mm/section.c b/ntoskrnl/mm/section.c index d71bc490934..8e9669d9ab9 100644 --- a/ntoskrnl/mm/section.c +++ b/ntoskrnl/mm/section.c @@ -1208,7 +1208,8 @@ MiReadPage(PMEMORY_AREA MemoryArea, Status = STATUS_SUCCESS; } - if ((MemoryArea->VadNode.u.VadFlags.VadType == VadImageMap) && ((SegOffset + PAGE_SIZE) > MemoryArea->SectionData.Segment->RawLength.QuadPart)) + if (!MemoryArea->SectionData.Section->u.Flags.Reserve + && ((SegOffset + PAGE_SIZE) > MemoryArea->SectionData.Segment->RawLength.QuadPart)) { KIRQL OldIrql; PUCHAR PageMap; @@ -2209,6 +2210,8 @@ MmCreateDataFileSection(PSECTION *SectionObject, if (AllocationAttributes & SEC_NO_CHANGE) Section->u.Flags.NoChange = 1; + if (AllocationAttributes & SEC_RESERVE) + Section->u.Flags.Reserve = 1; if (!GotFileHandle) { @@ -4832,13 +4835,16 @@ MmExtendSection( PMM_SECTION_SEGMENT Segment = (PMM_SECTION_SEGMENT)Section->Segment; Section->SizeOfSection = *NewSize; - MmLockSectionSegment(Segment); - if (Segment->RawLength.QuadPart < NewSize->QuadPart) + if (!Section->u.Flags.Reserve) { - Segment->RawLength = *NewSize; - Segment->Length.QuadPart = (NewSize->QuadPart + PAGE_SIZE - 1) & ~((LONGLONG)PAGE_SIZE); + MmLockSectionSegment(Segment); + if (Segment->RawLength.QuadPart < NewSize->QuadPart) + { + Segment->RawLength = *NewSize; + Segment->Length.QuadPart = (NewSize->QuadPart + PAGE_SIZE - 1) & ~((LONGLONG)PAGE_SIZE); + } + MmUnlockSectionSegment(Segment); } - MmUnlockSectionSegment(Segment); } return STATUS_SUCCESS;