diff options
| author | andretuta <andreviniciusmerlia@gmail.com> | 2026-11-24 02:42:07 -0300 |
|---|---|---|
| committer | andretuta <andreviniciusmerlia@gmail.com> | 2026-11-24 02:42:07 -0300 |
| commit | d7cdfcf25500503fbd694fb6eb949b694ae71bdf (patch) | |
| tree | b373008d61f4d167d4f30bccd6ad803aa6b6aa14 /docs | |
| parent | 7f7a5968563718098c3c592193ecb8da14e7d49a (diff) | |
ws2_offline: per-socket extension pointers, refuse name-service lookups, close connect-by-name and octal bypasses, cover wsock32
Review fixes for #357:
- ConnectEx / WSASendMsg wrappers ask the host for the pointer of the socket they run on, instead of one
process-wide pointer that the last WSAIoctl on any provider overwrote.
- WSALookupServiceBeginA/W fail with WSASERVICE_NOT_FOUND.
- WSAConnectByNameA/W hand the host the literal 127.0.0.1 for "localhost", so the hosts file is never read.
- A dotted octet with a leading zero (0127.0.0.1) is refused: Windows reads it as octal.
- wsock32.dll maps bind/connect/sendto/gethostby*/WSAAsyncGetHostBy* (names and ordinals) to the same wrappers and
stays host-owned in owns_dll, like ws2_32.dll.
- docs/runtime_imports.md no longer says a --run can open real sockets; it names the dnsapi.dll gap.
Tested: ws2_offline_test built with clang 23 (msys2 clang64) on Windows: 52 checks, 0 failures. MSVC build not
available locally; CI covers it. tests/test_docs_*.py, test_text_write_line_endings.py, test_runtime_paths.py pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/runtime_imports.md | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md index fb266b719..3187d2160 100644 --- a/docs/runtime_imports.md +++ b/docs/runtime_imports.md | |||
| @@ -188,9 +188,10 @@ What this does not show: `--run` has not been run, so the entry point has not be | |||
| 188 | reached on the way to the first frame. A bound import is not a working one (the binding only says a function with | 188 | reached on the way to the first frame. A bound import is not a working one (the binding only says a function with |
| 189 | that name exists), and an unimplemented import stops the run only if the title calls it | 189 | that name exists), and an unimplemented import stops the run only if the title calls it |
| 190 | ([When an unimplemented import is called](#when-an-unimplemented-import-is-called)). The executable imports 25 | 190 | ([When an unimplemented import is called](#when-an-unimplemented-import-is-called)). The executable imports 25 |
| 191 | functions from `ws2_32.dll` (23 by ordinal, plus `getaddrinfo` and `freeaddrinfo`) and the loader binds them to the | 191 | functions from `ws2_32.dll` (23 by ordinal, plus `getaddrinfo` and `freeaddrinfo`). The `ws2_offline` shim now serves the |
| 192 | host's, so a `--run` can open real sockets: run it with the network off. `winhttp.dll` is served by the offline shim, | 192 | outbound and name-resolution calls among them, loopback only (see the Winsock2 section below), and the remaining |
| 193 | which opens none. | 193 | imports bind to the host's. `winhttp.dll` is served by the offline shim, which opens none. Known gap: `dnsapi.dll` |
| 194 | (`DnsQuery*`) is not shimmed, so a title that calls it reaches the host's resolver. | ||
| 194 | 195 | ||
| 195 | ## Console paths and the write overlay | 196 | ## Console paths and the write overlay |
| 196 | 197 | ||
| @@ -633,21 +634,33 @@ asynchronous paths with `.invalid` names; it opens no connection. | |||
| 633 | `runtime/shims/ws2_offline.cpp` intercepts outbound Winsock2 entry points — both by name and by standard Windows | 634 | `runtime/shims/ws2_offline.cpp` intercepts outbound Winsock2 entry points — both by name and by standard Windows |
| 634 | `ws2_32.dll` ordinal (`bind`/`#2`, `connect`/`#4`, `sendto`/`#20`, `gethostbyaddr`/`#51`, `gethostbyname`/`#52`, | 635 | `ws2_32.dll` ordinal (`bind`/`#2`, `connect`/`#4`, `sendto`/`#20`, `gethostbyaddr`/`#51`, `gethostbyname`/`#52`, |
| 635 | `WSAAsyncGetHostByAddr`/`#102`, `WSAAsyncGetHostByName`/`#103`, `getaddrinfo`, `GetAddrInfoW`, `GetAddrInfoExA/W`, | 636 | `WSAAsyncGetHostByAddr`/`#102`, `WSAAsyncGetHostByName`/`#103`, `getaddrinfo`, `GetAddrInfoW`, `GetAddrInfoExA/W`, |
| 636 | `getnameinfo`, `GetNameInfoW`, `WSAConnect`, `WSAConnectByNameA/W`, `WSAConnectByList`, `WSASendTo`, `WSASendMsg`, and | 637 | `getnameinfo`, `GetNameInfoW`, `WSAConnect`, `WSAConnectByNameA/W`, `WSAConnectByList`, `WSASendTo`, `WSASendMsg`, |
| 637 | `WSAIoctl` for `WSAID_CONNECTEX` and `WSAID_WSASENDMSG`) — while keeping `ws2_32.dll` partially overridden so local | 638 | `WSALookupServiceBeginA/W`, and `WSAIoctl` for `WSAID_CONNECTEX` and `WSAID_WSASENDMSG`). `wsock32.dll` maps its |
| 638 | socket bookkeeping (`WSAStartup`, `socket`, `closesocket`, `select`, `recv`, `send`, byte-order helpers) still works | 639 | `bind`, `connect`, `sendto`, `gethostbyaddr`, `gethostbyname` and `WSAAsyncGetHostBy*` exports (and their ordinals) to |
| 639 | for loopback traffic: | 640 | the same wrappers, since its exports forward to `ws2_32.dll` natively; like `ws2_32.dll` it stays host-owned |
| 641 | (`owns_dll`), so `LoadLibrary` returns the real module. The shim keeps `ws2_32.dll` partially overridden | ||
| 642 | so local socket bookkeeping (`WSAStartup`, `socket`, `closesocket`, `select`, `recv`, `send`, byte-order helpers) still | ||
| 643 | works for loopback traffic: | ||
| 640 | 644 | ||
| 641 | - `connect`, `WSAConnect`, `ConnectEx`, `sendto`, `WSASendTo`, `WSASendMsg`, `WSAConnectByNameA/W` and | 645 | - `connect`, `WSAConnect`, `ConnectEx`, `sendto`, `WSASendTo`, `WSASendMsg`, `WSAConnectByNameA/W` and |
| 642 | `WSAConnectByList` allow only IPv4 loopback (`127.0.0.0/8`), IPv6 loopback (`::1`) and IPv4-mapped loopback | 646 | `WSAConnectByList` allow only IPv4 loopback (`127.0.0.0/8`), IPv6 loopback (`::1`) and IPv4-mapped loopback |
| 643 | (`::ffff:127.0.0.0/104`); everything else fails with `WSAENETUNREACH`. | 647 | (`::ffff:127.0.0.0/104`); everything else fails with `WSAENETUNREACH`. |
| 648 | - `WSAConnectByNameA/W` pass `localhost` to the host as the literal `127.0.0.1`, so the host never reads its hosts | ||
| 649 | file. Numeric loopback literals pass through unchanged. | ||
| 650 | - `ConnectEx` and `WSASendMsg` from `WSAIoctl` are the host's own pointers, fetched for the socket they are called on | ||
| 651 | (each Winsock provider has its own), after the same loopback check. | ||
| 644 | - `bind` narrows wildcard binds (`0.0.0.0`, `::`) to loopback (`127.0.0.1`, `::1`) and refuses other non-loopback | 652 | - `bind` narrows wildcard binds (`0.0.0.0`, `::`) to loopback (`127.0.0.1`, `::1`) and refuses other non-loopback |
| 645 | addresses with `WSAEADDRNOTAVAIL`. | 653 | addresses with `WSAEADDRNOTAVAIL`. |
| 646 | - Forward lookups refuse external names with `WSAHOST_NOT_FOUND` without sending DNS traffic; `getnameinfo` / | 654 | - Forward lookups refuse external names with `WSAHOST_NOT_FOUND` without sending DNS traffic. A dotted octet with a |
| 647 | `GetNameInfoW` force `NI_NUMERICHOST` (or return `WSAHOST_NOT_FOUND` under `NI_NAMEREQD`) for non-loopback addresses. | 655 | leading zero (`0127.0.0.1`) is refused too: Windows reads it as octal, so it is not the loopback address it looks |
| 648 | 656 | like. `getnameinfo` / `GetNameInfoW` force `NI_NUMERICHOST` (or return `WSAHOST_NOT_FOUND` under `NI_NAMEREQD`) for | |
| 649 | `runtime/test/ws2_offline_test.cpp` (ctest `ws2_offline`) verifies name and ordinal bindings, external refusals using | 657 | non-loopback addresses. |
| 650 | RFC 5737 / RFC 3849 / `.invalid` targets, wildcard-bind narrowing, and a local loopback UDP round-trip. | 658 | - `WSALookupServiceBeginA/W` (name-service queries) always fail with `WSASERVICE_NOT_FOUND`. |
| 659 | |||
| 660 | `runtime/test/ws2_offline_test.cpp` (ctest `ws2_offline`) verifies name and ordinal bindings, the `wsock32.dll` | ||
| 661 | aliases, external refusals using RFC 5737 / RFC 3849 / `.invalid` targets, the `0127.0.0.1` refusal, the | ||
| 662 | `WSASERVICE_NOT_FOUND` refusal, wildcard-bind narrowing, a `ConnectEx` pointer from `WSAIoctl` connecting to a loopback | ||
| 663 | listener, and a local loopback UDP round-trip. | ||
| 651 | 664 | ||
| 652 | ## What this proves and what it does not | 665 | ## What this proves and what it does not |
| 653 | 666 | ||