• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
58Implementation notes
59====================
60
61We specifically decided not to use VMA information in order to avoid relying on
62MM states (except for limited "struct page" info). The page table check is a
63separate from Linux-MM state machine that verifies that the user accessible
64pages are not falsely shared.
65
66PAGE_TABLE_CHECK depends on EXCLUSIVE_SYSTEM_RAM. The reason is that without
67EXCLUSIVE_SYSTEM_RAM, users are allowed to map arbitrary physical memory
68regions into the userspace via /dev/mem. At the same time, pages may change
69their properties (e.g., from anonymous pages to named pages) while they are
70still being mapped in the userspace, leading to "corruption" detected by the
71page table check.
72
73Even with EXCLUSIVE_SYSTEM_RAM, I/O pages may be still allowed to be mapped via
74/dev/mem. However, these pages are always considered as named pages, so they
75won't break the logic used in the page table check.
76