brintos

brintos / linux-shallow public Read only

0
0
Text · 3.7 KiB · c59f22e Raw
81 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3================4Page Table Check5================6 7Introduction8============9 10Page table check allows to harden the kernel by ensuring that some types of11the memory corruptions are prevented.12 13Page table check performs extra verifications at the time when new pages become14accessible from the userspace by getting their page table entries (PTEs PMDs15etc.) added into the table.16 17In case of most detected corruption, the kernel is crashed. There is a small18performance and memory overhead associated with the page table check. Therefore,19it is disabled by default, but can be optionally enabled on systems where the20extra hardening outweighs the performance costs. Also, because page table check21is synchronous, it can help with debugging double map memory corruption issues,22by crashing kernel at the time wrong mapping occurs instead of later which is23often the case with memory corruptions bugs.24 25It can also be used to do page table entry checks over various flags, dump26warnings when illegal combinations of entry flags are detected.  Currently,27userfaultfd is the only user of such to sanity check wr-protect bit against28any writable flags.  Illegal flag combinations will not directly cause data29corruption in this case immediately, but that will cause read-only data to30be writable, leading to corrupt when the page content is later modified.31 32Double mapping detection logic33==============================34 35+-------------------+-------------------+-------------------+------------------+36| Current Mapping   | New mapping       | Permissions       | Rule             |37+===================+===================+===================+==================+38| Anonymous         | Anonymous         | Read              | Allow            |39+-------------------+-------------------+-------------------+------------------+40| Anonymous         | Anonymous         | Read / Write      | Prohibit         |41+-------------------+-------------------+-------------------+------------------+42| Anonymous         | Named             | Any               | Prohibit         |43+-------------------+-------------------+-------------------+------------------+44| Named             | Anonymous         | Any               | Prohibit         |45+-------------------+-------------------+-------------------+------------------+46| Named             | Named             | Any               | Allow            |47+-------------------+-------------------+-------------------+------------------+48 49Enabling Page Table Check50=========================51 52Build kernel with:53 54- PAGE_TABLE_CHECK=y55  Note, it can only be enabled on platforms where ARCH_SUPPORTS_PAGE_TABLE_CHECK56  is available.57 58- Boot with 'page_table_check=on' kernel parameter.59 60Optionally, build kernel with PAGE_TABLE_CHECK_ENFORCED in order to have page61table support without extra kernel parameter.62 63Implementation notes64====================65 66We specifically decided not to use VMA information in order to avoid relying on67MM states (except for limited "struct page" info). The page table check is a68separate from Linux-MM state machine that verifies that the user accessible69pages are not falsely shared.70 71PAGE_TABLE_CHECK depends on EXCLUSIVE_SYSTEM_RAM. The reason is that without72EXCLUSIVE_SYSTEM_RAM, users are allowed to map arbitrary physical memory73regions into the userspace via /dev/mem. At the same time, pages may change74their properties (e.g., from anonymous pages to named pages) while they are75still being mapped in the userspace, leading to "corruption" detected by the76page table check.77 78Even with EXCLUSIVE_SYSTEM_RAM, I/O pages may be still allowed to be mapped via79/dev/mem. However, these pages are always considered as named pages, so they80won't break the logic used in the page table check.81