Skip to content

Conversation

@amjac27
Copy link
Contributor

@amjac27 amjac27 commented Mar 17, 2025

  1. Add support for X86_64/AArch64 Isolated Execution Environment(IEE).
  2. Add switch support in kernel command line: set "haoc=on" to enable HAOC.

Summary by Sourcery

This pull request introduces the Isolated Execution Environment (IEE) feature for the deepin linux-6.6.y kernel, supporting both X86_64 and AArch64 architectures. The IEE provides an isolated environment for executing specific code, enhancing system security. It includes mechanisms for memory protection and access control.

New Features:

  • Adds support for Isolated Execution Environment (IEE) on X86_64 and AArch64 architectures.
  • Introduces a kernel command line switch "haoc=on" to enable the HAOC (Hardware-Assisted Out-of-Context) feature, which includes IEE.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 17, 2025

Reviewer's Guide by Sourcery

This pull request introduces the Isolated Execution Environment (IEE) feature for both X86_64 and AArch64 architectures. It includes changes to memory management, context switching, interrupt handling, and build configuration to support the new IEE functionality. A kernel command line option 'haoc=on' is added to enable the feature.

Sequence diagram for IEE protected memory access

sequenceDiagram
    participant Kernel
    participant IEE Gate
    participant IEE Protected Memory

    Kernel->>IEE Gate: Access IEE Protected Memory
    activate IEE Gate

    IEE Gate->>IEE Gate: Save Context (DAIF, LR)
    IEE Gate->>IEE Gate: Disable Interrupts
    IEE Gate->>IEE Gate: Switch to IEE Stack
    IEE Gate->>IEE Gate: Modify TCR_EL1 (Enable HPD1 and A1)
    IEE Gate->>IEE Protected Memory: Access Memory (Read/Write)
    IEE Gate->>IEE Gate: Modify TCR_EL1 (Disable HPD1 and A1)
    IEE Gate->>IEE Gate: Switch to Kernel Stack
    IEE Gate->>IEE Gate: Restore Context (DAIF, LR)

    IEE Gate-->>Kernel: Return
    deactivate IEE Gate
Loading

Updated class diagram for iee_stack

classDiagram
    class iee_stack {
        void* stack
    }
    note for iee_stack "This class represents the IEE stack for each CPU."
Loading

File-Level Changes

Change Details Files
Introduces Isolated Execution Environment (IEE) support for both X86_64 and AArch64 architectures.
  • Adds necessary header files for IEE.
  • Modifies ASID handling to support IEE requirements.
  • Adds code to handle IEE during context switching.
  • Adds a kernel command line switch "haoc=on" to enable HAOC (Hardware-Assisted Object Capability).
  • Adds IEE-specific memory mapping and initialization routines.
  • Adds an entry gate to control access to IEE-protected memory.
  • Adds functions to put pages into and remove pages from IEE.
  • Adds a mechanism to check for bad modes in IEE and handle them.
  • Adds stack initialization for IEE.
  • Adds a mechanism to disable CET when IEE is enabled due to conflicts.
arch/arm64/mm/context.c
arch/arm64/mm/mmu.c
arch/arm64/kernel/entry.S
arch/x86/kernel/cpu/common.c
arch/arm64/mm/proc.S
arch/x86/mm/init_64.c
arch/arm64/kernel/vmlinux.lds.S
arch/x86/kernel/asm-offsets.c
arch/arm64/include/asm/assembler.h
arch/arm64/include/asm/memory.h
arch/arm64/kernel/entry-common.c
arch/arm64/kernel/smp.c
Makefile
arch/arm64/kernel/Makefile
arch/x86/kernel/Makefile
arch/arm64/Kconfig
arch/x86/Kconfig
arch/arm64/kernel/haoc/iee/iee-mmu.c
arch/arm64/kernel/haoc/iee/iee-func.c
arch/x86/kernel/haoc/iee/iee-init.c
arch/arm64/kernel/haoc/iee/iee-gate.S
arch/x86/kernel/haoc/iee/iee-gate.S
arch/arm64/include/asm/haoc/iee.h
arch/arm64/kernel/haoc/iee/iee-init.c
arch/x86/include/asm/haoc/iee-access.h
arch/x86/include/asm/haoc/iee.h
arch/arm64/include/asm/haoc/iee-asm.h
arch/arm64/include/asm/haoc/haoc-def.h
arch/arm64/include/asm/haoc/iee-access.h
arch/arm64/kernel/haoc/haoc.c
arch/x86/kernel/haoc/iee/iee.c
arch/x86/kernel/haoc/haoc.c
arch/arm64/include/asm/haoc/haoc.h
arch/arm64/include/asm/haoc/iee-func.h
arch/x86/include/asm/haoc/iee-func.h
arch/arm64/kernel/haoc/Makefile
arch/arm64/kernel/haoc/iee/Makefile
arch/x86/kernel/haoc/Makefile
arch/x86/kernel/haoc/iee/Makefile
arch/arm64/kernel/haoc/Kconfig

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

Hi @IamJustaChild. Thanks for your PR. 😃

@deepin-ci-robot
Copy link

Hi @IamJustaChild. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @IamJustaChild - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment describing the purpose of the NO_BLOCK_MAPPINGS and NO_CONT_MAPPINGS flags.
  • It would be helpful to add a comment explaining why CET is disabled when HAOC is enabled.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@opsiff
Copy link
Member

opsiff commented Mar 18, 2025

评审发现代码有fix未合入 https://gitee.com/openeuler/kernel/pulls/15512

syscall.o proton-pack.o idreg-override.o idle.o \
patching.o

obj-$(CONFIG_IEE) += haoc/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请对齐缩进。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from avenger-285714. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Shu Hang and others added 7 commits March 21, 2025 09:28
community inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQKOW

-------------------------------------------------

Support Isolated Execution Environment for x86.
IEE depends on CR0.wp

Signed-off-by: Shu Hang <[email protected]>
Signed-off-by: Hu Bing <<[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
community inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQKOW

-----------------------------------

The base framework of HAOC. Could isolate kernel critical data and
enforce all write access made and verified in IEE APIs.
Needs hardware support FEAT_HPDS.

Signed-off-by: Lyu Jinglin <[email protected]>
Signed-off-by: Zhang Shiyang <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
community inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQKOW

-----------------------------------

Use kernel command line haoc to control if HAOC should be enabled.
eg: haoc=on to enable haoc protection.

Signed-off-by: Shu Hang <[email protected]>
Signed-off-by: Hu Bing <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
community inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBQKOW

-----------------------------------

Use kernel command line parameter "haoc" to control if HAOC should
be enabled on ARM64.

Signed-off-by: Lyu Jinglin <[email protected]>
Signed-off-by: Zhang Shiyang <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
- change "__ptep_get" to "ptep_get"
- change "__set_pte" to "set_pte"
- change "P4D_TABLE_AF" to "PMD_SECT_AF"
- change the place of "iee_tcr_mask"

Signed-off-by: Lyu Jinglin <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
community inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBTMTU

--------------------------------

add support for large memory (more than 1TB) in HAOC-ARM64 IEE.

Fixes: 8d2e6d1bb690 ("HAOC: Add support for AArch64 Isolated Execution Environment(IEE).")
Signed-off-by: Zhang Shiyang <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
community inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBSGVE

--------------------------------

add support for versions lower than ARMv8.1-a

Fixes: 8d2e6d1bb690 ("HAOC: Add support for AArch64 Isolated Execution Environment(IEE).")
Signed-off-by: Lyu Jinglin <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
@amjac27
Copy link
Contributor Author

amjac27 commented Mar 21, 2025

  1. 已修改代码风格
  2. 已取消在 Kconfig 中使能 IEE,改为 savedefconfig 方式
  3. 支持 clang/llvm 编译
  4. 迁移来自 openeuler 的两个修复补丁(支持1TB以上大内存;识别ARMv8.1-a架构以下的处理器并关闭IEE)
  5. 删除 -Wno-unused-variable

We use `#pragma GCC optimize("O0")` because we want to a "memset()" function
for internal use within IEE. However, when the compiler detects operations similar
to memset, it automatically optimizes them into calls to the standard memset
library function. Since IEE calling external functions to access data may cause
security issues, we must prevent this function from being optimized. Now it
supports clang/llvm.

Remove "def_bool = y" for IEE in Kconfig and edit
deepin_x86/arm64_desktop_defconfig to enable IEE by default.

Remove -Wno-unused-variable in Makefile.

Signed-off-by: Lyu Jinglin <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
@Avenger-285714
Copy link
Member

/ok-to-test

CONFIG_KVM=y
CONFIG_IEE=y
CONFIG_KPROBES=y
CONFIG_SHADOW_CALL_STACK=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要删掉CONFIG_SHADOW_CALL_STACK=y?

#define SET_INVALID(x) __pgprot(pgprot_val(x) & (~PTE_VALID))
#define SET_NG(x) __pgprot(pgprot_val(x) | PTE_NG)

#define PGD_APTABLE_RO (_AT(pudval_t, 1) << 62)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加一下注释说明用法

#define ASID_BIT (UL(1) << 48)

#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
#define IEE_ASID 0xfffe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里ASID的使用加注释说明

panic("Alloc pgtable error.\n");

{
/* Iterate on the new page table. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调整一下格式

/* The reverse operation of put_pages_into_iee().
* Call this function when you are returning pages back to kernel.
*/
void remove_pages_from_iee(unsigned long addr, int order)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否需要加static

remove_pages_from_iee(addr, order);
}

#include <asm/ptrace.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段include为什么没放在顶部

p4dp = p4d_offset(pgdp, addr);
p4d = READ_ONCE(*p4dp);
if (!p4d_none(p4d) && !(p4d_val(p4d) & PGD_APTABLE_RO)) {
phys += next - addr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是否可能导致死循环

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是在单向依次处理所有 PGD 页表项,每个页表项只可能处理一次,不会导致死循环

/* Init percpu seeds for random tags after cpus are set up. */
kasan_init_sw_tags();
#ifdef CONFIG_IEE
extern void iee_stack_init(void);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一行应该没有用

arch/x86/Kconfig Outdated
Support for Isolated Execution Environment Framework. Foundation of HAOC.
Could isolate kernel critical data and enforce all write access made and
verified in IEE APIs.
depends on X86_64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

挪到help上面

SYM_FUNC_END(iee_rw_gate)

.global iee_tcr
iee_tcr:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当开启BTF后有以下编译错误:
LD .tmp_vmlinux.btf
arch/arm64/kernel/haoc/iee/iee-gate.o: in function iee_protected_rw_gate': /home/deepin/actions-runner/_work/kernel/kernel/arch/arm64/kernel/haoc/iee/iee-gate.S:55:(.iee.text+0x24): relocation truncated to fit: R_AARCH64_LDST64_ABS_LO12_NC against symbol iee_tcr' defined in .text section in arch/arm64/kernel/haoc/iee/iee-gate.o
ld: /home/deepin/actions-runner/_work/kernel/kernel/arch/arm64/kernel/haoc/iee/iee-gate.S:55: 警告:one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined
/home/deepin/actions-runner/_work/kernel/kernel/arch/arm64/kernel/haoc/iee/iee-gate.S:85:(.iee.text+0x8c): relocation truncated to fit: R_AARCH64_LDST64_ABS_LO12_NC against symbol kernel_tcr' defined in .text section in arch/arm64/kernel/haoc/iee/iee-gate.o ld: /home/deepin/actions-runner/_work/kernel/kernel/arch/arm64/kernel/haoc/iee/iee-gate.S:85: 警告:one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined arch/arm64/kernel/haoc/iee/iee-mmu.o: in function iee_init_tcr':
/home/deepin/actions-runner/_work/kernel/kernel/arch/arm64/kernel/haoc/iee/iee-mmu.c:63:(.init.text+0x2c0): relocation truncated to fit: R_AARCH64_LDST64_ABS_LO12_NC against symbol `kernel_tcr' defined in .text section in arch/arm64/kernel/haoc/iee/iee-gate.o
ld: /home/deepin/actions-runner/_work/kernel/kernel/arch/arm64/kernel/haoc/iee/iee-mmu.c:63: 警告:one possible cause of this error is that the symbol is being referenced in the indicated code as if it had a larger alignment than was declared where it was defined
BTF .btf.vmlinux.bin.o
pahole: .tmp_vmlinux.btf: Invalid argument

可能是定义时没有对齐

1. add align before "iee_tcr" in iee-gate.S
2. format HAOC Kconfig
3. add some comments for ARM64 iee-rw-gate
4. restore deepin_arm64_desktop_defconfig "CONFIG_SHADOW_CALL_STACK=y"

Signed-off-by: Lyu Jinglin <[email protected]>
Signed-off-by: Liu Zhehui <[email protected]>
@amjac27
Copy link
Contributor Author

amjac27 commented Mar 26, 2025

  1. iee-gate.S 中设置对齐,修复编译错误
  2. Kconfig 规范修改
  3. ARM64 IEE 关键标志位添加注释
  4. 恢复 defconfig 中的 CONFIG_SHADOW_CALL_STACK=y
  5. 修改提到的代码格式(static,include 等)

@Avenger-285714 Avenger-285714 merged commit 585d92b into deepin-community:linux-6.6.y Mar 28, 2025
5 of 6 checks passed
@amjac27 amjac27 deleted the dev-haoc branch April 24, 2025 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants