Skip to content

arch: enable ARCH_KERNEL_STACK support in protected builds#17984

Merged
GUIDINGLI merged 2 commits intoapache:masterfrom
hujun260:apache_arch_ARCH_KERNEL_STACK
Jan 18, 2026
Merged

arch: enable ARCH_KERNEL_STACK support in protected builds#17984
GUIDINGLI merged 2 commits intoapache:masterfrom
hujun260:apache_arch_ARCH_KERNEL_STACK

Conversation

@hujun260
Copy link
Contributor

Summary

Enable ARCH_KERNEL_STACK support in protected kernel builds (BUILD_PROTECTED) in addition to kernel-only builds (BUILD_KERNEL). The separate kernel stack feature is useful for both modes where address environments separate kernel and userspace memory. Update configuration and code to allow kernel stack allocation in protected builds, enabling proper kernel and user stack separation for protected mode processes.

Changes

  • arch/Kconfig:

    • Change ARCH_KERNEL_STACK configuration dependency from BUILD_KERNEL to BUILD_KERNEL || BUILD_PROTECTED
    • Enables kernel stack allocation in both kernel-only and protected build modes
  • sched/pthread/pthread_create.c:

    • Remove redundant CONFIG_BUILD_KERNEL check from kernel stack allocation conditional
    • Change condition from CONFIG_ARCH_ADDRENV && CONFIG_BUILD_KERNEL && CONFIG_ARCH_KERNEL_STACK to CONFIG_ARCH_ADDRENV && CONFIG_ARCH_KERNEL_STACK
    • Allows kernel stack allocation whenever CONFIG_ARCH_KERNEL_STACK is enabled, regardless of build mode

Benefits & Technical Details

  • Protected build support: Separate kernel and user stacks now work in protected mode
  • Stack isolation: Improves security by isolating kernel stack from userspace
  • Configuration flexibility: ARCH_KERNEL_STACK no longer tied exclusively to BUILD_KERNEL
  • Code simplification: Removes unnecessary BUILD_KERNEL coupling in pthread code
  • Consistent behavior: Same kernel/user stack separation available in both modes

Testing

  • Verified CONFIG_ARCH_KERNEL_STACK is available when CONFIG_BUILD_PROTECTED is enabled
  • Confirmed kernel stacks are properly allocated for pthreads in protected mode
  • Tested pthread creation with separate kernel and user stacks in protected builds
  • Validated kernel stack isolation prevents userspace code from accessing kernel stack
  • Confirmed no regressions in existing BUILD_KERNEL configurations

Impact

  • Compatibility: Fully backward compatible, extends existing feature
  • Configuration: Enables new configuration combinations for protected builds
  • Scope: Affects protected mode process creation and kernel stack management
  • Architecture: Applies to all architectures supporting ARCH_KERNEL_STACK and address environments

Expand ARCH_KERNEL_STACK configuration to support both BUILD_KERNEL and
BUILD_PROTECTED modes. Change Kconfig dependency from "depends on BUILD_KERNEL"
to "depends on BUILD_KERNEL || BUILD_PROTECTED". Update pthread_create.c to
remove redundant BUILD_KERNEL check when allocating kernel stacks with
CONFIG_ARCH_KERNEL_STACK enabled. Enables protected builds to use separate
kernel and user stacks for processes.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
@github-actions github-actions bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Jan 17, 2026
Move kernel stack allocation from exec_module() (binary format execution) to
nxtask_init() (task initialization) with proper type checking. Add conditional
check to allocate kernel stack only for non-kernel tasks (ttype != TCB_FLAG_TTYPE_KERNEL).
Enables kernel stack allocation for both exec'd tasks and regular task_create()
calls in protected builds, allowing userspace to create tasks with proper kernel
stack isolation.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
@github-actions github-actions bot added Area: BINFMT Size: S The size of the change in this PR is small labels Jan 17, 2026
@GUIDINGLI GUIDINGLI merged commit 6f4cb9f into apache:master Jan 18, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BINFMT Area: OS Components OS Components issues Size: S The size of the change in this PR is small Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants