Integer underflow in AMD64 NonPaged pool calculation and suboptimal i686 pool scaling #28
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
While reviewing the memory manager initialization functions (MM::Manager), I have identifies several issues in how the initial and maximum non-paged pool sizes are calculated across architectures. This includes a critical integer underflow bug on AMD64 that leads to an inevitable kernel panic on low-memory configurations, as well as a severe scaling discontinuity on i686.
1. Critical integer underflow on AMD64: In ComputeNonPagedPoolSize and ComputeMaximumNonPagedPoolSize, the size is calculated by unconditionally subtracting 4096 pages (16 MiB) from the total physical page count. However, the MM_MINIMUM_PHYSICAL_PAGES threshold for AMD64 is defined as 2048 (8 MiB). If the system attempts to boot with memory between 8 MiB and 16 MiB, the unsigned subtraction underflows to an extraordinarily large value. Consequently, the manager calculates a massive pool size, caps it at the maximum 128 GiB limit, and proceeds to blindly map the entire 128 GiB space. This immediately exhausts physical memory.
2. Suboptimal scaling discontinuity on i686: In ComputeNonPagedPoolSize, the code branches explicitly based on whether the system has less than or equal to 256 MiB of RAM. This introduces two problems: