Repository navigation
Loopback: 127/8, ::1 and own addresses stay inside the stack - #21
Closed
KoganTheDev wants to merge 13 commits into
Closed
KoganTheDev wants to merge 13 commits into
KoganTheDev wants to merge 13 commits into
Conversation
…e wire A datagram to 127.0.0.0/8 or to one of the stack's own addresses is built as for the wire and queued (bounded, 1024; overflow counts loopback_drops) instead of routed, ARPed and transmitted. poll() delivers the queue before the channels, capped at half the frame budget and only what was queued at the start, so replies wait for the next call and no send re-enters a receive path. ms_until_next_timer() is 0 while the queue is non-empty and poll() returns false until it is empty. Source address is the destination (Linux's rule), so a reply matches its connection. MSS on a local route comes from LOOPBACK_MTU (65535). A 127/8 source or destination arriving on a real interface is dropped and counted (RFC 1122 3.2.1.3), which also keeps forwarding away from loopback. The IPv6 half is stubbed here and lands next. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_send_ipv6_packet queues a local destination instead of resolving a neighbour; the source for a local destination is the destination itself (so ::1 needs no configured address); a connection to a local peer needs no route. _handle_ipv6 is split so the loopback queue reaches the same address checks and transport demux as a frame from the wire, and ::1 as source or destination on a real interface is dropped and counted (RFC 4291 2.5.3). MSS on a local v6 route is LOOPBACK_MTU less 60. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A packet arriving on a real interface whose source is one of this stack's own addresses (Linux's fib_validate_source rule) is dropped and counted, v4 and v6. Accepted, its replies would be addressed to a local address and land in the loopback queue, so a spoofed SYN with source == destination and equal ports (LAND) made the stack talk to itself. The unspecified v6 source used by DAD and router solicitation is not an own address and still passes. Also makes is_local_address() public for the socket layer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eal driver bind() accepts any 127/8 address and ::1 (previously only the interface's own address), and a UDP datagram to a local address is sized by the loopback MTU rather than the interface's. Tests drive socket/bind/listen/connect/ accept/send/recv over 127.0.0.1, an own address and ::1 through the sim driver on a channel that fails on any write, and a connect over the real driver, which only completes because ms_until_next_timer() is 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Found by the loopback differential: a ustack socket layer binds port 0 from its own counter and connect() from the stack's, both starting at 49152, so a connect to a local listener came from the listener's own port - source == destination, equal ports - and was a connection to itself. Harmless between two hosts, fatal on loopback. The allocator now steps over listening ports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The same scenarios run with ustack talking to itself over 127.0.0.1 / ::1 on a channel that fails on any write, compared line by line with the kernel's own loopback. Both stacks agree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ADME section The stateful harness now sends datagrams and one connection to 127.0.0.1 and ::1 whenever its application runs, and seven new seeds put loopback and own-address sources and destinations on the wire (the martian paths, incl. LAND). README gains a Loopback section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…receive _send_tcp_segment, _send_udp_datagram and _send_icmp_message ask once and hand the answer to _source_address_for and _send_ip_packet. The per-packet receive check read IPv4Address temporaries, each a heap Bytes; it now works on the header's octets. SimulatedBulkTransfer/0: 6.02 -> ~5.9 ms (base 5.82). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Item E, the last of the follow-up plan. A packet to 127.0.0.0/8 or to the stack's own address used to go out a real interface and ARP; a local application could not reach the stack through itself. Stacked on #20.
::1or an own v4/v6 address go into a queue bounded at 1024 datagrams and 4 MiB, drained bypoll()before the channels (capped at half the frame budget;poll()returns false andms_until_next_timer()is 0 while it holds anything). Delivery is deferred, never re-entrant.::1and own-address sources are dropped and counted - this also closes the LAND-style self-loop an automated security review found.Tests
Every loopback test stack's real channel fails the test on any write, so a pass cannot come from traffic leaking out. v4 and v6 TCP, UDP, ping, queue bounds (count and bytes), martian/LAND drops; ustack sockets over 127.0.0.1, an own address and
::1; loopback cases in the ustack-vs-kernel differential (v4 and v6); fuzz seeds and loopback sends in the stateful harness.make test(1318), asan, tsan, strict,SIM_SEEDS=2000 make sim,FUZZ_SECONDS=30 make fuzz, clang-format, clang-tidy, cppcheck. Bench: SimulatedBulkTransfer back within noise of the base (5.82 -> 5.84 ms), EchoBurst slightly faster.🤖 Generated with Claude Code