← Documents Documentation/mm/page_table_check.rst GitHub 원문 ↗

Linux 6.18.37 · Memory management

Page Table Check

Userspace page mapping을 동기 검사해 double mapping과 잘못된 entry-flag 조합을 조기에 찾는 hardening 기능입니다.

Source pathDocumentation/mm/page_table_check.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

page_table_check.rst:1-80

Page table check는 PTE·PMD가 userspace page를 노출하는 순간 mapping을 동기 검사합니다. Anonymous writable double mapping과 anonymous·named 교차 mapping을 금지하며, 별도 Linux-MM state machine으로 동작해 잘못된 mapping이 생긴 지점에서 문제를 드러냅니다.

Double mapping 검출 규칙
Current mappingNew mappingPermissionsRule
AnonymousAnonymousReadAllow
AnonymousAnonymousRead / WriteProhibit
AnonymousNamedAnyProhibit
NamedAnonymousAnyProhibit
NamedNamedAnyAllow

원문의 ASCII 표를 같은 행과 의미의 구조화 표로 옮겼습니다.

Page Table Check 활성화
`ARCH_SUPPORTS_PAGE_TABLE_CHECK``PAGE_TABLE_CHECK=y``page_table_check=on`동기 mapping 검사
`PAGE_TABLE_CHECK_ENFORCED`추가 boot parameter 없이 지원동기 mapping 검사

Platform 지원, build option과 boot parameter의 관계입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ================
4 Page Table Check
5 ================
6
7 Introduction
8 ============
9
10 Page table check allows to harden the kernel by ensuring that some types of
11 the memory corruptions are prevented.
12
13 Page table check performs extra verifications at the time when new pages become
14 accessible from the userspace by getting their page table entries (PTEs PMDs
15 etc.) added into the table.
16
17 In case of most detected corruption, the kernel is crashed. There is a small
18 performance and memory overhead associated with the page table check. Therefore,
19 it is disabled by default, but can be optionally enabled on systems where the
20 extra hardening outweighs the performance costs. Also, because page table check
21 is synchronous, it can help with debugging double map memory corruption issues,
22 by crashing kernel at the time wrong mapping occurs instead of later which is
23 often the case with memory corruptions bugs.
24
25 It can also be used to do page table entry checks over various flags, dump
26 warnings when illegal combinations of entry flags are detected. Currently,
27 userfaultfd is the only user of such to sanity check wr-protect bit against
28 any writable flags. Illegal flag combinations will not directly cause data
29 corruption in this case immediately, but that will cause read-only data to
30 be writable, leading to corrupt when the page content is later modified.
31
32 Double mapping detection logic
33 ==============================
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
49 Enabling Page Table Check
50 =========================
51
52 Build kernel with:
53
54 - PAGE_TABLE_CHECK=y
55 Note, it can only be enabled on platforms where ARCH_SUPPORTS_PAGE_TABLE_CHECK
56 is available.
57
58 - Boot with 'page_table_check=on' kernel parameter.
59
60 Optionally, build kernel with PAGE_TABLE_CHECK_ENFORCED in order to have page
61 table support without extra kernel parameter.
62
63 Implementation notes
64 ====================
65
66 We specifically decided not to use VMA information in order to avoid relying on
67 MM states (except for limited "struct page" info). The page table check is a
68 separate from Linux-MM state machine that verifies that the user accessible
69 pages are not falsely shared.
70
71 PAGE_TABLE_CHECK depends on EXCLUSIVE_SYSTEM_RAM. The reason is that without
72 EXCLUSIVE_SYSTEM_RAM, users are allowed to map arbitrary physical memory
73 regions into the userspace via /dev/mem. At the same time, pages may change
74 their properties (e.g., from anonymous pages to named pages) while they are
75 still being mapped in the userspace, leading to "corruption" detected by the
76 page table check.
77
78 Even with EXCLUSIVE_SYSTEM_RAM, I/O pages may be still allowed to be mapped via
79 /dev/mem. However, these pages are always considered as named pages, so they
80 won't break the logic used in the page table check.
81

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Page table check 개요

1-31

Page table check는 일부 memory corruption을 예방하도록 검사해 kernel을 강화합니다. 새 page가 page table에 PTE, PMD 등의 entry를 얻어 userspace에서 접근 가능해지는 시점에 추가 verification을 수행합니다.

검출한 corruption 대부분은 kernel crash로 이어집니다. Page table check에는 작은 performance와 memory overhead가 있어 기본적으로 disable되어 있습니다. 추가 hardening의 가치가 비용보다 큰 system에서 선택적으로 enable할 수 있습니다.

검사가 synchronous이므로 잘못된 mapping이 생긴 바로 그 시점에 kernel을 crash시킵니다. Memory-corruption bug가 나중에 드러나는 일반적인 경우보다 double-map corruption을 debug하기 쉽습니다.

여러 flag에 대한 page-table entry 검사에도 사용할 수 있으며, entry flag의 잘못된 조합을 발견하면 warning을 dump합니다. 현재는 `userfaultfd`만 이 기능으로 write-protect bit와 writable flag가 모순되지 않는지 sanity check합니다.

이 경우 잘못된 flag 조합이 즉시 data corruption을 일으키지는 않지만 read-only data를 writable하게 만들어, 나중에 page 내용을 수정할 때 corruption으로 이어집니다.

.. SPDX-License-Identifier: GPL-2.0

================
Page Table Check
================

Introduction
============

Page table check allows to harden the kernel by ensuring that some types of
the memory corruptions are prevented.

Page table check performs extra verifications at the time when new pages become
accessible from the userspace by getting their page table entries (PTEs PMDs
etc.) added into the table.

In case of most detected corruption, the kernel is crashed. There is a small
performance and memory overhead associated with the page table check. Therefore,
it is disabled by default, but can be optionally enabled on systems where the
extra hardening outweighs the performance costs. Also, because page table check
is synchronous, it can help with debugging double map memory corruption issues,
by crashing kernel at the time wrong mapping occurs instead of later which is
often the case with memory corruptions bugs.

It can also be used to do page table entry checks over various flags, dump
warnings when illegal combinations of entry flags are detected.  Currently,
userfaultfd is the only user of such to sanity check wr-protect bit against
any writable flags.  Illegal flag combinations will not directly cause data
corruption in this case immediately, but that will cause read-only data to
be writable, leading to corrupt when the page content is later modified.

Double-mapping 검출 규칙

32-48

현재 mapping과 새 mapping의 유형 및 permission에 따라 다음 규칙을 적용합니다.

  • Anonymous에서 Anonymous로 read-only mapping을 추가하는 것은 허용합니다.
  • Anonymous에서 Anonymous로 read/write mapping을 추가하는 것은 금지합니다.
  • Anonymous와 named mapping을 어느 방향으로든 섞는 것은 permission과 관계없이 금지합니다.
  • Named에서 named mapping을 추가하는 것은 permission과 관계없이 허용합니다.
Double mapping detection logic
==============================

+-------------------+-------------------+-------------------+------------------+
| Current Mapping   | New mapping       | Permissions       | Rule             |
+===================+===================+===================+==================+
| Anonymous         | Anonymous         | Read              | Allow            |
+-------------------+-------------------+-------------------+------------------+
| Anonymous         | Anonymous         | Read / Write      | Prohibit         |
+-------------------+-------------------+-------------------+------------------+
| Anonymous         | Named             | Any               | Prohibit         |
+-------------------+-------------------+-------------------+------------------+
| Named             | Anonymous         | Any               | Prohibit         |
+-------------------+-------------------+-------------------+------------------+
| Named             | Named             | Any               | Allow            |
+-------------------+-------------------+-------------------+------------------+

Page Table Check enable

49-62

Kernel을 `PAGE_TABLE_CHECK=y`로 build합니다. 이 option은 `ARCH_SUPPORTS_PAGE_TABLE_CHECK`를 제공하는 platform에서만 enable할 수 있습니다.

Boot 때 `page_table_check=on` kernel parameter를 지정합니다.

별도 kernel parameter 없이 page-table check를 항상 지원하려면 선택적으로 `PAGE_TABLE_CHECK_ENFORCED`를 enable해 kernel을 build합니다.

Enabling Page Table Check
=========================

Build kernel with:

- PAGE_TABLE_CHECK=y
  Note, it can only be enabled on platforms where ARCH_SUPPORTS_PAGE_TABLE_CHECK
  is available.

- Boot with 'page_table_check=on' kernel parameter.

Optionally, build kernel with PAGE_TABLE_CHECK_ENFORCED in order to have page
table support without extra kernel parameter.

구현상 고려 사항

63-80

제한된 `struct page` 정보 외의 MM state에 의존하지 않도록 VMA 정보를 의도적으로 사용하지 않습니다. Page table check는 Linux-MM state machine과 분리되어 있으며 userspace-accessible page가 잘못 공유되지 않는지 확인합니다.

`PAGE_TABLE_CHECK`는 `EXCLUSIVE_SYSTEM_RAM`에 의존합니다. `EXCLUSIVE_SYSTEM_RAM`이 없으면 user가 `/dev/mem`으로 임의의 physical-memory 영역을 userspace에 mapping할 수 있습니다. 동시에 userspace mapping을 유지한 채 page property가 anonymous에서 named로 바뀌는 등 변화할 수 있어, page table check가 이를 corruption으로 검출하게 됩니다.

`EXCLUSIVE_SYSTEM_RAM`이 있어도 I/O page는 `/dev/mem`으로 mapping할 수 있습니다. 그러나 I/O page는 항상 named page로 취급하므로 page-table-check logic을 깨뜨리지 않습니다.

Implementation notes
====================

We specifically decided not to use VMA information in order to avoid relying on
MM states (except for limited "struct page" info). The page table check is a
separate from Linux-MM state machine that verifies that the user accessible
pages are not falsely shared.

PAGE_TABLE_CHECK depends on EXCLUSIVE_SYSTEM_RAM. The reason is that without
EXCLUSIVE_SYSTEM_RAM, users are allowed to map arbitrary physical memory
regions into the userspace via /dev/mem. At the same time, pages may change
their properties (e.g., from anonymous pages to named pages) while they are
still being mapped in the userspace, leading to "corruption" detected by the
page table check.

Even with EXCLUSIVE_SYSTEM_RAM, I/O pages may be still allowed to be mapped via
/dev/mem. However, these pages are always considered as named pages, so they
won't break the logic used in the page table check.