Harden sys_getaddrinfo user-pointer handling for nested ai_addr writes - #11454
Harden sys_getaddrinfo user-pointer handling for nested ai_addr writes#11454BernardXiong with Copilot wants to merge 7 commits into
sys_getaddrinfo user-pointer handling for nested ai_addr writes#11454Conversation
|
|
sys_getaddrinfo user-pointer handling for nested ai_addr writes
📌 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-09-10 09:27 CST)
📝 Review Instructions
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
sys_getaddrinfoonly validated the top-level userresbuffer, then dereferencedres->ai_addrdirectly and wrote through that nested pointer in kernel context. In Smart/MMU builds, this allowed a user-controlled nested pointer to redirect kernel writes outside validated user memory.Copy user inputs into kernel temporaries
resandhintsinto kernel-ownedmusl_addrinfostructs before consuming their fields.Validate and isolate the nested output pointer
res->ai_addrfrom the copiedres.ARCH_MM_MMUbefore any writeback.Use user-copy helpers for all kernel-to-user writes
sockaddrinto a kernelmusl_sockaddrtemporary.lwp_put_to_user(...)instead of writing through the user pointer directly.musl_addrinfoback withlwp_put_to_user(...).Preserve existing syscall result semantics
hints-derivedai_socktype/ai_protocolbehavior.sal_getaddrinfo()results correctly.Example of the hardened flow: