Skip to content

Update HAOC 3.0 to HAOC 4.0 for Deepin - #2087

Open
amjac27 wants to merge 26 commits into
deepin-community:linux-6.6.yfrom
amjac27:haoc-4.0
Open

amjac27 wants to merge 26 commits into
deepin-community:linux-6.6.yfrom
amjac27:haoc-4.0

Conversation

@amjac27

@amjac27 amjac27 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

将 HAOC 3.0 更新至 HAOC 4.0,依据 Unixbench,性能开销在 5% 左右。目前提供的功能如下:

  • IEE:提供内核内隔离执行环境的框架,由受到保护的内存、堆栈、可信的代码出入口等构建而成。在内核由于漏洞发生安全问题时,IEE 可以确保内部的数据和代码不受到影响,因此可以用于加固对内核关键数据的防护,并承载一定的安全检查代码,用于监视内核行为。

    • IEE_SIP: 保护那些可能破坏IEE隔离性的关键指令,例如写入系统控制寄存器的指令,这些指令将在IEE内部执行。这类关键指令一旦被恶意或错误地执行,将直接破坏内核行为,导致安全敏感数据泄露或权限提升。

    • IEE_PTRP: 进程的 task_struct结构体包含大量关键指针,例如 struct cred*,它直接决定了进程的权限和能力。一旦该指针被恶意篡改,攻击者即可提升权限,导致严重安全风险。该选项为每个进程提供称为 task_token 的 IEE 元数据,在运行时动态验证 task_struct 中关键指针(例如 struct cred*,该指针决定了进程的权限能力)的完整性,防止指针被非法覆盖或重定向

    • IEE_PTRP_W: 与PTRP的功能相比,此选项仅对关键指针执行写保护。启用此选项可提升性能,并缩小防护范围。

    • IEE_SELINUXP:对 Linux 有名的安全子系统 Selinux 进行安全加固的选项。Selinux 是广泛使用的 LSM(Linux security module)的代表之一,它在内核的各个关键函数中进行插桩检查,并引入了自己的一套用户访问控制模型。我们将 Selinux 所使用的最关键的数据结构放入 Haoc 安全内存中进行监视,确保其提供的安全检查不被攻击者绕过。

  • PTP:由于 IEE 的防护设计基于内核页表实现,需要将内核页表进行隔离和保护,确保 IEE 自身的完整性。此外,内核页表也是内核运行的最关键数据,PTP 通过对内核页表的隔离与监视,确保了内核 DEP (Data execution prevention)防止代码篡改与注入,并阻止 Alias mapping,防止内核数据与代码被攻击者泄露到用户空间。

    • PTP_S: PTP 的子选项,开启后能提高 PTP 页表保护的性能,在 PTP 的基础上将页表划分为内核页表和用户页表,仅对内核页表实施只读保护,用户页表开放读写权限,减小开销。
  • CREDP:对内核内 cred 结构体的防护。cred 结构体是 Linux 访问控制策略中的关键数据,负责标识进程的各项权限,在进程访问各种资源时提供信息进行安全校验。如果 cred 被非法篡改或替换,攻击者将很容易绕过内核的各种安全防护,达到为所欲为的效果。Haoc 将 cred 放入隔离环境内,所有对 cred 的访问都需要经过 Haoc 的接口进行检验。我们在这些接口布置了相应的安全策略,即使攻击者利用内存安全漏洞,也无法直接修改 cred,或者构建 ROP 攻击复用内核接口修改进程 cred 为非法目标。

  • KEYP:对内核内 key 结构体的防护。key 是内核密钥环安全子系统的关键数据结构,可以用于强化 Linux 的控制访问策略。但在宏内核中,暴露的 key 结构体仍可能被攻击者通过内核漏洞随意篡改,导致这些安全加固失去意义。Haoc 框架则通过提供可信的内存并确保相关验证代码的控制流完整性,给这些安全加固机制提供了更为可靠的保障。

  • VARP: 对 Linux 内核中易被攻击者利用的关键全局变量进行安全加固的选项,例如 modprobe_path 等。这类变量会影响内核安全决策或用户态辅助程序执行路径,攻击者获得内核任意写后常通过篡改它们劫持内核行为。我们将这些关键变量放入 Haoc 安全内存,确保这些安全敏感变量在运行期仍可被内核正常读写,但不会被攻击者直接改写以绕过系统保护。

Summary by Sourcery

Enable HAOC 4.0 security hardening for Deepin by integrating page-table protection, credential and key isolation, and SELinux/varp hardening across arm64 and x86, while wiring the new infrastructure into memory management, exec/fork paths, keyrings, and security subsystems.

New Features:

  • Introduce HAOC bitmap infrastructure and per-page type tagging to distinguish IEE data, page tables, credentials, keys, SELinux data, and protected variables.
  • Add PTP-based page table protection that enforces read-only kernel page tables, guarded TLB/free paths, and WP-aware context switches on x86 and arm64.
  • Extend CREDP to track and verify per-task credentials via task tokens, add periodic credential integrity checking threads, and tighten cred lifecycle verification.
  • Introduce KEYP to isolate and guard keyring metadata and payloads in IEE memory, including new key_union/key_struct layouts and RCU-safe payload handling.
  • Add VARP to protect sensitive kernel variables such as modprobe_path via IEE-backed storage and custom proc string handling.
  • Harden SELinux (SELINUXP) by placing policy structures, status pages, and caps into IEE memory with dedicated caches and gate functions, and updating SELinux fs and status handling accordingly.

Bug Fixes:

  • Ensure HAOC is opt-in via a boot parameter, with hardware capability checks and CET/CR4 pinning adjustments to avoid conflicts on unsupported systems.
  • Prevent creation of writable-executable or alias mappings over IEE-protected regions by adding DEP-style checks in page table mutation paths and early identity mapping code.

Enhancements:

  • Refine IEE MMU and early init on arm64 and x86 to allocate separate IEE pools for stacks, data, and page tables and to support HPD/ASID-based isolation.
  • Strengthen IEE_PTRP by associating task tokens with pgd/cred state, adding seqcount-based verification, and integrating verification hooks into IO, scheduler context switches, and fork/exec paths.
  • Augment slab allocation paths to tag and protect cred, key, and SELinux policy slabs as IEE types, including deferred free handling and split-order adjustments.
  • Update generic MM/TLB, page fault, and mprotect/mmap/exit_mmap paths to honor PTP constraints, route page-table frees through HAOC-aware caches, and add new TLB flush helpers.
  • Adapt keyring and key type implementations to respect KEYP semantics, including new locking macros, assoc_array usage over key_struct wrappers, and explicit field setters for HAOC.

Loading
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.

6 participants