Repository navigation
ws2_offline: refuse the local computer's name, answer localhost with loopback literals, keep WSAIoctl synchronous (RT-WS2-OFFLINE-LOOKUP-LEAKS) - #2533
Conversation
…loopback literals, keep WSAIoctl synchronous From kevincommits' finding (batch 18, item 3) in ProjectLeonida#1608. - An empty name ("") passed is_loopback_node_a, so getaddrinfo, GetAddrInfoW, GetAddrInfoExA/W, gethostbyname and WSAAsyncGetHostByName forwarded it to the host, which answers with every address of the local computer (its LAN and external adapters). A null name did the same for gethostbyname and WSAAsyncGetHostByName. Both are refused now; a null getaddrinfo node (a service-only lookup: loopback, or the wildcard that bind narrows) is still answered. - "localhost" went to the host as a name, so its hosts file could map it off loopback. The lookups now hand the host a loopback literal for it (::1 for an AF_INET6 lookup, else 127.0.0.1), as WSAConnectByNameA/W already do. - WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) for ConnectEx and WSASendMsg passed the caller's overlapped and completion routine to the host along with pointers into its own stack frame. The host lookup is now synchronous, as in host_extension, and an overlapped request is reported as completed at once: status and byte count in the OVERLAPPED, its event set or its routine queued. ws2_offline_test gains section 9 for each case. With main's shim the test fails at gethostbyname(NULL) and then crashes; 83/83 checks pass with the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…SAIoctl lookup Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed at head Verification
Findings (Request changes)
AI-assisted review + local MSVC verification. |
…MERICHOST keeps localhost a name From timbot103's review of ProjectLeonida#2533. - The ConnectEx and WSASendMsg lookups no longer complete the caller's overlapped themselves (complete_now). That posted no packet for a socket on an I/O completion port, so a caller waiting in GetQueuedCompletionStatus hung, and it signalled an overlapped a socket without WSA_FLAG_OVERLAPPED must ignore; its APC record also leaked if the thread never waited alertably. The host's WSAIoctl now gets the caller's overlapped and completion routine again, so the completion is reported as Winsock reports it, but writes its own pointer and byte count into storage of the shim's (wrap_extension_lookup): freed when the call completed, kept if the host reports it pending. The caller's buffer holds the wrapper before the host is called, so a packet another thread dequeues already finds it, and gets its old contents back on failure. - With AI_NUMERICHOST, "localhost" is passed on as the name, so the host refuses it with EAI_NONAME instead of the shim answering with a literal. ws2_offline_test: a completion-port socket gets its packet with the wrapped pointer; on a socket without WSA_FLAG_OVERLAPPED the overlapped ends as the host's own WSAIoctl leaves it; getaddrinfo(localhost, AI_NUMERICHOST) is EAI_NONAME. The event and routine cases follow what Windows 11 does for this lookup (measured: event set, routine run once, packet posted, 0 bytes in the OVERLAPPED). The previous commit fails these 3 checks; 87/87 pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@timbot103 thanks, all four points were right. Fixed in 37163d1. 1 and 2 (completion port, non-overlapped sockets): The original problem was the stack frame, and that is fixed in
3a ( 3b (the APC record leak): gone with Evidence. What Windows 11 itself does for this lookup with an overlapped (a standalone probe on an overlapped socket):
The event and routine checks now expect what Windows does (no byte count in the OVERLAPPED). With the previous commit's shim these 3 new checks fail. With this one, 87/87 pass. Windows 11, MSVC (VS 18), RelWithDebInfo. AI-assisted (Claude Code) |
|
#2533 | head 37163d1 (merged cleanly with main 6dfca64) | |
timbot103
left a comment
There was a problem hiding this comment.
Static code audit against 37163d100 and ec740bcc3. I would request changes for four issues.
runtime/shims/ws2_offline.cpp:879adds a directWSAGetLastErrorimport. The standalone test linksws2_32, but the runtime without the optional Rust decoders has no such link dependency. Resolve it through the existing host lookup before calling the provider.runtime/shims/ws2_offline.cpp:270and:274drop::1forAF_UNSPECand null hints. A client cannot discover an IPv6-only localhost listener through these calls. Preserve both loopback families under those hints with native result ownership.runtime/shims/ws2_offline.cpp:876writes the wrapper before the provider readsin_buf. With shared input and output storage that overwrites the GUID. Pass the saved GUID through storage that survives the provider's use.runtime/shims/ws2_offline.cpp:885leaks the native scratch allocation on everyWSA_IO_PENDINGreturn, even after completion or cancellation. Give the storage a completion lifetime or guarantee synchronous lookup while preserving native notification behavior.
The reported Windows tests cover event, IOCP, APC and non-overlapped cases. Please add coverage for overlapping buffers, a forced pending result, both loopback families with default hints, and the Ex variants.
AI-assisted.
Claimed in the coordination issue as: RT-WS2-OFFLINE-LOOKUP-LEAKS (#1608 (comment))
What and why
Item 3 of @kevincommits' batch 18 in #1608 (#1608 (comment)). Thanks for the line-by-line report.
runtime/shims/ws2_offline.cppis what keeps a title off the network. Three gaps:is_loopback_node_a/wreturned true for a null and an empty name. Sogetaddrinfo,GetAddrInfoW,GetAddrInfoExA/W,gethostbynameandWSAAsyncGetHostByNamepassed""(and, for the last two,NULL) to the host. The host answers those with every address of the local computer: its LAN and external adapters.WSAConnectByNameA/Walready refused them.gethostbyname/WSAAsyncGetHostByNamealso refuse a null one (WSAHOST_NOT_FOUND).getaddrinfonode is still answered: it is a service-only lookup that gives loopback, or withAI_PASSIVEthe wildcard, which the shim'sbindnarrows to loopback.localhostand the hosts file.WSAConnectByNameA/Whand the host the literal127.0.0.1forlocalhost, so the hosts file is never read. The six lookup shims passed the name itself, so a hosts entry could map it off loopback.::1for anAF_INET6lookup, else127.0.0.1.gethostbynameandWSAAsyncGetHostByNameare IPv4 only, so they get127.0.0.1.AF_UNSPEClookup oflocalhosttherefore answers127.0.0.1only, where Windows also lists::1.WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER). ForWSAID_CONNECTEXandWSAID_WSASENDMSG, the shim passed the caller's overlapped and completion routine to the host, together with&real_extand&returnedin its own stack frame. If the host completed later, it would write into a frame that was gone.wrap_extension_lookup). The block is freed when the call completes and kept if the host reports it pending.WSA_FLAG_OVERLAPPED) is reported as Winsock reports it.AI_NUMERICHOST,localhostis passed on unchanged, so the host refuses it (EAI_NONAME).The header comment and
docs/runtime_imports.mddescribe the new rules.Overlap: #2241 (
connectand UDP) and #2242 (WSAConnectByNametolocalhoston IPv6 sockets) change other functions of this file and test. Whichever lands second may need a small rebase of the test file, which all three append to. With #2242,WSAConnectByNameand these lookups pick::1the same way: by the socket's or the lookup's family.Tested
Windows 11, MSVC (VS 18), RelWithDebInfo, on
main431ceba. Loopback only, no network.ws2_offline_testgains section 9:gethostbyname(NULL)andgethostbyname(""),WSAAsyncGetHostByNamewith a null or empty name,getaddrinfo("")andGetAddrInfoW(L"")are refused;getaddrinfo(NULL, "80")is still answered;getaddrinfo("localhost", AF_INET)answers127.0.0.1only,getaddrinfo("localhost.", AF_INET6)::1only, andgethostbyname("LOCALHOST")loopback only;WSAIoctlfor ConnectEx returns the same wrapped pointer as a plain one and sets its event;WSA_FLAG_OVERLAPPED, the overlapped ends as the host's own call leaves it;getaddrinfo("localhost", AI_NUMERICHOST)isEAI_NONAME;main's shim the test fails atgethostbyname(NULL)(the host answered with this computer's addresses) and then crashes later in section 9. With the fix, 87/87 checks pass (the review's three cases fail with the first version of this PR).scripts/check_no_game_data.py: clean.Not tested: a hosts file that maps
localhostelsewhere (the test does not edit the system's hosts file), and Wine.GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU tests only)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code