mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:25:52 +01:00
[PR #357] [MERGED] runtime: add offline loopback-only Winsock2 (ws2_32.dll) shim #410
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#410
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/357
Author: @Andretuta
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism
Base:
main← Head:feat/ws2-offline-shim📝 Commits (4)
9b59db0ws2_offline: add offline loopback-only Winsock2 (ws2_32.dll) shim (RT-WS2-OFFLINE)7f7a596Merge remote-tracking branch 'ubiq/main' into feat/ws2-offline-shimd7cdfcfws2_offline: per-socket extension pointers, refuse name-service lookups, close connect-by-name and octal bypasses, cover wsock321f88b25ws2_offline: loopback-bind unbound sends, refuse multicast joins and WSAJoinLeaf groups📊 Changes
8 files changed (+1567 additions, -8 deletions)
View changed files
📝
docs/boot.md(+3 -2)📝
docs/runtime_imports.md(+48 -3)📝
runtime/CMakeLists.txt(+16 -0)📝
runtime/shims/library_loader.cpp(+1 -1)📝
runtime/shims/registry.cpp(+2 -1)➕
runtime/shims/ws2_offline.cpp(+949 -0)➕
runtime/test/ws2_offline_test.cpp(+547 -0)📝
scripts/build_runtime.ps1(+1 -1)📄 Description
Claimed in the coordination issue as: RT-WS2-OFFLINE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7121196296)
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.