Skip to content

[HUST CSE][core] validate thread priority at runtime#11297

Open
Telecaster2147 wants to merge 3 commits intoRT-Thread:masterfrom
Telecaster2147:security/core-priority-validation
Open

[HUST CSE][core] validate thread priority at runtime#11297
Telecaster2147 wants to merge 3 commits intoRT-Thread:masterfrom
Telecaster2147:security/core-priority-validation

Conversation

@Telecaster2147
Copy link

@Telecaster2147 Telecaster2147 commented Mar 25, 2026

拉取/合并请求描述:(PR description)

为什么提交这份PR (why to submit this PR)

当前调度优先级更新路径对非法优先级的保护主要依赖 RT_ASSERT。在非断言构建下,越界优先级可能继续进入核心调度逻辑,带来不可预期行为。

你的解决方案是什么 (what is your solution)

本 PR 在 rt_sched_thread_change_priority() 和 rt_sched_thread_reset_priority() 中增加运行时检查:当 priority 大于等于 RT_THREAD_PRIORITY_MAX 时,直接返回 -RT_EINVAL,避免非法值继续传入内部调度更新逻辑。

请提供验证的bsp和config (provide the config and bsp)

  • BSP:
    bsp/qemu-vexpress-a9

  • .config:使用 bsp/qemu-vexpress-a9/.config 做基础编译验证。

  • action:currently unavailable

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@Telecaster2147 Telecaster2147 marked this pull request as draft March 25, 2026 12:05
@Telecaster2147 Telecaster2147 marked this pull request as ready for review March 25, 2026 12:05
@Telecaster2147
Copy link
Author

Telecaster2147 commented Mar 25, 2026

@Rbb666 您好,我这边的 PR #11297 好像被卡在 workflow approval 这里了,导致 pr-labeler 和 reviewer assign 都没有继续执行。能麻烦您有空帮忙看一下并 approve 一下吗,感谢!!

@github-actions
Copy link

github-actions bot commented Mar 25, 2026

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/lwp/lwp_syscall.c

🏷️ Tag: components_lwp

Reviewers: xu18838022837

Changed Files (Click to expand)
  • components/lwp/lwp_syscall.c

🏷️ Tag: kernel

Reviewers: GorrayLi ReviewSun hamburger-os lianux-mm wdfk-prog xu18838022837

Changed Files (Click to expand)
  • src/scheduler_comm.c

📊 Current Review Status (Last Updated: 2026-03-26 12:25 CST)

  • GorrayLi Pending Review
  • @Maihuanyi Pending Review
  • ReviewSun Pending Review
  • hamburger-os Pending Review
  • lianux-mm Pending Review
  • wdfk-prog Pending Review
  • xu18838022837 Pending Review

📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions github-actions bot added the Kernel PR has src relate code label Mar 25, 2026
@Rbb666
Copy link
Member

Rbb666 commented Mar 25, 2026

@Rbb666 您好,我这边的 PR #11297 好像被卡在 workflow approval 这里了,导致 pr-labeler 和 reviewer assign 都没有继续执行。能麻烦您有空帮忙看一下并 approve 一下吗,感谢!!

可以了,因为第一次贡献不会运行ci,下一次就好了

*/
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority)
{
if (priority >= RT_THREAD_PRIORITY_MAX)
Copy link
Member

Choose a reason for hiding this comment

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

如果上层没有正确的针对返回值进行判断,系统是会继续运行的,而不会执行_rt_sched_update_priority进行assert异常停止。
系统也有很多调用此函数的地方没有对返回值进行处理:

rt_sched_thread_change_priority(thread, priority);

Copy link
Author

Choose a reason for hiding this comment

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

如果上层没有正确的针对返回值进行判断,系统是会继续运行的,而不会执行_rt_sched_update_priority进行assert异常停止。 系统也有很多调用此函数的地方没有对返回值进行处理:

rt_sched_thread_change_priority(thread, priority);

感谢提醒,这个点我重新调整了。之前的确是把检查放得太靠下了,现在的推送已经把优先级校验前移到 sys_sched_setparam() / sys_sched_setscheduler() 的 syscall 入口,内核内部原有的 assert 路径保持不变,本地已经通过编译

@Telecaster2147 Telecaster2147 force-pushed the security/core-priority-validation branch from 7797e7f to 034f06d Compare March 26, 2026 04:25
@github-actions github-actions bot added RT-Smart RT-Thread Smart related PR or issues component: lwp Component labels Mar 26, 2026
@Telecaster2147 Telecaster2147 requested a review from Rbb666 March 26, 2026 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: lwp Component Kernel PR has src relate code RT-Smart RT-Thread Smart related PR or issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants