요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
======================
Kernel page table dump
======================
ptdump is a debugfs interface that provides a detailed dump of the
kernel page tables. It offers a comprehensive overview of the kernel
virtual memory layout as well as the attributes associated with the
various regions in a human-readable format. It is useful to dump the
kernel page tables to verify permissions and memory types. Examining the
page table entries and permissions helps identify potential security
vulnerabilities such as mappings with overly permissive access rights or
improper memory protections.
Memory hotplug allows dynamic expansion or contraction of available
memory without requiring a system reboot. To maintain the consistency
and integrity of the memory management data structures, arm64 makes use
of the ``mem_hotplug_lock`` semaphore in write mode. Additionally, in
read mode, ``mem_hotplug_lock`` supports an efficient implementation of
``get_online_mems()`` and ``put_online_mems()``. These protect the
offlining of memory being accessed by the ptdump code.
In order to dump the kernel page tables, enable the following
configurations and mount debugfs::
CONFIG_PTDUMP_DEBUGFS=y
mount -t debugfs nodev /sys/kernel/debug
cat /sys/kernel/debug/kernel_page_tables
On analysing the output of ``cat /sys/kernel/debug/kernel_page_tables``
one can derive information about the virtual address range of the entry,
followed by size of the memory region covered by this entry, the
hierarchical structure of the page tables and finally the attributes
associated with each page. The page attributes provide information about
access permissions, execution capability, type of mapping such as leaf
level PTE or block level PGD, PMD and PUD, and access status of a page
within the kernel memory. Assessing these attributes can assist in
understanding the memory layout, access patterns and security
characteristics of the kernel pages.
Kernel virtual memory layout example::
start address end address size attributes
+---------------------------------------------------------------------------------------+
| ---[ Linear Mapping start ]---------------------------------------------------------- |
| .................. |
| 0xfff0000000000000-0xfff0000000210000 2112K PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED |
| 0xfff0000000210000-0xfff0000001c00000 26560K PTE ro NX SHD AF UXN MEM/NORMAL |
| .................. |
| ---[ Linear Mapping end ]------------------------------------------------------------ |
+---------------------------------------------------------------------------------------+
| ---[ Modules start ]----------------------------------------------------------------- |
| .................. |
| 0xffff800000000000-0xffff800008000000 128M PTE |
| .................. |
| ---[ Modules end ]------------------------------------------------------------------- |
+---------------------------------------------------------------------------------------+
| ---[ vmalloc() area ]---------------------------------------------------------------- |
| .................. |
| 0xffff800008010000-0xffff800008200000 1984K PTE ro x SHD AF UXN MEM/NORMAL |
| 0xffff800008200000-0xffff800008e00000 12M PTE ro x SHD AF CON UXN MEM/NORMAL |
| .................. |
| ---[ vmalloc() end ]----------------------------------------------------------------- |
+---------------------------------------------------------------------------------------+
| ---[ Fixmap start ]------------------------------------------------------------------ |
| .................. |
| 0xfffffbfffdb80000-0xfffffbfffdb90000 64K PTE ro x SHD AF UXN MEM/NORMAL |
| 0xfffffbfffdb90000-0xfffffbfffdba0000 64K PTE ro NX SHD AF UXN MEM/NORMAL |
| .................. |
| ---[ Fixmap end ]-------------------------------------------------------------------- |
+---------------------------------------------------------------------------------------+
| ---[ PCI I/O start ]----------------------------------------------------------------- |
| .................. |
| 0xfffffbfffe800000-0xfffffbffff800000 16M PTE |
| .................. |
| ---[ PCI I/O end ]------------------------------------------------------------------- |
+---------------------------------------------------------------------------------------+
| ---[ vmemmap start ]----------------------------------------------------------------- |
| .................. |
| 0xfffffc0002000000-0xfffffc0002200000 2M PTE RW NX SHD AF UXN MEM/NORMAL |
| 0xfffffc0002200000-0xfffffc0020000000 478M PTE |
| .................. |
| ---[ vmemmap end ]------------------------------------------------------------------- |
+---------------------------------------------------------------------------------------+
``cat /sys/kernel/debug/kernel_page_tables`` output::
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
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-40Kernel 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 range | Entry가 덮는 시작 주소와 끝 주소 |
| Size | Entry가 덮는 memory 영역 크기 |
| Hierarchy | Leaf `PTE` 또는 block-level `PGD`, `PMD`, `PUD` |
| Permission | Read/write, read-only, executable 또는 NX/UXN |
| Memory와 access | Mapping 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
요약과 해설
ptdump.rst:1-94`ptdump`는 kernel VA 영역별 page-table level, permission, execution 가능성, memory type을 읽기 쉬운 형태로 보여 줍니다. 원문의 큰 ASCII 상자는 아래 구조화 영역 지도와 전문 번역 표로 다시 구성했습니다.
Debugfs 출력에서 과도한 permission과 잘못된 protection을 찾는 과정입니다.
원문 ASCII diagram의 여섯 구간을 주소 순서대로 구조화했습니다.