Repository navigation
[components][lwp] Validate signal number in sys_sigaction - #11899
BernardXiong wants to merge 1 commit into
Conversation
sys_sigaction() forwarded the user-supplied signal number to lwp_signal_action() without any range check. lwp_signal_action() indexes the fixed-size sig_action[] and sig_action_mask[] arrays (_LWP_NSIG = 64) with signo - 1, so an out-of-range or negative signal caused out-of-bounds accesses in the kernel heap: - arbitrary-offset 8-byte write with a user-controlled handler value - kernel heap disclosure through the oact copy-out path - kernel crash when a far offset hits an unmapped address Reject signals outside [1, _LWP_NSIG] with EINVAL at the syscall entry, and add the same guard to lwp_signal_action() so future callers cannot reach the indexing code with an invalid signal. Verified on qemu-virt64-aarch64 and qemu-virt64-riscv (RT-Smart) with a user-space PoC: in-range signals still succeed, while 0, -1, 65, 200 and 0x1000000 now return -EINVAL without touching the arrays. Co-authored-by: DeepSeek 4.1 Flash <noreply@deepseek.com>
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
🏷️ Tag: components_lwpReviewers: @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-10-19 08:49 CST)
📝 Review Instructions
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
修复 #11882。
sys_sigaction()将用户态传入的sig直接传给lwp_signal_action(),两处均未做范围检查。lwp_signal_action()使用signo - 1索引struct rt_lwp中固定大小的sig_action[]/sig_action_mask[]数组(_LWP_NSIG = 64),因此越界或负的信号编号会导致内核堆越界读写,普通用户态程序可通过一次系统调用触发:oact回拷路径泄露内核堆内容;你的解决方案是什么 (what is your solution)
sys_sigaction()入口校验信号编号,仅接受[1, _LWP_NSIG],否则设置EINVAL并返回;lwp_signal_action()中增加相同的前置校验,保护后续新增的调用者。valid_signo_check()已存在于lwp_signal.c,但它允许sig == 0(符合kill(pid, 0)的语义),因此 sigaction 路径需要额外排除0。请提供验证的bsp和config (provide the config and bsp)
BSP: bsp/qemu-virt64-aarch64, bsp/qemu-virt64-riscv
.config: CONFIG_RT_USING_SMART=y CONFIG_RT_USING_LWP=y
action: 本地完成两平台编译与启动验证;RT-Smart 用户态 PoC 结果如下:
修复前上述非法信号不会被拒绝(系统调用返回 0,并执行越界访问)。修复后
qemu-virt64-aarch64与qemu-virt64-riscv均通过。当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up