components/lwp: use bounded formatting in tty_ptmx.c#11447
components/lwp: use bounded formatting in tty_ptmx.c#11447orbisai0security wants to merge 2 commits into
Conversation
Automated security fix generated by OrbisAI Security
The sprintf() call at line 293 in the kernel's PTY subsystem writes a formatted string combining root_path and dev_rel_path into the device_name buffer without any bounds checking
|
👋 感谢您对 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)
🏷️ Tag: components_lwpReviewers: @xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-06-08 15:35 CST)
📝 Review Instructions
|
| @@ -0,0 +1,96 @@ | |||
| #include <check.h> | |||
There was a problem hiding this comment.
不存在 /tests 这样的目录,这样合并PR会对整体代码结构都会破坏掉了。
Summary
Replace unbounded string formatting in
tty_ptmx.cwith bounded formatting.Rationale
lwp_ptmx_init()currently allocatesdevice_namebased onstrlen(root_path) + sizeof("/ptmx"), so the existingsprintf()is not obviously exploitable in normal use. However, usingsnprintf()keeps the code consistent with safer bounded string handling and avoids future mistakes if the allocation logic changes.This also replaces
strncpy()insysptmx_readlink()withsnprintf()so the output buffer is NUL-terminated whenlen > 0.Security impact
Defensive hardening; no confirmed exploit claimed.
Changes
components/lwp/terminal/tty_ptmx.csnprintf()when constructing the ptmx device name.snprintf()for the sysptmx readlink target.Description: The sprintf() call at line 293 in the kernel's PTY subsystem writes a formatted string combining root_path and dev_rel_path into the device_name buffer without any bounds checking. If the combined length exceeds the buffer size, a stack buffer overflow occurs. This code runs in kernel context as part of pseudo-terminal device creation, making exploitation particularly severe.
Evidence
Scanner confirmation: multi_agent_ai rule
V-004flagged this pattern.Production code: This file is in the production codebase, not test-only code.
Verification
Security Invariant
Regression test
This test guards against regressions — it's useful independent of the code change above.
Automated security fix by OrbisAI Security