[NTOS:MM] Fix more 64 bit arithmetics

This commit is contained in:
Jérôme Gardou 2020-12-15 10:07:27 +01:00
parent 6bab72f69a
commit 96ae15ac4b

View file

@ -1299,6 +1299,14 @@ MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
{
/* The caller did not, so pick a 64K aligned view size based on the offset */
SectionOffset->LowPart &= ~(_64K - 1);
/* Make sure that we will not overflow */
if ((Section->SizeOfSection.QuadPart - SectionOffset->QuadPart) > MAXLONG_PTR)
{
MiDereferenceControlArea(ControlArea);
return STATUS_INVALID_VIEW_SIZE;
}
*ViewSize = (SIZE_T)(Section->SizeOfSection.QuadPart - SectionOffset->QuadPart);
}
else
@ -1306,6 +1314,13 @@ MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
/* A size was specified, align it to a 64K boundary */
*ViewSize += SectionOffset->LowPart & (_64K - 1);
/* Check for overflow or huge value */
if ((*ViewSize < (SectionOffset->LowPart & (_64K - 1))) || ((*ViewSize) > MAXLONG_PTR))
{
MiDereferenceControlArea(ControlArea);
return STATUS_INVALID_VIEW_SIZE;
}
/* Align the offset as well to make this an aligned map */
SectionOffset->LowPart &= ~((ULONG)_64K - 1);
}
@ -1313,13 +1328,6 @@ MiMapViewOfDataSection(IN PCONTROL_AREA ControlArea,
/* We must be dealing with a 64KB aligned offset. This is a Windows ASSERT */
ASSERT((SectionOffset->LowPart & ((ULONG)_64K - 1)) == 0);
/* It's illegal to try to map more than overflows a LONG_PTR */
if (*ViewSize >= MAXLONG_PTR)
{
MiDereferenceControlArea(ControlArea);
return STATUS_INVALID_VIEW_SIZE;
}
/* Windows ASSERTs for this flag */
ASSERT(ControlArea->u.Flags.GlobalOnlyPerSession == 0);
@ -1535,7 +1543,10 @@ MiCreatePagingFileMap(OUT PSEGMENT *Segment,
SizeLimit <<= PAGE_SHIFT;
/* Fail if this size is too big */
if (MaximumSize->QuadPart > SizeLimit) return STATUS_SECTION_TOO_BIG;
if (MaximumSize->QuadPart > SizeLimit)
{
return STATUS_SECTION_TOO_BIG;
}
/* Calculate how many Prototype PTEs will be needed */
PteCount = (PFN_COUNT)((MaximumSize->QuadPart + PAGE_SIZE - 1) >> PAGE_SHIFT);
@ -1592,7 +1603,7 @@ MiCreatePagingFileMap(OUT PSEGMENT *Segment,
/* Save some extra accounting data for the segment as well */
NewSegment->u1.CreatingProcess = PsGetCurrentProcess();
NewSegment->SizeOfSegment = PteCount * PAGE_SIZE;
NewSegment->SizeOfSegment = ((ULONGLONG)PteCount) * PAGE_SIZE;
NewSegment->TotalNumberOfPtes = PteCount;
NewSegment->NonExtendedPtes = PteCount;