[HUST CSE] drivers/ipc: validate pipe ioctl args#11373
[HUST CSE] drivers/ipc: validate pipe ioctl args#11373Aphlita wants to merge 1 commit intoRT-Thread:masterfrom
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-05-07 15:40 CST)
📝 Review Instructions
|
2ab9ab4 to
3cdff74
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens the pipe DFS ioctl handler in RT-Thread’s IPC driver layer by validating the output-argument pointer for FIONREAD/FIONWRITE, preventing NULL-pointer dereferences on invalid caller input.
本 PR 通过在 pipe 的 DFS ioctl 处理中对 FIONREAD/FIONWRITE 的输出参数指针进行校验,避免调用方传入空指针时触发空指针解引用,从而增强 IPC 驱动层的健壮性。
Changes / 变更点:
- Add
args == RT_NULLchecks forFIONREADandFIONWRITE, returning-EINVALon invalid input.
在FIONREAD/FIONWRITE分支增加args == RT_NULL检查,非法输入返回-EINVAL。 - Keep normal-path behavior unchanged for valid
args.
对正常传入有效参数的路径不改变行为。
| switch ((rt_ubase_t)cmd) | ||
| { | ||
| case FIONREAD: | ||
| if (args == RT_NULL) | ||
| { |
| case FIONWRITE: | ||
| if (args == RT_NULL) | ||
| { | ||
| ret = -EINVAL; | ||
| break; | ||
| } |
| case FIONREAD: | ||
| if (args == RT_NULL) | ||
| { | ||
| ret = -EINVAL; | ||
| break; | ||
| } | ||
| *((int*)args) = rt_ringbuffer_data_len(pipe->fifo); |
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
pipe_fops_ioctl()在处理FIONREAD和FIONWRITE命令时会直接解引用args。如果调用方传入空指针,pipe ioctl的错误路径会触发空指针解引用,而不是稳定返回错误码。你的解决方案是什么 (what is your solution)
在
FIONREAD和FIONWRITE分支中增加args == RT_NULL检查。当调用方传入空指针时返回-EINVAL,避免空指针解引用。该修改只影响pipe ioctl的异常输入路径,不改变正常传入有效输出参数时的行为。
请提供验证的bsp和config (provide the config and bsp)
bsp/simulatorbsp/simulator当前默认配置,无需额外修改本地验证:
git diff --check -- components/drivers/ipc/pipe.cscons -C /home/world/rt-thread/bsp/simulator -j2cppcheck --enable=warning,style,performance,portability --quiet components/drivers/ipc/pipe.c说明:
cppcheck仅报告pipe.c中既有style提示,未发现本次新增空指针校验相关问题。]
当前拉取/合并请求的状态 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