Skip to content

security(core): harden user memory access, runtime CPU controls, and low-level fault containment#11

Open
minto-dane wants to merge 6 commits intotas0dev:devfrom
minto-dane:dev
Open

security(core): harden user memory access, runtime CPU controls, and low-level fault containment#11
minto-dane wants to merge 6 commits intotas0dev:devfrom
minto-dane:dev

Conversation

@minto-dane
Copy link
Copy Markdown
Contributor

概要

この PR は src/core の low-level runtime hardening を目的とした変更です。主に次の 3 点を改善しています。

  • user memory access を hardened usercopy に統一
  • CPU の runtime hardening を有効化し、重要な境界で再適用
  • panic や assert に寄っていた低レイヤ異常経路を audit-backed containment に変更

module 実装や service 構造の変更は含めず、並行して進んでいる別作業と衝突しにくい範囲に限定しています。

変更点

1. audit 基盤を追加

対象:

  • src/core/audit.rs
  • src/core/lib.rs

変更内容:

  • src/core/audit.rs を追加
  • src/core/lib.rs から audit を公開
  • low-level runtime から fault / quarantine / deny などを記録できる append-only audit ring buffer を導入

理由:
panic や silent failure に頼らず、異常を記録して追跡できるようにするためです。

2. CPU runtime hardening を強化

対象:

  • src/core/cpu.rs
  • src/core/interrupt/timer.rs
  • src/core/percpu.rs

変更内容:

  • CR0.WP を有効化
  • UMIP を有効化
  • SMEP/SMAP を有効化・再適用
  • IBPB / SPEC_CTRL のサポート検出と再適用を追加
  • timer interrupt や context switch 周辺で hardening を再主張
  • boot CPU の APIC ID チェックから runtime assert! を除去し、audit 付き fallback に変更

理由:
runtime 中に hardening 状態が崩れたまま動くリスクを減らすためです。

3. user memory access を page-table-walk ベースへ移行

対象:

  • src/core/init/mod.rs
  • src/core/mem/mod.rs
  • src/core/mem/paging.rs
  • src/core/mem/user.rs
  • src/core/syscall/mod.rs
  • src/core/task/elf.rs

変更内容:

  • paging / memory init を Result ベースに変更
  • page-table-walk による copy_from_user / copy_to_user を整備
  • ELF load / relocation / user stack 構築を hardened usercopy ベースへ変更
  • writable + executable な user mapping を拒否
  • user mapping の permission を厳格化

理由:
kernel が user memory を扱う経路を、より KPTI に整合した安全な実装へ寄せるためです。

4. fs / exec / pipe / io 系 syscall の user buffer handling を harden

対象:

  • src/core/syscall/exec.rs
  • src/core/syscall/fs.rs
  • src/core/syscall/io.rs
  • src/core/syscall/pipe.rs
  • src/core/task/fd_table.rs

変更内容:

  • direct user pointer access を helper 経由へ置換
  • pipe fd 書き戻しを helper 化
  • pipe handle 生成を helper に整理

理由:
よく使われる syscall 経路で、壊れた user pointer が kernel 側の不正アクセスや不安定動作につながるのを防ぐためです。

5. process / signal / time / vga / pgroup 系 syscall の usercopy を harden

対象:

  • src/core/syscall/pgroup.rs
  • src/core/syscall/process.rs
  • src/core/syscall/signal.rs
  • src/core/syscall/time.rs
  • src/core/syscall/vga.rs

変更内容:

  • signal action / sigmask / signal frame / sigreturn の usercopy 化
  • wait, arch_prctl, clock_gettime, framebuffer info 返却の helper 化
  • futex wake queue overflow を debug_assert! 依存から audit + drop に変更
  • heap base に bounded randomization を追加

理由:
構造体の user/kernel 受け渡しや process 制御系 syscall を、他の hardened path と同じ基準で安全化するためです。

6. low-level fault containment を追加

対象:

  • src/core/mem/gdt.rs
  • src/core/syscall/ipc.rs
  • src/core/task/context.rs
  • src/core/task/scheduler.rs
  • src/core/task/thread.rs

変更内容:

  • IPC mailbox の free list 異常を panic ではなく quarantine + audit に変更
  • kernel stack guard corruption を terminate + audit に変更
  • unexpected thread return や missing metadata を audit 付き failure に変更
  • GDT selector 取得失敗を監査付き fatal path に統一
  • scheduler dead-end を audit 付きで扱うように変更

理由:
低レイヤ metadata の破損や想定外状態が、opaque な panic や silent corruption に繋がるのを防ぐためです。

この PR の目的

この PR の主目的は、src/core の runtime path を次の方向へ改善することです。

  • user memory access をより安全にする
  • CPU hardening を runtime 中も維持する
  • panic や assert に依存した低レイヤ安全性を減らす
  • 異常を監査可能にし、局所的に封じ込める

module や service の構造変更をこの PR に含めると差分が大きくなりすぎ、並行作業とも競合しやすいため、この PR では hardening に集中しています。

互換性

既存の service stack や runtime ABI を壊さない範囲で変更しています。

維持しているもの:

  • 既存 service 前提の syscall surface
  • 既存 fd table モデル
  • 既存 privilege モデル
  • userspace / service 側の前提

コミット構成

  • 8a617af observability(core): add append-only audit log infrastructure
  • 0b551bb security(core): enable runtime CPU hardening controls
  • f05c489 security(core): move user memory access to page-table-walk primitives
  • e0c57c1 security(core): harden fs, exec, and pipe user-buffer handling
  • 1d4f130 security(core): update process and signal syscalls for hardened usercopy
  • 2b12efe reliability(core): add audit-backed containment for low-level runtime faults

Introduce a minimal append-only audit ring buffer for recording fault, quarantine, deny, and recovery events from the core runtime. Export the audit module from the core crate so later hardening changes can report abnormal conditions without relying on panic output alone.
Enable supervisor write-protect, UMIP, SMEP/SMAP reinforcement, and supported speculation-control state during core runtime initialization. Reassert hardening state on timer entry and replace the boot CPU APIC table assertion with an audited fallback path.
Convert memory initialization, syscall entry, and ELF loading to use page-table-walk usercopy helpers instead of temporary user address-space switching. Keep kernel CR3 active during kernel-side copies, tighten user mapping permissions, and return explicit initialization errors from paging setup.
Route filesystem, exec, generic I/O, and pipe descriptor paths through the hardened usercopy helpers. Replace direct user-pointer reads and writes in these runtime paths while preserving the existing fd table model used by the service stack.
Replace remaining direct user-buffer accesses in process control, signal delivery, timekeeping, framebuffer, and mprotect-related syscall paths with the hardened copy helpers. Add bounded heap-base randomization and explicit handling for futex wake-queue overflow instead of relying on debug assertions.
… faults

Replace panic-prone mailbox bookkeeping and unexpected thread or context return paths with explicit audit logging and containment behavior. Record GDT lookup failures, IPC mailbox corruption, kernel stack guard faults, and scheduler dead-end conditions without relying on silent corruption or unchecked panic paths.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 852db680-2c16-4d1f-86bd-dbf7dc24884b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@tas0dev tas0dev self-requested a review April 9, 2026 06:07
@tas0dev
Copy link
Copy Markdown
Owner

tas0dev commented Apr 9, 2026

cargo runで実行確認をしてから再メンションしてください

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants