콘텐츠로 이동

Task 5-5: KPTI (Kernel Page Table Isolation - 유저/커널 페이지 테이블 완전 분리 및 Meltdown 방어)

1. 개요 (Overview)

1.1 기능 정의 및 핵심 목적

  • KPTI (Kernel Page Table Isolation): 유저 공간 프로세스가 실행 중일 때 커널 메모리 매핑을 가상 주소 공간에서 원천적으로 제거(Unmapping)하여, 유저/커널 간의 페이지 테이블을 완전히 분리하는 리눅스 커널의 핵심 하드웨어 격리 방어 기술임.
  • 주요 방어 대상:
  • Meltdown 취약점 (CVE-2017-5754, Rogue Data Cache Load): 비순차 투기적 실행(Out-of-Order Speculative Execution) 과정에서 CPU 권한 검사 지연을 악용하여 유저 모드에서 커널 메모리를 불법으로 읽어내는 마이크로아키텍처 공격을 하드웨어 페이지 테이블 수준에서 물리적으로 무력화함.
  • 커널 주소 유출 방지 (Kernel ASLR Bypass 완화): 유저 모드에서 커널 페이지 테이블 엔트리(PTE)를 관찰하거나 캐시 부채널로 주소를 추론하는 공격 표면을 차단함.
  • 적용 아키텍처:
  • x86_64: CONFIG_MITIGATION_PAGE_TABLE_ISOLATION=y, boot_cpu_has(X86_FEATURE_PTI), pti=on / pti=off.
  • arm64: CONFIG_UNMAP_KERNEL_AT_EL0=y (KAISER / ARM64 KPTI), arm64_kernel_unmapped_at_el0(), kpti=on / kpti=off.
flowchart TD
    subgraph PreKPTI["Pre-KPTI (Unified Page Table - 취약 구조)"]
        A1["유저 공간 코드 실행 (Ring 3 / EL0)"]
        B1["단일 PGD (동일 가상 주소 공간 공유)"]
        C1["커널 메모리 매핑 상주 (U=0 플래그로만 보호)"]
        D1["비순차 투기적 실행 (Meltdown) ➔ L1D 캐시 부채널 기밀 유출 가능"]
        A1 --> B1
        B1 --> C1
        C1 -.->|투기적 읽기 허용| D1
    end

    subgraph PostKPTI["KPTI (Dual PGD / Split Page Table - 하드닝 구조)"]
        A2["유저 공간 코드 실행 (Ring 3 / EL0)"]
        B2["유저 모드 전용 PGD (CR3 bit 12 = 1 / Trampoline TTBR1)"]
        C2["커널 주소 공간 완전 언매핑 (Not-Present)"]
        D2["투기적 실행 시도 ➔ 변환 엔트리 부재로 즉시 무효화 (Meltdown 원천 차단)"]
        A2 --> B2
        B2 --> C2
        C2 -->|물리 주소 변환 불가| D2
    end

    classDef danger fill:#ef4444,stroke:#dc2626,color:#fff;
    classDef safe fill:#22c55e,stroke:#16a34a,color:#fff;
    class D1 danger;
    class D2 safe;

1.2 현실 세계 비유 (Real-World Metaphor)

"정부 기밀 문서고와 일반 열람실의 출입 카드 및 물리적 분리 체계"

  • Pre-KPTI (통합 테이블): 열람실 한가운데에 최고 기밀 문서 보관함이 투명 유리벽 안에 놓여 있는 상태임. 문에는 "일반인 출입 금지" 경고문이 붙어 있으나, 비정상적인 침입자(비순차 투기적 실행)가 경비원이 달려오기 전 찰나의 순간에 유리창 너머로 문서를 훔쳐보고 자신의 수첩(CPU L1D 캐시)에 메모해 둘 수 있음.
  • KPTI (분리 테이블): 일반인이 열람실(유저 공간)에 들어올 때는 기밀 문서가 아예 존재하지 않는 별도의 방을 배정함. 기밀 문서가 있는 중앙 금고(커널 공간)는 특수 보안 카드를 찍고 진입하는 엄격한 에어락 통로(트램펄린 시스템 콜 진입점)를 거친 공무원(커널 모드)에게만 별도의 열쇠(커널 PGD)로 열어줌. 일반 열람실에서는 망원경을 동원하더라도 물리적으로 존재하는 문서가 없으므로 도청이나 투기적 훔쳐보기가 원천 불가능함.

2. 핵심 기술 메커니즘 (Technical Deep Dive)

2.1 Meltdown 공격 (CVE-2017-5754)의 본질

  1. 비순차 실행 (Out-of-Order Execution): 현대 초고성능 슈퍼스칼라 CPU는 명령어 파이프라인의 유휴 상태를 방지하기 위해 명령어의 데이터 준비가 완료되는 즉시 순서와 무관하게 먼저 연산함.
  2. 권한 검사와 실행의 시간차 (Transient Window):
    // 유저 모드(Ring 3)에서 실행되는 공격자 코드 조각
    char secret = *(char *)kernel_secret_address; // 1단계: 커널 주소 불법 역참조 (MMU #PF 유발 예정)
    char dummy  = probe_array[secret * 4096];     // 2단계: 기밀 값을 인덱스로 유저 배열 접근
    
  3. CPU는 1단계의 MMU 권한 위반 예외(#PF)를 명령어 완료 단계(Retire/Commit)에서 처리함.
  4. 예외가 커밋되기 전 마이크로아키텍처 수준에서 1단계의 secret 값이 CPU 임시 레지스터로 로드되고, 2단계의 probe_array 캐시 라인이 L1D 캐시로 인출(Fetch)됨.
  5. 예외가 발생하여 아키텍처 상태(레지스터)는 롤백되지만, L1D 캐시에 로드된 흔적(Cache State)은 남음.
  6. Flush+Reload 부채널 복원:
  7. 공격자는 probe_array[0..255 * 4096]를 사전에 캐시에서 플러시(clflush)해 둠.
  8. 예외 처리 후 256개 페이지의 접근 시간을 고정밀 타이머(rdtsc)로 측정함.
  9. 접근 시간이 현저히 짧은(예: < 80 사이클) 인덱스가 바로 유출된 secret 바이트임.

2.2 KPTI의 듀얼 PGD (Dual Page Global Directory) 분리 아키텍처

KPTI의 핵심 아이디어는 "유저 모드에서 실행 중일 때는 커널 메모리의 변환 엔트리(Translation Entry) 자체를 MMU에서 지워버린다"는 단순하면서도 강력한 원리임.

flowchart LR
    subgraph UserPGD["User PGD (CR3 bit 12 = 1)"]
        U1["User Address Space (0x0000... ~ 0x7fff...)"]
        U2["Minimal Trampoline Vector (Entry/Exit Stubs Only)"]
        U3["Kernel Space: UNMAPPED / NOT-PRESENT"]
    end

    subgraph KernelPGD["Kernel PGD (CR3 bit 12 = 0)"]
        K1["User Address Space (User copy helper)"]
        K2["Full Kernel Image & Direct Physical Mapping"]
        K3["Kernel Secrets & Data Structures"]
    end

    UserPGD -- "SYSCALL / Interrupt Entry (CR3 bit 12 = 0)" --> KernelPGD
    KernelPGD -- "SYSRET / IRET Return (CR3 bit 12 = 1)" --> UserPGD

    classDef danger fill:#ef4444,stroke:#dc2626,color:#fff;
    classDef safe fill:#22c55e,stroke:#16a34a,color:#fff;
    classDef tramp fill:#a855f7,stroke:#9333ea,color:#fff;
    class U3 danger;
    class K2,K3 safe;
    class U2 tramp;

1) x86_64 듀얼 CR3 스위칭 메커니즘

  • x86_64에서 각 프로세스는 두 세트의 최상위 페이지 테이블(PGD)을 인접한 8KB 영역에 할당받음:
  • Kernel PGD: 물리 주소 P (CR3 레지스터 기준 4KB 정렬)
  • User PGD: 물리 주소 P + 0x1000 (4096바이트 오프셋, PTI_USER_PGTABLE_BIT = bit 12)
  • 유저 모드로 전환 시: SWITCH_TO_USER_CR3 매크로가 CR3의 12번 비트를 세트하여 User PGD를 활성화함.
  • 커널 모드로 진입 시: SAVE_AND_SWITCH_TO_KERNEL_CR3 매크로가 CR3의 12번 비트를 클리어하여 Kernel PGD를 활성화함.
  • 트램펄린(Trampoline) 영역: 인터럽트 디스크립터 테이블(IDT), 시스템 콜 진입점(entry_SYSCALL_64), TSS, GDT 등 CPU가 유저에서 커널로 전환하기 위해 필수적인 극소수의 페이지만 User PGD에 남겨둠.

2) ARM64 UNMAP_KERNEL_AT_EL0 메커니즘

  • ARM64는 하드웨어적으로 2개의 변환 테이블 베이스 레지스터를 보유함:
  • TTBR0_EL1: 유저 공간 주소 번역 (0x0000_0000_0000_0000 ~)
  • TTBR1_EL1: 커널 공간 주소 번역 (0xffff_0000_0000_0000 ~)
  • CONFIG_UNMAP_KERNEL_AT_EL0 활성화 시:
  • EL0(유저)에서 실행되는 동안 TTBR1_EL1은 커널 전체가 아닌 최소 트램펄린 벡터 페이지(tramp_vectors)만을 가리키도록 설정됨.
  • EL0 ➔ EL1 예외 발생 시 트램펄린 벡터가 TTBR1_EL1을 실제 swapper_pg_dir로 전환하고 메인 커널 핸들러로 분기함.
  • EL1 ➔ EL0 복귀 시 다시 트램펄린 페이지로 TTBR1_EL1을 복원함.

2.3 성능 최적화: PCID (x86) 및 ASID (ARM64)

  • 과거 문제점: CR3 레지스터를 쓸 때마다 CPU는 전체 TLB(Translation Lookaside Buffer)를 플러시하여, 시스템 콜 빈도가 높은 워크로드에서 5%~30%에 달하는 막대한 성능 저하가 발생함.
  • PCID (Process Context Identifiers, x86):
  • CR3 하위 11비트에 프로세스 ID 태그(0~4095)를 부여하고, CR3의 63번 비트(NOFLUSH)를 세트하여 CR3 쓰기 시 기존 TLB 항목을 보존함.
  • KPTI는 Kernel PGD와 User PGD에 서로 다른 PCID를 할당하여, 유저/커널 전환 시 TLB 플러시를 0으로 만들어 오버헤드를 1~3% 수준으로 억제함.
  • ASID (Address Space Identifier, ARM64):
  • ARM64의 하드웨어 ASID 태깅 메커니즘을 동일하게 활용하여 TLB 무효화 오버헤드를 방지함.

3. 인터랙티브 아키텍처 다이어그램

아래 링크를 브라우저에서 열어 KPTI의 4가지 동작 시나리오(통합 테이블 취약성, Meltdown 공격 경로, 분리 테이블 방어, CR3 전환 흐름)를 인터랙티브하게 확인할 수 있음:


4. 실측 검증 및 텔레메트리 (Dual-Arch QEMU)

4.1 x86_64 실측 로그 (Base vs Hardened)

[Base] x86_64 KPTI 비활성화 (pti=off nopti)

=========================================================
  [Test 1/3] Kernel Command Line & Sysfs Vulnerability Status
=========================================================
Kernel cmdline: console=ttyS0 quiet panic=1 nokaslr lab_test=test_kpti pti=off nopti
Meltdown status: Vulnerable
KPTI Configuration: DISABLED (boot override active)

=========================================================
  [Test 2/3] Kernel KPTI Hardware Telemetry (/proc/vuln_kpti)
=========================================================
ARCHITECTURE:             x86_64
FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
CONFIG_PAGE_TABLE_ISOL:   ENABLED (y)
CONFIG_UNMAP_KERNEL_EL0:  DISABLED (n)
HARDWARE_KPTI_ACTIVE:     NO (Disabled / Inactive)
PAGE_TABLE_SEPARATION:    UNIFIED (Kernel addresses shared in user page tables)
PGD_REGISTER_TYPE:        CR3 (Page Global Directory Base)
CURRENT_PGD_REGISTER:     0x0000000004210000
MELTDOWN_MITIGATION:      VULNERABLE (Meltdown speculative cache side-channel possible)
KERNEL_SECRET_ADDR:       0xffffffff8260a040
KERNEL_SECRET_MAGIC:      0x4b50544953454352
LAST_PROBE_ADDR:          0x0000000000000000
LAST_PROBE_RESULT:        NOT_TESTED

=========================================================
  [Test 3/3] Non-Privileged User PoC Demonstration
  Target: /proc/vuln_kpti
  Runner: lab (UID 1000, non-privileged)
=========================================================
=========================================================
  Linux Kernel Hardening Lab - KPTI Verification PoC
  Target: Task 5-5: Kernel Page Table Isolation & Meltdown
  Architecture: x86_64
  Current User: UID = 1000 (non-root 'lab' user)
=========================================================
[*] 1. Inspecting CPU Vulnerabilities Interface (/sys/devices/system/cpu/vulnerabilities/meltdown):
    Meltdown Mitigation Status: Vulnerable

[*] 2. Querying Kernel KPTI Telemetry (/proc/vuln_kpti):
    ARCHITECTURE:             x86_64
    FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
    CONFIG_PAGE_TABLE_ISOL:   ENABLED (y)
    CONFIG_UNMAP_KERNEL_EL0:  DISABLED (n)
    HARDWARE_KPTI_ACTIVE:     NO (Disabled / Inactive)
    PAGE_TABLE_SEPARATION:    UNIFIED (Kernel addresses shared in user page tables)
    PGD_REGISTER_TYPE:        CR3 (Page Global Directory Base)
    CURRENT_PGD_REGISTER:     0x0000000004210000
    MELTDOWN_MITIGATION:      VULNERABLE (Meltdown speculative cache side-channel possible)
    KERNEL_SECRET_ADDR:       0xffffffff8260a040
    KERNEL_SECRET_MAGIC:      0x4b50544953454352

=========================================================
[*] 3. Probing Kernel Address Space Isolation via Driver...
    Probing Kernel Address: 0xffffffff8260a040
=========================================================

[*] 4. Post-Probe Telemetry Verification:
    MELTDOWN_MITIGATION:      VULNERABLE (Meltdown speculative cache side-channel possible)
    LAST_PROBE_ADDR:          0xffffffff8260a040
    LAST_PROBE_RESULT:        UNPROTECTED (Kernel address visible in user page tables)

[!] =========================================================
[!] BASELINE CONFIRMED (KPTI Disabled):
[!] Kernel address space is shared within user page tables.
[!] System lacks complete address space isolation between user & kernel.
[!] Vulnerable to Meltdown speculative data leakage!
[!] =========================================================

=========================================================
  Kernel Ring Buffer (dmesg) Security Events
=========================================================
[    0.000000] Command line: console=ttyS0 quiet panic=1 nokaslr lab_test=test_kpti pti=off nopti
[    0.118220] Kernel/User page tables isolation: disabled on command line.
[    1.520410] [vuln_kpti] Initialized /proc/vuln_kpti (kpti active: 0)
[    2.821040] [vuln_kpti] Received probe request for address 0xffffffff8260a040
[    2.821110] [vuln_kpti] [!] WARNING: KPTI is disabled (pti=off / kpti=off)!
[    2.821140] [vuln_kpti] [!] Kernel address space remains mapped in user page tables.

[Hardened] x86_64 KPTI 활성화 (pti=on)

=========================================================
  [Test 1/3] Kernel Command Line & Sysfs Vulnerability Status
=========================================================
Kernel cmdline: console=ttyS0 quiet panic=1 nokaslr lab_test=test_kpti pti=on
Meltdown status: Mitigation: PTI
KPTI Configuration: ACTIVE (pti=on / kpti=on enforced)

=========================================================
  [Test 2/3] Kernel KPTI Hardware Telemetry (/proc/vuln_kpti)
=========================================================
ARCHITECTURE:             x86_64
FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
CONFIG_PAGE_TABLE_ISOL:   ENABLED (y)
CONFIG_UNMAP_KERNEL_EL0:  DISABLED (n)
HARDWARE_KPTI_ACTIVE:     YES (Enforced via CPU / MMU)
PAGE_TABLE_SEPARATION:    ISOLATED (Kernel unmapped from user address space)
PGD_REGISTER_TYPE:        CR3 (Page Global Directory Base)
CURRENT_PGD_REGISTER:     0x0000000004210000
MELTDOWN_MITIGATION:      MITIGATED (Meltdown rogue data cache load blocked by unmapping)
KERNEL_SECRET_ADDR:       0xffffffff8260a040
KERNEL_SECRET_MAGIC:      0x4b50544953454352
LAST_PROBE_ADDR:          0x0000000000000000
LAST_PROBE_RESULT:        NOT_TESTED

=========================================================
  [Test 3/3] Non-Privileged User PoC Demonstration
  Target: /proc/vuln_kpti
  Runner: lab (UID 1000, non-privileged)
=========================================================
=========================================================
  Linux Kernel Hardening Lab - KPTI Verification PoC
  Target: Task 5-5: Kernel Page Table Isolation & Meltdown
  Architecture: x86_64
  Current User: UID = 1000 (non-root 'lab' user)
=========================================================
[*] 1. Inspecting CPU Vulnerabilities Interface (/sys/devices/system/cpu/vulnerabilities/meltdown):
    Meltdown Mitigation Status: Mitigation: PTI

[*] 2. Querying Kernel KPTI Telemetry (/proc/vuln_kpti):
    ARCHITECTURE:             x86_64
    FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
    CONFIG_PAGE_TABLE_ISOL:   ENABLED (y)
    CONFIG_UNMAP_KERNEL_EL0:  DISABLED (n)
    HARDWARE_KPTI_ACTIVE:     YES (Enforced via CPU / MMU)
    PAGE_TABLE_SEPARATION:    ISOLATED (Kernel unmapped from user address space)
    PGD_REGISTER_TYPE:        CR3 (Page Global Directory Base)
    CURRENT_PGD_REGISTER:     0x0000000004210000
    MELTDOWN_MITIGATION:      MITIGATED (Meltdown rogue data cache load blocked by unmapping)
    KERNEL_SECRET_ADDR:       0xffffffff8260a040
    KERNEL_SECRET_MAGIC:      0x4b50544953454352

=========================================================
[*] 3. Probing Kernel Address Space Isolation via Driver...
    Probing Kernel Address: 0xffffffff8260a040
=========================================================

[*] 4. Post-Probe Telemetry Verification:
    MELTDOWN_MITIGATION:      MITIGATED (Meltdown rogue data cache load blocked by unmapping)
    LAST_PROBE_ADDR:          0xffffffff8260a040
    LAST_PROBE_RESULT:        PROTECTED (Kernel address unmapped in user mode)

[+] =========================================================
[+] HARDENING VERIFIED (KPTI / Meltdown Mitigation Active):
[+] Dual PGDs / Trampoline Vectors strictly separate address spaces!
[+] Kernel address space is completely unmapped in user mode (Ring 3/EL0).
[+] Meltdown rogue data cache load side-channel attacks are mitigated.
[+] =========================================================

=========================================================
  Kernel Ring Buffer (dmesg) Security Events
=========================================================
[    0.000000] Command line: console=ttyS0 quiet panic=1 nokaslr lab_test=test_kpti pti=on
[    0.119050] Kernel/User page tables isolation: enabled
[    1.531200] [vuln_kpti] Initialized /proc/vuln_kpti (kpti active: 1)
[    2.791020] [vuln_kpti] Received probe request for address 0xffffffff8260a040
[    2.791100] [vuln_kpti] [+] DEFENSE ACTIVE: Kernel Page Table Isolation is enforced!
[    2.791125] [vuln_kpti] [+] User page tables do NOT contain kernel space mappings.

4.2 ARM64 실측 로그 (Base vs Hardened)

[Base] ARM64 KPTI 비활성화 (kpti=off)

=========================================================
  [Test 1/3] Kernel Command Line & Sysfs Vulnerability Status
=========================================================
Kernel cmdline: console=ttyAMA0 quiet panic=1 nokaslr lab_test=test_kpti kpti=off
Meltdown status: Vulnerable
KPTI Configuration: DISABLED (boot override active)

=========================================================
  [Test 2/3] Kernel KPTI Hardware Telemetry (/proc/vuln_kpti)
=========================================================
ARCHITECTURE:             arm64 (aarch64)
FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
CONFIG_PAGE_TABLE_ISOL:   DISABLED (n)
CONFIG_UNMAP_KERNEL_EL0:  ENABLED (y)
HARDWARE_KPTI_ACTIVE:     NO (Disabled / Inactive)
PAGE_TABLE_SEPARATION:    UNIFIED (Kernel addresses shared in user page tables)
PGD_REGISTER_TYPE:        TTBR1_EL1 (Kernel Translation Table Base)
CURRENT_PGD_REGISTER:     0x0000000042300000
MELTDOWN_MITIGATION:      VULNERABLE (Meltdown speculative cache side-channel possible)
KERNEL_SECRET_ADDR:       0xffff800081e05040
KERNEL_SECRET_MAGIC:      0x4b50544953454352
LAST_PROBE_ADDR:          0x0000000000000000
LAST_PROBE_RESULT:        NOT_TESTED

=========================================================
  [Test 3/3] Non-Privileged User PoC Demonstration
  Target: /proc/vuln_kpti
  Runner: lab (UID 1000, non-privileged)
=========================================================
=========================================================
  Linux Kernel Hardening Lab - KPTI Verification PoC
  Target: Task 5-5: Kernel Page Table Isolation & Meltdown
  Architecture: arm64 (aarch64)
  Current User: UID = 1000 (non-root 'lab' user)
=========================================================
[*] 1. Inspecting CPU Vulnerabilities Interface (/sys/devices/system/cpu/vulnerabilities/meltdown):
    Meltdown Mitigation Status: Vulnerable

[*] 2. Querying Kernel KPTI Telemetry (/proc/vuln_kpti):
    ARCHITECTURE:             arm64 (aarch64)
    FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
    CONFIG_PAGE_TABLE_ISOL:   DISABLED (n)
    CONFIG_UNMAP_KERNEL_EL0:  ENABLED (y)
    HARDWARE_KPTI_ACTIVE:     NO (Disabled / Inactive)
    PAGE_TABLE_SEPARATION:    UNIFIED (Kernel addresses shared in user page tables)
    PGD_REGISTER_TYPE:        TTBR1_EL1 (Kernel Translation Table Base)
    CURRENT_PGD_REGISTER:     0x0000000042300000
    MELTDOWN_MITIGATION:      VULNERABLE (Meltdown speculative cache side-channel possible)
    KERNEL_SECRET_ADDR:       0xffff800081e05040
    KERNEL_SECRET_MAGIC:      0x4b50544953454352

=========================================================
[*] 3. Probing Kernel Address Space Isolation via Driver...
    Probing Kernel Address: 0xffff800081e05040
=========================================================

[*] 4. Post-Probe Telemetry Verification:
    MELTDOWN_MITIGATION:      VULNERABLE (Meltdown speculative cache side-channel possible)
    LAST_PROBE_ADDR:          0xffff800081e05040
    LAST_PROBE_RESULT:        UNPROTECTED (Kernel address visible in user page tables)

[!] =========================================================
[!] BASELINE CONFIRMED (KPTI Disabled):
[!] Kernel address space is shared within user page tables.
[!] System lacks complete address space isolation between user & kernel.
[!] Vulnerable to Meltdown speculative data leakage!
[!] =========================================================

=========================================================
  Kernel Ring Buffer (dmesg) Security Events
=========================================================
[    0.000000] Kernel command line: console=ttyAMA0 quiet panic=1 nokaslr lab_test=test_kpti kpti=off
[    0.000000] CPU features: SANITY CHECK: Unexpected variation in SYS_CTR_EL0.
[    0.720410] [vuln_kpti] Initialized /proc/vuln_kpti (kpti active: 0)
[    1.421040] [vuln_kpti] Received probe request for address 0xffff800081e05040
[    1.421110] [vuln_kpti] [!] WARNING: KPTI is disabled (pti=off / kpti=off)!
[    1.421140] [vuln_kpti] [!] Kernel address space remains mapped in user page tables.

[Hardened] ARM64 KPTI 활성화 (kpti=on)

=========================================================
  [Test 1/3] Kernel Command Line & Sysfs Vulnerability Status
=========================================================
Kernel cmdline: console=ttyAMA0 quiet panic=1 nokaslr lab_test=test_kpti kpti=on
Meltdown status: Mitigation: PTI
KPTI Configuration: ACTIVE (pti=on / kpti=on enforced)

=========================================================
  [Test 2/3] Kernel KPTI Hardware Telemetry (/proc/vuln_kpti)
=========================================================
ARCHITECTURE:             arm64 (aarch64)
FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
CONFIG_PAGE_TABLE_ISOL:   DISABLED (n)
CONFIG_UNMAP_KERNEL_EL0:  ENABLED (y)
HARDWARE_KPTI_ACTIVE:     YES (Enforced via CPU / MMU)
PAGE_TABLE_SEPARATION:    ISOLATED (Kernel unmapped from user address space)
PGD_REGISTER_TYPE:        TTBR1_EL1 (Kernel Translation Table Base)
CURRENT_PGD_REGISTER:     0x0000000042300000
MELTDOWN_MITIGATION:      MITIGATED (Meltdown rogue data cache load blocked by unmapping)
KERNEL_SECRET_ADDR:       0xffff800081e05040
KERNEL_SECRET_MAGIC:      0x4b50544953454352
LAST_PROBE_ADDR:          0x0000000000000000
LAST_PROBE_RESULT:        NOT_TESTED

=========================================================
  [Test 3/3] Non-Privileged User PoC Demonstration
  Target: /proc/vuln_kpti
  Runner: lab (UID 1000, non-privileged)
=========================================================
=========================================================
  Linux Kernel Hardening Lab - KPTI Verification PoC
  Target: Task 5-5: Kernel Page Table Isolation & Meltdown
  Architecture: arm64 (aarch64)
  Current User: UID = 1000 (non-root 'lab' user)
=========================================================
[*] 1. Inspecting CPU Vulnerabilities Interface (/sys/devices/system/cpu/vulnerabilities/meltdown):
    Meltdown Mitigation Status: Mitigation: PTI

[*] 2. Querying Kernel KPTI Telemetry (/proc/vuln_kpti):
    ARCHITECTURE:             arm64 (aarch64)
    FEATURE_NAME:             KPTI (Kernel Page Table Isolation)
    CONFIG_PAGE_TABLE_ISOL:   DISABLED (n)
    CONFIG_UNMAP_KERNEL_EL0:  ENABLED (y)
    HARDWARE_KPTI_ACTIVE:     YES (Enforced via CPU / MMU)
    PAGE_TABLE_SEPARATION:    ISOLATED (Kernel unmapped from user address space)
    PGD_REGISTER_TYPE:        TTBR1_EL1 (Kernel Translation Table Base)
    CURRENT_PGD_REGISTER:     0x0000000042300000
    MELTDOWN_MITIGATION:      MITIGATED (Meltdown rogue data cache load blocked by unmapping)
    KERNEL_SECRET_ADDR:       0xffff800081e05040
    KERNEL_SECRET_MAGIC:      0x4b50544953454352

=========================================================
[*] 3. Probing Kernel Address Space Isolation via Driver...
    Probing Kernel Address: 0xffff800081e05040
=========================================================

[*] 4. Post-Probe Telemetry Verification:
    MELTDOWN_MITIGATION:      MITIGATED (Meltdown rogue data cache load blocked by unmapping)
    LAST_PROBE_ADDR:          0xffff800081e05040
    LAST_PROBE_RESULT:        PROTECTED (Kernel address unmapped in user mode)

[+] =========================================================
[+] HARDENING VERIFIED (KPTI / Meltdown Mitigation Active):
[+] Dual PGDs / Trampoline Vectors strictly separate address spaces!
[+] Kernel address space is completely unmapped in user mode (Ring 3/EL0).
[+] Meltdown rogue data cache load side-channel attacks are mitigated.
[+] =========================================================

=========================================================
  Kernel Ring Buffer (dmesg) Security Events
=========================================================
[    0.000000] Kernel command line: console=ttyAMA0 quiet panic=1 nokaslr lab_test=test_kpti kpti=on
[    0.000000] CPU features: enabling workaround for Meltdown
[    1.264100] [vuln_kpti] Initialized /proc/vuln_kpti (kpti active: 1)
[    2.327050] [vuln_kpti] Received probe request for address 0xffff800081e05040
[    2.327120] [vuln_kpti] [+] DEFENSE ACTIVE: Kernel Page Table Isolation is enforced!
[    2.327140] [vuln_kpti] [+] User page tables do NOT contain kernel space mappings.

4.3 하드닝 비교 매트릭스

검증 항목 (Dimension) 베이스라인 (pti=off / kpti=off) 하드닝 (pti=on / kpti=on) 보안 및 아키텍처 영향
페이지 테이블 구조 단일 통합 PGD 공유 유저/커널 분리 듀얼 PGD (트램펄린 최소화) 유저 모드에서 커널 주소 변환 엔트리 물리적 부재
Meltdown 취약성 취약 (Vulnerable) 완화 (Mitigation: PTI) 비순차 실행을 통한 L1D 캐시 부채널 기밀 유출 차단
하드웨어 제어 레지스터 단일 CR3 / 공유 TTBR CR3 bit 12 반전 / TTBR1 트램펄린 전환 시스템 콜/인터럽트 진입/복귀 시 PGD 전환 강제
성능 최적화 기법 해당 없음 PCID (x86) / ASID (ARM64) 태깅 접목 TLB 전면 플러시 방지로 전환 오버헤드 1~3% 수준 억제

5. 영문 발표 대본 (English Presentation Script)

Slide 1: The Meltdown Flaw and the Need for Physical Address Separation

"Good morning, everyone. Today, we conclude Phase 5 of our Linux Kernel Hardening Lab by exploring Kernel Page Table Isolation (KPTI). For decades, monolithic operating systems mapped the entire kernel space directly into every user process's page table. While this provided exceptional performance for system calls, it fatally overlooked hardware out-of-order execution. With Meltdown (CVE-2017-5754), processors could transiently read privileged kernel memory before committing privilege fault exceptions, leaking confidential data via L1D cache timing attacks."

Slide 2: How KPTI Neutralizes Speculative Data Cache Loads

"KPTI solves this problem not with software checks, but through strict architectural partition. Under KPTI, every process maintains two separate sets of page tables: a Kernel PGD used exclusively in Ring 0, and a User PGD activated whenever code runs in Ring 3. The User PGD unmaps virtually all kernel code and data structures, leaving only the bare minimum trampoline entry stubs. Because there is simply no translation entry in the user page tables, speculative instructions immediately hit a hardware wall—preventing any unauthorized memory from ever being cached."

Slide 3: Performance Mitigation via PCID and ASID

"Historically, switching page tables on every system call imposed an unacceptable 5% to 30% performance penalty due to complete TLB flushing. However, by coupling KPTI with Process Context Identifiers (PCID) on x86 and Address Space Identifiers (ASID) on ARM64, the kernel retains valid TLB entries across context switches, reducing the runtime overhead to approximately 1% to 2%."


6. 용어 사전 (Technical Glossary)

  • KPTI (Kernel Page Table Isolation): 유저 공간과 커널 공간의 가상 주소 변환 테이블을 완전 분리하여 Meltdown 공격을 방어하는 리눅스 커널 메모리 하드닝 메커니즘.
  • Meltdown (CVE-2017-5754): 비순차 투기적 실행 중 권한 검사 완료 전에 불법적으로 로드된 커널 기밀을 캐시 부채널로 유출하는 하드웨어 마이크로아키텍처 결함.
  • Dual PGD: 단일 프로세스마다 유저 모드용과 커널 모드용 2개의 최상위 페이지 테이블(PGD)을 분리 유지하는 기법.
  • Trampoline Vector: 유저 PGD에 유일하게 매핑되어 시스템 콜이나 인터럽트 진입 시 PGD 전환을 안전하게 수행하는 최소 커널 어셈블리 스텁.
  • PCID (Process Context Identifier): x86 MMU에서 프로세스 컨텍스트별로 TLB 항목에 태그를 달아 CR3 전환 시 불필요한 TLB 플러시를 방지하는 하드웨어 기능.
  • ASID (Address Space Identifier): ARM64 아키텍처에서 주소 공간별 TLB 태깅을 지원하여 컨텍스트 스위칭 오버헤드를 완화하는 하드웨어 식별자.
  • Flush+Reload: 캐시 라인을 플러시한 후 특정 메모리 접근 시간을 정밀 측정하여 데이터 캐시 상주 여부를 판별하는 캐시 부채널 공격 기법.