runtime: add offline loopback-only Winsock2 (ws2_32.dll) shim #357
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!357
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/357/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Andretuta on GitHub · 2026-11-24 03:53 UTC · original
ubiquitarianism:feat/ws2-offline-shim→main· +1567 −8 · 8 files · 4 commits · merged 2026-11-24 13:44 UTCClaimed in the coordination issue as: RT-WS2-OFFLINE (#14)
What and why
Closes the Winsock2 (
ws2_32.dll) offline boundary for mapped titles so nothing reaches external hosts or sends DNS queries while loopback IPC continues to work:runtime/shims/ws2_offline.cppand registersws2_32.dllas a partially overridden host DLL inruntime/shims/registry.cpp(socket bookkeeping such asWSAStartup,socket,closesocket,select,recv,send, andfreeaddrinfostay native).connect(#4),WSAConnect,WSAConnectByNameA/W,WSAConnectByList,sendto(#20),WSASendTo,WSASendMsg, andWSAIoctl-acquiredConnectEx/WSASendMsgextension pointers to IPv4 loopback (127.0.0.0/8), IPv6 loopback (::1), and IPv4-mapped IPv6 loopback (::ffff:127.0.0.0/104), refusing external destinations withWSAENETUNREACHand logging each refused target once. RefusesSIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTERwithWSAEINVAL.bind(#2) addresses (0.0.0.0,::) to127.0.0.1/::1and refuses non-loopback binds withWSAEADDRNOTAVAIL.getaddrinfo,GetAddrInfoW,GetAddrInfoExA/W,gethostbyname(#52),gethostbyaddr(#51), andWSAAsyncGetHostByName/Addr(#103/#102) to null/empty nodes,localhost, and loopback literals (WSAHOST_NOT_FOUNDotherwise), and forcesNI_NUMERICHOST(orWSAHOST_NOT_FOUNDwithNI_NAMEREQD) ongetnameinfo/GetNameInfoWfor non-loopback addresses.#2,#4,#20,#51,#52,#102,#103) on partially overridden host DLLs inruntime/shims/library_loader.cppso dynamicGetProcAddressby ordinal hits the same offline wrappers as static IAT binding.ws2_32.dlldynamically from System32 (LOAD_LIBRARY_SEARCH_SYSTEM32) so the runtime needs no extra static link library.ws2_offline_testinruntime/CMakeLists.txt, addsshims\ws2_offline.cpptoscripts/build_runtime.ps1, and updatesdocs/boot.mdanddocs/runtime_imports.md.Tested
ws2_offline_testlocally (Clang 23.1.3-std=c++20 -Wall -Wextra -Werror): 39 check(s), 0 failure(s) (verifying name + ordinal resolution, external IPv4/IPv6/hostname refusals, wrappedConnectEx/WSASendMsgviaWSAIoctl, wildcardbindnarrowing to127.0.0.1, DNS refusals +localhostallowance, and a real loopback UDP round-trip).runtime/shims/library_loader.cpp(-fsyntax-only -Wall -Wextra -Werror).python -I scripts/check_no_game_data.pyon all 8 touched files (exit 0) andpython -I tests/test_docs_links.py(16 tests OK).GPUs tested: n/a
AI-assisted: yes
Update after review (merged with current
main)ConnectExandWSASendMsgextension pointers are looked up per socket through the hostWSAIoctl, so each provider's own function is used.WSALookupServiceBeginA/Ware refused (WSASERVICE_NOT_FOUND), so name lookups cannot go around the shim.WSAConnectByNameA/Wconnect only tolocalhost/loopback literals; IPv4 literals with leading-zero octets (0127.0.0.1) are refused.wsock32.dllexports (bind,connect,sendto,gethostbyname,gethostbyaddrand the async lookups, by name and ordinal) go through the same checks;wsock32.dllis a partially overridden host DLL inowns_dll.scripts/build_runtime.ps1keeps main'sdstorage.cpp;docs/runtime_imports.mdno longer says--runcan open real sockets and names the remainingdnsapi.dllgap.ws2_offline_test52 checks, 0 failures (clang 23 / mingw x64); docs tests.Update after the second review (implicit binds and multicast)
sendto,WSASendTo,WSASendMsg(and itsWSAIoctlpointer) andWSAJoinLeafon an unbound socket bind it to127.0.0.1(or::1/::ffff:127.0.0.1for IPv6) before the host call. Microsoft'ssendto,WSASendToandWSAJoinLeafpages say an unbound socket is bound implicitly to the wildcard address. The new test shows the host doing exactly that (control:getsocknamegives0.0.0.0) and the shim giving127.0.0.1instead.setsockopt(#21) refuses group joins withWSAEADDRNOTAVAIL(IP_ADD_MEMBERSHIP,IP_ADD_SOURCE_MEMBERSHIP,MCAST_JOIN_GROUP,MCAST_JOIN_SOURCE_GROUP,IPV6_ADD_MEMBERSHIP); other options go to the host.wsock32.dll'ssetsockopt(#21) is its own export, not a forwarder (dumpbin on Windows 10), and takes Winsock 1 option numbers. So its shim also refusesIP_ADD_MEMBERSHIPas 5 (Wine'swsock32remap table: 5 -> 12) and forwards everything else to the hostwsock32.dll.WSAJoinLeaf(by name: ws2_32 has no fixed ordinal for it) refuses non-loopback groups withWSAENETUNREACH.tools/pe_inspect.py) listsWS2_32.dllordinals#20(sendto) and#21(setsockopt) among its 25 Winsock imports, so the implicit bind and the join refusals are on paths it links. It does not importWSAJoinLeaf,WSASendToorwsock32.dll; those stay covered in caseGetProcAddressor a package DLL reaches them.ws2_offline_test71 checks, 0 failures. The 19 new checks cover: the resolution of#21,WSAJoinLeafand thewsock32shim; the implicit binds against the host control; IPv4, IPv6 and Winsock 1 joins refused; TTL and buffer options passed through;WSAJoinLeafrefused. Docs tests: 47 passed.Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
@QemmHD on GitHub · 2026-11-24 05:28 UTC · original
The network boundary looks right: it fails closed, the host DLL is loaded with
LOAD_LIBRARY_SEARCH_SYSTEM32, wildcard binds are narrowed to loopback, ConnectEx and WSASendMsg are wrapped, and the RIO multi-pointer request is refused. Gaps worth closing so "loopback only" holds:WSAJoinLeafisn't wrapped (a nativesend()can then reach a multicast group),WSALookupServiceBegin/Nextaren't wrapped (DNS can still go out), an unbound UDPsendtogets an implicit wildcard bind, and multicast joins viasetsockoptaren't blocked;dnsapi,iphlpapiICMP and mswsockGetAddressByNameare outside the shim. Also needs a rebase.Security review; read only, nothing run.
AI-assisted (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.
@QemmHD on GitHub · 2026-11-24 14:10 UTC · original
Post-merge check of main
d0da7dadeon Windows 11 / RTX 4070 SUPER (VS 2022, Ninja, RelWithDebInfo):ws2_offlinepasses, and full ctest is 304/306 with the same two pre-existing failures as before the merge (d3d12_execute_indirect_validation, d3d12_depth_resolve).One gap, low severity, reproduced on this PC: multicast joins through
WSAIoctlwithSIOCSIPMSFILTER(0x8004747D, what ws2tcpip.h's inlinesetipv4sourcefilteruses) orSIOCSMSFILTERreach the host.wsa_ioctl_offlinepasses those codes through (runtime/shims/ws2_offline.cpp:885). A UDP socket bound to 127.0.0.1 joined 239.255.77.77 on the real Wi-Fi interface. That contradicts the "every join is refused" comment atws2_offline.cpp:511-512. The title doesn't importWSAIoctlstatically (docs/runtime_imports.md), so this is LAN-only and needs a dynamic lookup. Refusing those two ioctl codes the same wayIP_ADD_MEMBERSHIPis refused would close it.I found no DNS leak:
[::1]and zone-suffixed loopback forms resolve locally, and the getaddrinfo family stays offline.AI-assisted (Claude Code, Claude Opus 5.5).