page_table_check.rst 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. _page_table_check:
  3. ================
  4. Page Table Check
  5. ================
  6. Introduction
  7. ============
  8. Page table check allows to harden the kernel by ensuring that some types of
  9. the memory corruptions are prevented.
  10. Page table check performs extra verifications at the time when new pages become
  11. accessible from the userspace by getting their page table entries (PTEs PMDs
  12. etc.) added into the table.
  13. In case of detected corruption, the kernel is crashed. There is a small
  14. performance and memory overhead associated with the page table check. Therefore,
  15. it is disabled by default, but can be optionally enabled on systems where the
  16. extra hardening outweighs the performance costs. Also, because page table check
  17. is synchronous, it can help with debugging double map memory corruption issues,
  18. by crashing kernel at the time wrong mapping occurs instead of later which is
  19. often the case with memory corruptions bugs.
  20. Double mapping detection logic
  21. ==============================
  22. +-------------------+-------------------+-------------------+------------------+
  23. | Current Mapping | New mapping | Permissions | Rule |
  24. +===================+===================+===================+==================+
  25. | Anonymous | Anonymous | Read | Allow |
  26. +-------------------+-------------------+-------------------+------------------+
  27. | Anonymous | Anonymous | Read / Write | Prohibit |
  28. +-------------------+-------------------+-------------------+------------------+
  29. | Anonymous | Named | Any | Prohibit |
  30. +-------------------+-------------------+-------------------+------------------+
  31. | Named | Anonymous | Any | Prohibit |
  32. +-------------------+-------------------+-------------------+------------------+
  33. | Named | Named | Any | Allow |
  34. +-------------------+-------------------+-------------------+------------------+
  35. Enabling Page Table Check
  36. =========================
  37. Build kernel with:
  38. - PAGE_TABLE_CHECK=y
  39. Note, it can only be enabled on platforms where ARCH_SUPPORTS_PAGE_TABLE_CHECK
  40. is available.
  41. - Boot with 'page_table_check=on' kernel parameter.
  42. Optionally, build kernel with PAGE_TABLE_CHECK_ENFORCED in order to have page
  43. table support without extra kernel parameter.
  44. Implementation notes
  45. ====================
  46. We specifically decided not to use VMA information in order to avoid relying on
  47. MM states (except for limited "struct page" info). The page table check is a
  48. separate from Linux-MM state machine that verifies that the user accessible
  49. pages are not falsely shared.
  50. PAGE_TABLE_CHECK depends on EXCLUSIVE_SYSTEM_RAM. The reason is that without
  51. EXCLUSIVE_SYSTEM_RAM, users are allowed to map arbitrary physical memory
  52. regions into the userspace via /dev/mem. At the same time, pages may change
  53. their properties (e.g., from anonymous pages to named pages) while they are
  54. still being mapped in the userspace, leading to "corruption" detected by the
  55. page table check.
  56. Even with EXCLUSIVE_SYSTEM_RAM, I/O pages may be still allowed to be mapped via
  57. /dev/mem. However, these pages are always considered as named pages, so they
  58. won't break the logic used in the page table check.