1.. SPDX-License-Identifier: GPL-2.0
2
3.. _page_table_check:
4
5================
6Page Table Check
7================
8
9Introduction
10============
11
12Page table check allows to harden the kernel by ensuring that some types of
13the memory corruptions are prevented.
14
15Page table check performs extra verifications at the time when new pages become
16accessible from the userspace by getting their page table entries (PTEs PMDs
17etc.) added into the table.
18
19In case of detected corruption, the kernel is crashed. There is a small
20performance and memory overhead associated with the page table check. Therefore,
21it is disabled by default, but can be optionally enabled on systems where the
22extra hardening outweighs the performance costs. Also, because page table check
23is synchronous, it can help with debugging double map memory corruption issues,
24by crashing kernel at the time wrong mapping occurs instead of later which is
25often the case with memory corruptions bugs.
26
27Double mapping detection logic
28==============================
29
30+-------------------+-------------------+-------------------+------------------+
31| Current Mapping   | New mapping       | Permissions       | Rule             |
32+===================+===================+===================+==================+
33| Anonymous         | Anonymous         | Read              | Allow            |
34+-------------------+-------------------+-------------------+------------------+
35| Anonymous         | Anonymous         | Read / Write      | Prohibit         |
36+-------------------+-------------------+-------------------+------------------+
37| Anonymous         | Named             | Any               | Prohibit         |
38+-------------------+-------------------+-------------------+------------------+
39| Named             | Anonymous         | Any               | Prohibit         |
40+-------------------+-------------------+-------------------+------------------+
41| Named             | Named             | Any               | Allow            |
42+-------------------+-------------------+-------------------+------------------+
43
44Enabling Page Table Check
45=========================
46
47Build kernel with:
48
49- PAGE_TABLE_CHECK=y
50  Note, it can only be enabled on platforms where ARCH_SUPPORTS_PAGE_TABLE_CHECK
51  is available.
52
53- Boot with 'page_table_check=on' kernel parameter.
54
55Optionally, build kernel with PAGE_TABLE_CHECK_ENFORCED in order to have page
56table support without extra kernel parameter.
57