← Documents Documentation/arch/arm64/ptdump.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Kernel Page Table Dump

Debugfs ptdump 설정, memory hotplug 동기화, page-table hierarchy와 permission 출력 해석을 설명합니다.

Source pathDocumentation/arch/arm64/ptdump.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약과 해설

ptdump.rst:1-94

`ptdump`는 kernel VA 영역별 page-table level, permission, execution 가능성, memory type을 읽기 쉬운 형태로 보여 줍니다. 원문의 큰 ASCII 상자는 아래 구조화 영역 지도와 전문 번역 표로 다시 구성했습니다.

ptdump 검사 흐름
`CONFIG_PTDUMP_DEBUGFS=y`debugfs mount`kernel_page_tables` 읽기Range/size 확인Hierarchy/attribute 검토

Debugfs 출력에서 과도한 permission과 잘못된 protection을 찾는 과정입니다.

Kernel VA 영역 지도
순서영역원문 sample 특성
1Linear Mapping`RW NX`, `ro NX`, Normal/Tagged
2Modules128M `PTE`
3vmalloc()`ro x`, Normal
4Fixmap`ro x`와 `ro NX`
5PCI I/O16M `PTE`
6vmemmap`RW NX`, 2M + 478M

원문 ASCII diagram의 여섯 구간을 주소 순서대로 구조화했습니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 ======================
2 Kernel page table dump
3 ======================
4
5 ptdump is a debugfs interface that provides a detailed dump of the
6 kernel page tables. It offers a comprehensive overview of the kernel
7 virtual memory layout as well as the attributes associated with the
8 various regions in a human-readable format. It is useful to dump the
9 kernel page tables to verify permissions and memory types. Examining the
10 page table entries and permissions helps identify potential security
11 vulnerabilities such as mappings with overly permissive access rights or
12 improper memory protections.
13
14 Memory hotplug allows dynamic expansion or contraction of available
15 memory without requiring a system reboot. To maintain the consistency
16 and integrity of the memory management data structures, arm64 makes use
17 of the ``mem_hotplug_lock`` semaphore in write mode. Additionally, in
18 read mode, ``mem_hotplug_lock`` supports an efficient implementation of
19 ``get_online_mems()`` and ``put_online_mems()``. These protect the
20 offlining of memory being accessed by the ptdump code.
21
22 In order to dump the kernel page tables, enable the following
23 configurations and mount debugfs::
24
25 CONFIG_PTDUMP_DEBUGFS=y
26
27 mount -t debugfs nodev /sys/kernel/debug
28 cat /sys/kernel/debug/kernel_page_tables
29
30 On analysing the output of ``cat /sys/kernel/debug/kernel_page_tables``
31 one can derive information about the virtual address range of the entry,
32 followed by size of the memory region covered by this entry, the
33 hierarchical structure of the page tables and finally the attributes
34 associated with each page. The page attributes provide information about
35 access permissions, execution capability, type of mapping such as leaf
36 level PTE or block level PGD, PMD and PUD, and access status of a page
37 within the kernel memory. Assessing these attributes can assist in
38 understanding the memory layout, access patterns and security
39 characteristics of the kernel pages.
40
41 Kernel virtual memory layout example::
42
43 start address end address size attributes
44 +---------------------------------------------------------------------------------------+
45 | ---[ Linear Mapping start ]---------------------------------------------------------- |
46 | .................. |
47 | 0xfff0000000000000-0xfff0000000210000 2112K PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED |
48 | 0xfff0000000210000-0xfff0000001c00000 26560K PTE ro NX SHD AF UXN MEM/NORMAL |
49 | .................. |
50 | ---[ Linear Mapping end ]------------------------------------------------------------ |
51 +---------------------------------------------------------------------------------------+
52 | ---[ Modules start ]----------------------------------------------------------------- |
53 | .................. |
54 | 0xffff800000000000-0xffff800008000000 128M PTE |
55 | .................. |
56 | ---[ Modules end ]------------------------------------------------------------------- |
57 +---------------------------------------------------------------------------------------+
58 | ---[ vmalloc() area ]---------------------------------------------------------------- |
59 | .................. |
60 | 0xffff800008010000-0xffff800008200000 1984K PTE ro x SHD AF UXN MEM/NORMAL |
61 | 0xffff800008200000-0xffff800008e00000 12M PTE ro x SHD AF CON UXN MEM/NORMAL |
62 | .................. |
63 | ---[ vmalloc() end ]----------------------------------------------------------------- |
64 +---------------------------------------------------------------------------------------+
65 | ---[ Fixmap start ]------------------------------------------------------------------ |
66 | .................. |
67 | 0xfffffbfffdb80000-0xfffffbfffdb90000 64K PTE ro x SHD AF UXN MEM/NORMAL |
68 | 0xfffffbfffdb90000-0xfffffbfffdba0000 64K PTE ro NX SHD AF UXN MEM/NORMAL |
69 | .................. |
70 | ---[ Fixmap end ]-------------------------------------------------------------------- |
71 +---------------------------------------------------------------------------------------+
72 | ---[ PCI I/O start ]----------------------------------------------------------------- |
73 | .................. |
74 | 0xfffffbfffe800000-0xfffffbffff800000 16M PTE |
75 | .................. |
76 | ---[ PCI I/O end ]------------------------------------------------------------------- |
77 +---------------------------------------------------------------------------------------+
78 | ---[ vmemmap start ]----------------------------------------------------------------- |
79 | .................. |
80 | 0xfffffc0002000000-0xfffffc0002200000 2M PTE RW NX SHD AF UXN MEM/NORMAL |
81 | 0xfffffc0002200000-0xfffffc0020000000 478M PTE |
82 | .................. |
83 | ---[ vmemmap end ]------------------------------------------------------------------- |
84 +---------------------------------------------------------------------------------------+
85
86 ``cat /sys/kernel/debug/kernel_page_tables`` output::
87
88 0xfff0000001c00000-0xfff0000080000000 2020M PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED
89 0xfff0000080000000-0xfff0000800000000 30G PMD
90 0xfff0000800000000-0xfff0000800700000 7M PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED
91 0xfff0000800700000-0xfff0000800710000 64K PTE ro NX SHD AF UXN MEM/NORMAL-TAGGED
92 0xfff0000800710000-0xfff0000880000000 2089920K PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED
93 0xfff0000880000000-0xfff0040000000000 4062G PMD
94 0xfff0040000000000-0xffff800000000000 3964T PGD
95

3. 한국어 전문 번역

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

ptdump의 목적과 동시성 보호

1-21

`ptdump`는 kernel page table을 자세히 dump하는 debugfs interface입니다. 사람이 읽을 수 있는 형식으로 kernel virtual memory layout과 각 영역의 attribute를 보여 주므로 permission과 memory type을 검증하는 데 유용합니다.

Page-table entry와 permission을 검사하면 지나치게 넓은 access right나 잘못된 memory protection 같은 잠재적인 보안 취약점을 찾는 데 도움이 됩니다.

Memory hotplug는 reboot 없이 가용 memory를 늘리거나 줄입니다. Arm64는 memory-management data structure의 일관성과 무결성을 위해 `mem_hotplug_lock` semaphore를 write mode로 사용합니다. Read mode에서는 `get_online_mems()`와 `put_online_mems()`를 효율적으로 구현해 ptdump가 접근 중인 memory가 offline되는 것을 막습니다.

설정과 출력 해석

22-40

Kernel page table을 dump하려면 다음 config를 enable하고 debugfs를 mount한 뒤 interface를 읽습니다.

CONFIG_PTDUMP_DEBUGFS=y

mount -t debugfs nodev /sys/kernel/debug
cat /sys/kernel/debug/kernel_page_tables

`cat /sys/kernel/debug/kernel_page_tables` 출력은 entry의 virtual address range, 영역 size, page-table hierarchy, 각 page의 attribute 순서로 정보를 제공합니다.

출력 요소의미
Address rangeEntry가 덮는 시작 주소와 끝 주소
SizeEntry가 덮는 memory 영역 크기
HierarchyLeaf `PTE` 또는 block-level `PGD`, `PMD`, `PUD`
PermissionRead/write, read-only, executable 또는 NX/UXN
Memory와 accessMapping type, sharing, access flag 등

이 attribute를 평가하면 kernel page의 memory layout, access pattern, 보안 특성을 이해할 수 있습니다.

구조화한 kernel virtual memory 배치 예

41-85

원문의 ASCII 상자를 같은 정보의 구조화 표로 다시 그렸습니다. 생략 표시는 제외하고 원문에 제시된 모든 sample mapping을 순서대로 보존했습니다.

영역주소 범위크기Attribute
Linear Mapping`0xfff0000000000000-0xfff0000000210000``2112K``PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED`
Linear Mapping`0xfff0000000210000-0xfff0000001c00000``26560K``PTE ro NX SHD AF UXN MEM/NORMAL`
Modules`0xffff800000000000-0xffff800008000000``128M``PTE`
vmalloc()`0xffff800008010000-0xffff800008200000``1984K``PTE ro x SHD AF UXN MEM/NORMAL`
vmalloc()`0xffff800008200000-0xffff800008e00000``12M``PTE ro x SHD AF CON UXN MEM/NORMAL`
Fixmap`0xfffffbfffdb80000-0xfffffbfffdb90000``64K``PTE ro x SHD AF UXN MEM/NORMAL`
Fixmap`0xfffffbfffdb90000-0xfffffbfffdba0000``64K``PTE ro NX SHD AF UXN MEM/NORMAL`
PCI I/O`0xfffffbfffe800000-0xfffffbffff800000``16M``PTE`
vmemmap`0xfffffc0002000000-0xfffffc0002200000``2M``PTE RW NX SHD AF UXN MEM/NORMAL`
vmemmap`0xfffffc0002200000-0xfffffc0020000000``478M``PTE`

실제 출력 예

86-94

다음은 `cat /sys/kernel/debug/kernel_page_tables`의 원문 출력 예입니다. 주소와 크기, `PTE`/`PMD`/`PGD` hierarchy 및 attribute를 그대로 보존했습니다.

0xfff0000001c00000-0xfff0000080000000     2020M PTE  RW NX SHD AF   UXN    MEM/NORMAL-TAGGED
0xfff0000080000000-0xfff0000800000000       30G PMD
0xfff0000800000000-0xfff0000800700000        7M PTE  RW NX SHD AF   UXN    MEM/NORMAL-TAGGED
0xfff0000800700000-0xfff0000800710000       64K PTE  ro NX SHD AF   UXN    MEM/NORMAL-TAGGED
0xfff0000800710000-0xfff0000880000000  2089920K PTE  RW NX SHD AF   UXN    MEM/NORMAL-TAGGED
0xfff0000880000000-0xfff0040000000000     4062G PMD
0xfff0040000000000-0xffff800000000000     3964T PGD