mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-16 01:05:15 +08:00
sys_getaddrinfo() validated the top-level res buffer, then wrote the resolved socket address through res->ai_addr, a user-controlled nested pointer that was never checked. On Smart/MMU builds a user program could therefore turn getaddrinfo() into an arbitrary kernel write. The hints fields were also read directly from user memory after the access check, leaving a TOCTOU window. Copy res and hints into kernel temporaries with lwp_get_from_user() so all nested pointers come from one validated snapshot. Write the nested sockaddr and the outer addrinfo back with lwp_put_to_user(), which validates the destination range and never dereferences an unchecked user pointer in kernel context. Also fix the servname copy check (a size_t result can never be < 0), allocate the kernel addrinfo with sizeof(*k_hints), and release k_res on the new error paths. Co-Authored-By: Claude Code <noreply@anthropic.com>