aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / net / tcp / README.md
| 1 | # native/net/tcp: native TCP in seeded Omega (ledger L232) |
| 2 | |
| 3 | TCP over IPv4 and ARP, written in Omega and built by the pinned seeded `omc`. |
| 4 | The pin is the `omc-sha256` line of the repository's one `PIN` file, which |
| 5 | `gate.sh` reads and checks; it refuses any other compiler. No C, no heap, no outside library |
| 6 | in the stack or its drivers. |
| 7 | |
| 8 | | File | What it is | |
| 9 | |---|---| |
| 10 | | `tcp.om` | The stack: Ethernet II, ARP (4 entries), IPv4 (no options sent, fragments refused), TCP per RFC 9293 with RFC 6298 RTO, RFC 5681/6582 NewReno congestion control and fast retransmit, RFC 5961 RST/SYN/ACK hardening, out-of-order reassembly into a 64 KiB ring (first copy wins), FIN ordering, TIME-WAIT, zero-window probing. One connection block plus one passive port. The embedding unit supplies `tlinkout` and the clock. | |
| 11 | | `tcpd.om` | Guest driver (`cat tcp.om tcpd.om \| omc`). Runs as a process inside a Linux guest: rtnetlink brings `eth0` up with GRO off, an AF_PACKET socket carries raw frames. The guest kernel has no IPv4 address, so this stack alone answers for 10.0.2.15. Modes: echo, receive to file, send a file. | |
| 12 | | `link.om` | Impairment relay between the guest NIC and QEMU's slirp network: seeded drop, hold-back reordering, duplication, and hostile injection toward the guest (15 kinds, see the `lmutate` note). Hostile variants go ahead of the real frame. | |
| 13 | | `peer.om` | Host peer on 127.0.0.1 (slirp forwards into the guest): echo check, send, receive and compare. | |
| 14 | | `corpus.om` | Hosted hostile corpus (`cat tcp.om corpus.om \| omc`): exact-state cases, a seeded fuzz phase with invariants, and a final transfer whose sequence numbers wrap past 2^32. | |
| 15 | | `gate.sh` | The gate (verification rig, POSIX sh): checks the compiler pin, builds everything, runs the corpus, then boots one fresh QEMU guest per profile and scenario. | |
| 16 | |
| 17 | ## Gate |
| 18 | |
| 19 | ``` |
| 20 | sh gate.sh OMC IMAGE BUSYBOX OUTDIR [PROFILES] [SCENARIOS] |
| 21 | ``` |
| 22 | |
| 23 | Profiles (per mille, per direction): `clean` (none), `loss` (3% drop), |
| 24 | `reorder` (15% held back 1 to 3 frames or 40 ms), `hostile` (2% drop, 10% |
| 25 | reorder, 2% duplicate, 20% hostile injection toward the guest). Scenarios: |
| 26 | `echo` (1 MiB echoed back to the host), `h2g` (2,000,000 bytes host to guest, |
| 27 | digest checked in the guest with busybox `sha256sum`), `g2h` (the 1,914,704 byte |
| 28 | busybox binary guest to host). A run passes only when the peer, the guest |
| 29 | stack, QEMU's exit and the digest all agree (echo bytes are compared one by |
| 30 | one by `peer.om`), and the link log proves the profile's impairments happened; |
| 31 | a hostile run must have injected all 15 kinds. The corpus runs 2,000,000 fuzz |
| 32 | frames by default (`FUZZ=`). |
| 33 | |
| 34 | Verification-only dependencies (not in the stack): QEMU `qemu-system-aarch64` |
| 35 | with KVM, a Linux arm64 `Image` with virtio-net and AF_PACKET, a static |
| 36 | aarch64 busybox (guest init, `sha256sum`, and the g2h payload), POSIX sh, |
| 37 | gzip, cpio, sha256sum, sed and timeout. |
| 38 | |
| 39 | Oracle defect (QEMU's slirp, libslirp 4.7.0-1ubuntu3.1, unchanged on upstream |
| 40 | master): `tcp_input` runs `tcp_dooptions` on every segment outside LISTEN, and |
| 41 | an MSS option on a SYN calls `tcp_mss`, whose `sbreserve` resets the socket's |
| 42 | send buffer (`sb_cc = 0`). A duplicated or late SYN-ACK that reaches slirp |
| 43 | after it has buffered host data therefore silently discards that data. Found |
| 44 | when a hostile echo run lost 113,152 bytes inside slirp (packet capture: slirp's |
| 45 | second segment carried file offset 114,612 at stream offset 1,460). The relay |
| 46 | therefore never holds back or duplicates SYN segments travelling toward slirp; |
| 47 | the stack answers a duplicate SYN in syn-received with a plain ACK (RFC 9293). |
| 48 | Residual: if the relay drops slirp's handshake ACK and every following slirp |
| 49 | segment for the guest's 1 s SYN-ACK timer, the retransmitted SYN-ACK can still |
| 50 | hit the defect; no run has shown it. |
| 51 | |
| 52 | ## Limits (not claimed) |
| 53 | |
| 54 | - One connection at a time; no window scaling, SACK or timestamps; receive |
| 55 | window 65,535 bytes; TIME-WAIT is 1 s (`Tcf 8`), not 2 MSL of minutes. A |
| 56 | passive block whose SYN-ACK is never answered returns to LISTEN when its |
| 57 | retries run out (12 retransmissions, given up at the 13th timeout, 483 s), |
| 58 | as it does on an exact RST. |
| 59 | Until then every other client's SYN gets a RST, so one unanswered SYN |
| 60 | every 8 minutes keeps the only listener busy. |
| 61 | - The minimum RTO is 200 ms (`Tcf 10`), below RFC 6298's 1 s (rule 2.4, a |
| 62 | SHOULD), so recovery on a fast link does not wait a full second. |
| 63 | - Challenge ACKs (RFC 5961 sections 3 to 5) are not rate limited (section 7 |
| 64 | recommends a limit): every forged in-window RST or SYN, or out-of-range ACK, |
| 65 | gets one ACK. |
| 66 | - Fixed tables: 4 ARP entries reused round robin (any on-link host can evict |
| 67 | the gateway entry, as ARP is unauthenticated) and one connection block. The |
| 68 | drivers' main loops (`tcpd` 100,000,000 passes, `link` 1,000,000,000) trap |
| 69 | if ever reached; the gate's deadlines (QEMU 200 s, link 230 s) end a run |
| 70 | long before that. |
| 71 | - Blind in-window forgery is inherent to TCP without authentication: an |
| 72 | attacker who knows the 4-tuple and lands a sequence number exactly at |
| 73 | RCV.NXT can reset the connection (RFC 5961 narrows this to one exact value). |
| 74 | The QEMU hostile profile therefore injects only frames a correct stack must |
| 75 | refuse in every state: on handshake segments (SYN set or ACK clear) only the |
| 76 | malformed kinds 0 to 5, on ARP only garbage frames, because a RST with an |
| 77 | acceptable ACK or a SYN-ACK with a foreign ISS is legal there. Exact-state |
| 78 | cases (in-window RST, SYN, ACK range, SYN-SENT reset) are in the corpus. |
| 79 | - ARP is unauthenticated (RFC 826). |
| 80 | - QEMU only. The stack runs as a Linux guest process over AF_PACKET; it is not |
| 81 | bound into the AIENOS kernel's virtio-net driver and has not run on hardware. |