8000
Skip to content

Latest commit

ย 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ARM64 Linux 6.6 Safety Isolation Demonstration System

CI Build License: GPL-2.0 C++20 Linux 6.6 LTS Target: ARM64

An interactive, live ARM64 Linux 6.6 demonstration system illustrating the critical boundary between software synchronization (std::mutex) and hardware-enforced memory isolation (PTE page protection & SMMUv3 bus translation).


๐Ÿ’ก Key Question

"What does it actually take to protect safety-critical kernel memory โ€” and why isn't a mutex enough?"

In safety-critical embedded systems (automotive ISO 26262, robotics, aerospace), developers frequently assume that holding a software lock or setting a page read-only guarantees safety. This project demonstrates live how rogue kernel threads, uncooperative drivers, and bus-mastering DMA devices easily bypass software abstractions, and proves how complete hardware isolation (Level 2 PTE walking + SMMUv3 IOMMU mapping) neutralizes memory corruption.


๐ŸŽฏ Master Analogy: The Server Room Building

Everything maps to a single physical analogy to make abstract kernel mechanisms intuitively clear:

  • ๐Ÿข Safety Memory (safety_buf): A high-security server rack inside a room.
  • ๐Ÿ“‹ Mutex (struct mutex): A sign-in sheet on the front door. ("A sign-in sheet only works if everyone agrees to read and sign it.")
  • ๐Ÿ”‘ set_memory_ro / PTE Protection: A keycard lock on the front door.
  • ๐Ÿšช Linear Map Alias (phys_to_virt): A unlocked fire exit โ€” a second door to the exact same room with no keycard reader. ("Locking the front door doesn't help if you left the fire exit open.")
  • ๐Ÿšœ DMA Bus Master Write: A forklift driving directly through the brick wall. ("Door locks stop pedestrians; they do not stop forklifts.")
  • ๐Ÿฐ SMMUv3 IOMMU Guard: A reinforced outer concrete perimeter wall surrounding the entire property.

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Apple Silicon Mac (ARM64 Host)                                  โ”‚
โ”‚                                                                  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                      โ”‚
โ”‚  โ”‚  Docker Container: safety-demo-builderโ”‚                      โ”‚
โ”‚  โ”‚  aarch64-linux-gnu-gcc  (kernel C)    โ”‚ โ†’ .ko files          โ”‚
โ”‚  โ”‚  aarch64-linux-gnu-g++  (C++20)       โ”‚ โ†’ monitor, harness   โ”‚
โ”‚  โ”‚  Linux 6.6 LTS source + Kbuild        โ”‚ โ†’ kernel Image       โ”‚
โ”‚  โ”‚  busybox + cmake + ninja              โ”‚ โ†’ initramfs.cpio.gz  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ”‚
โ”‚                         โ”‚ ./out/Image  ./out/initramfs.cpio.gz  โ”‚
โ”‚                         โ–ผ                                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  QEMU ARM64 (-accel hvf โ€” near-native on Apple Silicon)    โ”‚ โ”‚
โ”‚  โ”‚  -machine virt,iommu=smmuv3  -cpu cortex-a57  -m 512M      โ”‚ โ”‚
โ”‚  โ”‚                                                            โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚
โ”‚  โ”‚  โ”‚  tmux Live Split Display Interface                   โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚  โ”‚ Left Pane: Dashboard  โ”‚ Right Pane: Harness    โ”‚  โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚  โ”‚ (3x std::jthread TUI) โ”‚ (4-Beat Presenter UI)  โ”‚  โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚ โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“Š Core Scenarios & Tradeoff Matrix

Scenario Summary Breakdown

  1. Scenario B โ€” Mutex + Rogue Thread: Thread A holds the mutex. Thread C (rogue driver) ignores the mutex and writes directly to safety_buf. Memory is corrupted while the mutex is held!
    • Takeaway: Mutex provides serialization, not authorization.
  2. Scenario D โ€” DMA Linear Map Bypass: set_memory_ro() locks the primary vmalloc virtual address. Attack driver writes to the physical address via the kernel linear map (phys_to_virt). The vmalloc alias reads SAFE, while the physical page is CORRUPTED!
    • Takeaway: Protecting one virtual alias leaves the linear map fire exit open.
  3. Scenario F โ€” Full CTX + SMMUv3 Isolation: Level 2 page-table walking locks both vmalloc AND linear map PTEs (PMD split applied). SMMUv3 domain blocks physical DMA bus-mastering transactions. Memory remains 100% PROTECTED.
    • Takeaway: Virtual MMU + Physical SMMU are both required for complete safety.
  4. Scenario G โ€” Mutex Metadata Attack (Optional Q&A): Attacker driver overwrites mutex.owner = 0 in RAM. Thread B acquires the lock while Thread A still holds it!
    • Takeaway: Software state structures living in writable RAM are self-referentially fragile.

Comprehensive Tradeoff Matrix

Feature / Attribute Scenario B (Mutex) Scenario D (Naive CTX) Scenario F (Full CTX + SMMU) Scenario G (Lock Attack)
CPU MMU Protected? โŒ No ๐ŸŸก Vmalloc alias only โœ… All PTEs (Level 2 walk) โŒ No
Physical Bus (DMA)? โŒ No โŒ No โœ… SMMUv3 Domain โŒ No
Rogue Thread Proof? โŒ No ๐ŸŸก Partial โœ… Yes โŒ No
Lock Structure Safe? โŒ No โŒ No โœ… Yes โŒ Corruptible
Implementation Complexity ๐ŸŸข Very Low ๐ŸŸก Moderate ๐Ÿ”ด High ๐ŸŸข Low
Runtime Latency Cost ~4 ns ~600 ns ~2.5 ยตs ~4 ns

๐Ÿš€ Quick Start (Build & Run Instructions)

Prerequisites

  • Docker Desktop (with Compose)
  • macOS (Apple Silicon M1/M2/M3 for -accel hvf) or Linux ARM64/x86_64
  • QEMU (qemu-system-aarch64)

1. Cross-Compile Build (Inside Docker)

Builds Linux 6.6 LTS kernel, out-of-tree C kernel modules, C++20 userspace binaries, and rootfs image in one command:

docker compose run build
# Generates out/Image and out/initramfs.cpio.gz

2. Launch QEMU VM

./env/run_qemu.sh

Auto-detects host architecture and selects -accel hvf on macOS or -accel kvm/tcg on Linux.

3. Launch Interactive Presenter Mode (Inside QEMU)

harness --interactive

Auto-launches tmux split window: left pane shows live memory dashboard, right pane presents 4-beat interactive scenarios.


๐ŸŽฎ Harness CLI Options

harness --interactive               # Interactive 3-scenario presenter mode (B, D, F)
harness --interactive --start-at D  # Skip Scenario B, start directly at Scenario D
harness --interactive --scenario G  # Trigger optional Scenario G (Q&A mode)
harness --auto --scenario all        # Unattended CI automated validation mode

During Scenario D reveal, inspect live physical memory changes:

devmem watch 0x40001000

Generate final results comparison table:

analysis --output /results/comparison_table.md

๐Ÿ› ๏ธ Code Structure & Quality Standards

demo-linux-safety-isolation/
โ”œโ”€โ”€ .github/workflows/build.yml     # GitHub Actions CI Workflow (6 Quality Jobs)
โ”œโ”€โ”€ .clang-tidy                     # C++ Core Guidelines & CERT rules
โ”œโ”€โ”€ README.md                       # Master Documentation
โ”œโ”€โ”€ Dockerfile.builder              # Multi-stage Docker builder
โ”œโ”€โ”€ docker-compose.yml              # Build orchestration
โ”œโ”€โ”€ cmake/                          # Toolchain & Presets (asan, tsan, xray)
โ”‚   โ””โ”€โ”€ aarch64-toolchain.cmake
โ”œโ”€โ”€ env/                            # Kernel environment scripts
โ”‚   โ”œโ”€โ”€ build_rootfs.sh
โ”‚   โ”œโ”€โ”€ kernel.config
โ”‚   โ””โ”€โ”€ run_qemu.sh
โ”œโ”€โ”€ kernel/                         # Out-of-tree C Kernel Modules
โ”‚   โ”œโ”€โ”€ safety_mem/                 # CTX01 memory owner & PTE page table walker
โ”‚   โ”œโ”€โ”€ bad_driver/                 # Attack driver (modes 0, 1, 2)
โ”‚   โ”œโ”€โ”€ mutex_threads/              # Cooperative vs Rogue threads
โ”‚   โ”œโ”€โ”€ ctx_monitor/                # SR die_notifier page fault monitor
โ”‚   โ””โ”€โ”€ smmu_guard/                 # SMMUv3 DMA bus isolation module
โ””โ”€โ”€ userspace/                      # Modern C++20 Applications
    โ”œโ”€โ”€ common/                     # Concepts, ProcReader, PhysicalMemoryView
    โ”œโ”€โ”€ monitor/                    # 3-jthread live dashboard
    โ”œโ”€โ”€ harness/                    # 4-beat presenter interface & scenarios
    โ”œโ”€โ”€ devmem/                     # Physical memory inspector
    โ””โ”€โ”€ analysis/                   # Comparison table generator

Static Analysis & Runtime Verification

  • Kernel (C): Inspected via sparse (make C=1) and smatch.
  • Userspace (C++20): Enforced via clang-tidy (C++ Core Guidelines), cppcheck, AddressSanitizer (ASan), UndefinedBehaviorSanitizer (UBSan), and ThreadSanitizer (TSan).

๐Ÿ“œ License

This project is released under the GNU General Public License v2.0.

About

Demonstrating Linux safety-critical memory isolation gaps (linear map bypass, uncooperative threads) and mitigation via ARM64 dual-alias PTE protection and SMMUv3 bus enforcement.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0