interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / net / README.md

273 lines · 19020 bytes Raw Blame History Rendered
1# native/net: AIENOS M6-A hosted network stack (C)
2
3C port of the Rust reference `crates/aienos-kernel/src/net.rs` and
4`virtio_net.rs` (read as the spec, not extended), plus a framed
5control-transport stub. No Rust, no Python, no heap, no outside library.
6
7| File | What it is |
8|---|---|
9| `aienos_net.{h,c}` | Ethernet II, ARP + fixed ARP cache, IPv4 (no reassembly), ICMP echo, UDP. Bounded parsers; error order matches the reference. |
10| `aienos_virtio_pci.{h,c}` | virtio 1.x PCI vendor-capability walk over a config image (no device access). Accepts the real QEMU virtio-net-pci layout (see Lane 26 below). |
11| `aienos_virtio_net.{h,c}` | Lane 26: virtio-net driver core, split virtqueues, polled. New C written from the virtio 1.x spec (the Rust reference has no queue code). Device access only through a small ops struct. |
12| `aienos_ctl.{h,c}` | Control-transport stub: authenticated frames, ordered exactly-once delivery, retransmit, link-down. **TEST identity only.** The frame format is specified in the header. |
13| `x25519.{h,c}` | M6-B: X25519 (RFC 7748), constant-time ladder, small-order outputs refused. |
14| `aienos_sec.{h,c}` | M6-B: mutually authenticated secure control transport over the M6-A UDP framing. **TEST identities only.** The wire format is specified in the header. |
15| `aienos_rtl8127.{h,c}` | L198: driver core for the Spark's Realtek RTL8127 10 GbE (10ec:8127), polled, one DMA region, TX no-close, RX type 1, interrupts masked. Realtek publishes no datasheet (DOCS SILENT); written from Realtek's Linux r8127 v11.014.00. Tested only against a chip model (`tests/rtl8127_test.c`); never run on the chip. Details and the UNKNOWN list: `docs/SPARK_RTL8127.md`. |
16| `aienos_report.{h,c}` | L198: a boot report as UDP broadcast datagrams (the iMac wire format, tag as a parameter; the Spark uses `AIENUX-SPARK-REPORT`). |
17| `tcp/` | L232: native TCP over IPv4/ARP in seeded Omega (`tcp.om`), with a QEMU gate under loss, reordering and hostile injection, and a hosted hostile corpus. See `tcp/README.md`. QEMU only; not bound into the kernel NIC path. |
18
19## Tests (`make test`, `make sanitize`)
20
21- `tests/net_test.c`: the reference's own vectors, malformed negatives
22 (every truncation, bad lengths, bad checksums, ihl/version/ttl/flags,
23 oversize builds, capability loops, short caps, bad regions, duplicates),
24 build/parse round trips with single-bit corruption, seeded random hostile
25 inputs with bounds checks on every returned view.
26- `tests/ctl_test.c`: seeded simulated link with loss, duplication,
27 corruption, reordering and blackouts; every scenario runs twice and must be
28 bit-identical; refusal cases (truncation, trailing byte, header fields,
29 tag coverage, wrong key, reflection, wrong session, non-TEST identity,
30 forged ack, capacity, window, sequence exhaustion, sticky link-down).
31- `tests/net_diff.c` + `make diff-check`: a 200,000-record structure-aware
32 hostile corpus. Its canonical output was compared byte for byte with the
33 unmodified Rust reference run by a scratch driver kept outside this repo
34 (no Rust in AIENOS code); the agreed digest is pinned in the Makefile.
35- `make receipt`: clean-tree-only, content-addressed receipt in `receipts/`.
36
37## Deliberate differences from the reference
38
39- Checksums accumulate in 64 bits (the Rust `u32` sum overflows above
40 about 128 KiB of input).
41- NULL pointer or argument misuse returns an error instead of being
42 impossible by type.
43- The ARP cache reuses an expired entry when learning (the reference only
44 frees expired entries during a lookup, so a full cache refused new senders
45 until some lookup ran). Found by the Codex review.
46
47## Not claimed (deferred, with the dependency)
48
49- Physical binding (real NIC, interrupts): the virtio-net driver is bound in the C kernel by `native/kernel/dev/net_bind.c` (#200 d75a266 attach and split virtqueue driver, #203 9807281 kernel hook, NET gate PASS in QEMU only). It is polled (no IRQs) and uses TEST keys. Lane 31 negotiates and requires VIRTIO_F_ACCESS_PLATFORM so the NIC DMA should go through the SMMU window, and the NET gate script now checks that an out-of-window DMA is refused; QEMU PASS on this branch (receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`, forge log of `scripts/qemu_ck_net_test.sh`), QEMU only; hardware NOT_RUN for virtio-net. Physical Ethernet drivers live in the kernel, not here: the Raspberry Pi 5 RP1 GEM (`native/kernel/dev/pi5_gem.c`, one frame sent on the wire, `docs/native/PI5-NET-3-RUNS.md`) and the 2017 iMac BCM57766, transmit only (`native/kernel/x86/tg3_x86.c`). The 2026-10-17 iMac run found that chip with the link down (`evidence/imac_kernel1_2026-10-17/`); frame transmit is hardware-unverified. Neither receives traffic yet. The Spark's RTL8127 driver (`aienos_rtl8127.c`, L198) exists but has run only against a chip model; it is bound by `native/kernel/dev/rtl8127_bind.c` only in a `CK_RTL8127=1` image, hardware NOT_RUN (hardware-unverified).
50- Production identity and keys: needs M5 (key hierarchy, TRUST-1). The M6-B
51 secure transport below exists as hosted code but runs on TEST keys only. The stub refuses every identity kind except TEST, whose key is
52 derived from a public label and so protects nothing against an attacker.
53- Physical NIC qualification: the Machine 1 wave after TRUST-1 Gate 7.
54- DHCP, NDP/IPv6, fragment reassembly: not in the reference; later M6 work.
55 TCP now exists in Omega under `tcp/` (L232), exercised in QEMU only.
56- The ARP cache stores whatever reply the caller marks solicited; gating
57 spoofed replies is the caller's job (same as the reference).
58
59## M6-B: secure control transport (hosted)
60
61`aienos_sec` puts a mutually authenticated, encrypted session between two
62AIENOS machines. Each datagram is one UDP payload of the M6-A stack. Make
63targets: `make secure` runs everything below and prints
64`AIENOS_NET_SECURE: PASS/FAIL`; `make mutants` runs the mutant pass alone.
65
66**Scope.** The design follows the SIGMA pattern (sign, then MAC), in three
67messages:
68
69- **Identities.** Ed25519 keys (`native/sig`). Each side is configured with
70 the single peer key it accepts.
71- **Key exchange.** Fresh ephemeral X25519 keys (`x25519.c`) for every
72 session.
73- **Key derivation.** HKDF-SHA256 built on `native/crypto`'s HMAC.
74- **Binding.** Each signature and each finished MAC covers a hash of every
75 handshake byte so far, so messages from two sessions cannot be spliced
76 together.
77- **Records.** AES-256-GCM-SIV, one key per direction. The nonce is the
78 direction plus a 64-bit counter, and the 24-byte record header is
79 authenticated.
80- **Replay.** A 64-record replay window.
81- **Rekey.** A one-way key ratchet every `rekey_interval` records (at least
82 128). The old key is wiped. The receiver keeps one previous epoch key so
83 that reordering across a boundary still works.
84- **Limits.** A hard `max_records` cap (`EXHAUSTED` once reached, so a new
85 handshake is needed), and an authenticated CLOSE that wipes keys on both
86 sides.
87- **Handshake loss.** Resend timers, plus an answer to a repeated HS1 or HS3.
88- **Data loss.** Recovered by carrying M6-A `aienos_ctl` frames inside the
89 secure records (ordered, exactly once).
90- **Parsers.** Every parser checks the total length first. A refused message
91 changes no state.
92
93**What is proven, hosted only** (`tests/x25519_test.c`, `tests/sec_test.c`,
94two in-process machines over real M6-A Ethernet/IPv4/UDP frames):
95
96- **X25519.**
97 - The RFC 7748 vectors pass: section 5.2 (single vectors, plus 1 and 1000
98 iterations) and section 6.1.
99 - The 1,000,000-iteration vector passes with `X25519_LONG=1` (run once by
100 hand; not part of `make test`).
101 - Small-order inputs are refused.
102- **HKDF.** RFC 5869 test case 1 passes.
103- **Handshake.** It succeeds, and the two sides end up with matching keys
104 and session id. Ephemeral and intermediate secrets are wiped.
105- **Identity.**
106 - A wrong identity is refused in both directions.
107 - Impersonation is refused: claiming the expected key while signing with
108 another key fails, even with a valid finished MAC.
109- **Tampering.** A one-byte change at every position of HS1, HS2 and HS3 is
110 refused, and no handshake completes. The following are also refused:
111 - splicing HS2 or HS3 from a concurrent session
112 - replaying an old HS2
113 - a weak (small-order) key share, even when correctly signed
114 - a different HS1 sent mid-handshake
115- **Replay window.**
116 - A replayed record is refused.
117 - Records reordered inside the window, including fully shuffled, are
118 accepted exactly once.
119 - Records outside the window are refused, at the exact boundary (64 back
120 accepted, 65 refused).
121- **Record damage.** Every truncation, every extension of 1 to 64 bytes and
122 every single-bit flip of a record is refused. The receiver is unchanged
123 afterwards.
124- **Misrouted records.** Reflected, wrong-session and wrong-state records
125 are refused.
126- **Rekey.**
127 - It is correct over 10 epochs, with reordering across every epoch
128 boundary.
129 - The epoch-0 key is no longer anywhere in either endpoint's memory.
130 - A record sealed with an old key is refused.
131 - Jumping more than 4 epochs ahead is refused.
132- **Limits and close.** The `max_records` limit holds on both the sender and
133 the receiver. Close works.
134- **Loss.** With every Nth datagram dropped in each direction (N = 2, 3, 4,
135 5, 7, 11, 16), all 150 messages each way arrive in order exactly once,
136 including with rekeys every 128 records, and reruns are bit-identical. A
137 blackout or a permanently lost HS3 ends in `LINK_DOWN`.
138- **Fuzzing.** 100,000 random and structured datagrams yield no data, the waiting
139 responder stays in its start state, and the established endpoint keeps
140 working.
141- **Sanitizers.** All of the above also runs under ASan and UBSan.
142- **Mutants.** Every one of the 24 guard mutants (5 in X25519, 19 in the
143 transport) is killed.
144
145**Not proven:**
146
147- **No physical binding.** This transport is hosted C only; the C kernel binds the M6-A UDP path and virtio-net driver (#203), not this secure transport.
148- **No real keys.** Identities come from `sec_test_identity` (a public label,
149 marked NOT-FOR-PRODUCTION), and the "entropy" is a seeded generator. Real
150 identities wait for the M5 owner-key hierarchy (TRUST-1), and a real
151 randomness source waits for the native binding.
152- **No timing measurement.** The X25519 ladder, the masks and the MAC
153 comparisons are written to be constant-time, but no timing, power or
154 cache test was run. GCM-SIV and Ed25519 inherit whatever `native/crypto`
155 and `native/sig` claim.
156- **No formal protocol analysis.** There is no ProVerif or Tamarin model.
157 The security argument is the SIGMA design plus the tests above.
158- **Accepted design limits.**
159 - Identity hiding is not a goal: the responder's key is sent in the clear.
160 - There is no forward secrecy against a later compromise of an identity
161 key alone. The ephemeral keys protect past sessions, but an identity key
162 still allows future impersonation.
163 - A responder keeps one handshake in flight. Denial-of-service hardening
164 (cookies) is not done.
165- **Lockstep finding.** On a strictly periodic loss pattern, the M6-A
166 channel's fixed resend schedule can lock into step with the losses, so
167 the same frame is dropped every round and the link goes down. This was
168 seen with N = 2, 3 and 4 when both senders run in lockstep. **Fixed at the
169 source (Lane 19):** `aienos_ctl` now waits exactly rto before the first
170 retransmit and rto plus a deterministic jitter in [0, rto] before each later
171 one (a pure function of session, role, seq and try count; no clock, no
172 randomness, no key bits, no wire or header change). The loss tests no longer
173 vary sender timing; `ctl_test` adds a drop-every-N run (N = 2 to 16) and a
174 schedule test (bounds, determinism, variation), and `make mutants` covers the
175 six jitter guard lines. The M6-B handshake resend (HS1/HS3) still uses a
176 fixed rto; its loss tests pass for N = 2 to 16.
177
178**Mapping onto omega's Fabric.** Omega's F5-0 Fabric (`src/fabric/fabric.h`)
179takes a `FabTransport {ctx, send(ctx, from, to, msg, len), recv(ctx, self,
180buf, cap, *len)}`, which it treats as untrusted, and a `FabAuth {sign,
181verify}`, which carries a 32-byte tag. The two connect like this:
182
183- **Session table.** An adapter keeps one `sec_endpoint` per peer machine,
184 keyed by `AienMachineId`. Each endpoint's peer key comes from the
185 roster/AEGIS boundary. The Fabric never adds peers.
186- **`send`.** It hands the whole "AFAB" message (at most `FAB_MSG_MAX`,
187 under `SEC_MAX_PAYLOAD` = 1100) to `sec_seal` for the `to` machine, or to
188 `ct_send` and then `sec_seal` when ordered delivery is wanted. It then
189 sends the result as one UDP datagram.
190- **`recv`.** It drains UDP and calls `sec_receive`. Only `SEC_DATA`
191 payloads reach the Fabric, so it sees only authenticated bytes from the
192 configured peer.
193- **Tag size.** An Ed25519 signature is 64 bytes, but `FAB_TAG_BYTES` was 32,
194 so the identity key could not sign Fabric messages directly. omega #137 (1299b19) has since widened the Fabric signature field to 64 bytes; no adapter uses it yet.
195- **Nothing is built yet.** No adapter exists in either repository. This
196 section is the interface plan only.
197
198## Lane 26: virtio-net PCI fix and virtqueue data path (hosted)
199
200> Update 2026-10-01: the text of this section is the hosted-lane record. The driver is now bound in the C kernel (#200 d75a266, #203 9807281, `native/kernel/dev/net_bind.c`) and the NET gate passes in QEMU only (slirp UDP round trip; the last receipt predates Lane 31; Lane 31 negotiates VIRTIO_F_ACCESS_PLATFORM and adds an out-of-window DMA check to the gate, QEMU PASS with receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`; polled, no IRQs; no physical NIC; TEST keys). The "not proven" list below still holds for real hardware.
201
202**The attach bug.** The capability walk refused any vendor capability whose
203region had length 0, before looking at its type. Real QEMU virtio-net-pci
204always carries a `VIRTIO_PCI_CAP_PCI_CFG` (cfg_type 5) capability with bar 0,
205offset 0, length 0, which the virtio 1.x spec allows, so every real QEMU
206virtio-net device was refused with `InvalidRegion`. Confirmed on real config
207space dumped from QEMU 8.2.2 (no guest: the qtest protocol reads the ECAM
208window while the CPU is paused; `tests/fixtures/dump_qemu_virtio_net_cfg.sh`
209re-dumps it). Fix: the BAR / zero-length / overflow checks now apply to the
210four structures the driver maps (cfg_type 1..4) only; other cfg types are
211ignored, as the spec requires. The Rust reference has the same bug (left
212unedited: no Rust work).
213
214The pinned Rust differential still runs, against a reference-compat build
215(`-DAIENOS_VIRTIO_PCI_REFERENCE_COMPAT`, test-only). The default build has its
216own C-only pin, and `make diff-check` proves the two differ only on records
217the reference refused as `InvalidRegion` (1,622 of 200,000).
218
219**The data path** (`aienos_virtio_net`): reset, ACK, DRIVER; VERSION_1
220required, MAC and ACCESS_PLATFORM (bit 33) accepted if offered, every other
221feature declined; `vnet_init_flags(..., VNET_INIT_REQUIRE_ACCESS_PLATFORM)`
222refuses a device that does not offer ACCESS_PLATFORM before FEATURES_OK (the C
223kernel uses it, so a NIC that would DMA around the SMMU never runs); FEATURES_OK
224read back; queue 0 RX and queue 1 TX, power-of-two size up to 256 (downsized to
225what the device offers); notify offset checked against the notify window; all
226RX buffers posted before DRIVER_OK; polled (no MSI-X vector, NO_INTERRUPT).
227Rings and buffers live in one caller region; descriptors are rebuilt from the
228id on every post and checked inside the region; nothing the device writes is
229trusted. A used entry with an id out of range or not outstanding, a length
230over the buffer, a short RX completion, or a used index running ahead marks the
231device broken (sticky) until re-init.
232
233**Tests** (`tests/vnet_test.c`, in `make test` and `make sanitize`):
234- `VIRTIO_PCI_QEMU822_CAPS`: both real QEMU dumps (transitional 0x1000, modern
235 0x1041) parse to the expected windows (BAR 4, common 0x0, ISR 0x1000, device
236 0x2000, notify 0x3000, multiplier 4); 15 malformed variants of the real image
237 stay refused (zero-length common/notify/ISR/device, bad BAR, offset overflow,
238 short cap, cap past config space, loops, duplicate, bad pointer).
239- Init against a simulated device in C: feature masking when the device offers
240 all 64 bits; refusals for no VERSION_1, FEATURES_OK refused, stuck reset, one
241 queue, queue size 0/1, pre-enabled queue, notify offset outside the window,
242 unstable config generation, missing/short caps, small/misaligned/wrapping
243 memory. No notify before DRIVER_OK.
244- `VNET_ACCESS_PLATFORM_SIM`: bit 33 accepted when offered (with and without the
245 flag); with the flag and no offer (three offer sets) refused as
246 `NoAccessPlatform` with FAILED set, no feature bits written, no queue enabled
247 and no notify; unknown flags refused. PASS in the forge run `make -C native/net test` (log HIVE-L31NET-173414.log, not committed;
248 simulated device only).
249- Data path: TX full/reclaim, max-size frames, 70,000 frames each way so the
250 16-bit ring indices wrap; the device model checks every descriptor it reads.
251- Hostile device: 9 directed cases plus a 2,000-round seeded fuzz of forged
252 used entries and indices; each refusal is sticky; a device scribbling over
253 the descriptor table cannot steer the driver.
254- `VNET_M6A_UDP_ROUNDTRIP_SIM`: a UDP frame built by M6-A leaves through the TX
255 queue byte-exact; the simulated device answers with a frame placed in the RX
256 queue, and M6-A parses it (Ethernet, IPv4, UDP checksum, payload).
257
258**Not proven (do not read more into the PASS lines):** no real device, no real
259DMA or IOMMU/SMMU mapping, no interrupts, no QEMU slirp round trip, no
260cache-coherence or MMIO ordering on real hardware, no physical NIC. The only
261real-QEMU evidence is the static config space. A real QEMU end-to-end needs a
262guest kernel that drives the device; this module is hosted and the kernel
263binding belongs to the native kernel lane. (Lane 31: the C kernel binding,
264`native/kernel/dev/net_bind.c`, runs this driver in QEMU behind the smmuv3
265vIOMMU with ACCESS_PLATFORM required; see gate NET, GATES.md rows 102-112. The
266ACCESS_PLATFORM attach and the fence rows are QEMU PASS with receipt `evidence/ck_net_qemu_8bdbc2e46b85d04c422f9d2830c1c4b263e254b3cfecfe21ff0063c9e33c86e8.log`; hardware NOT_RUN.)
267
268**Kernel hook (for the native kernel).** After `ck_virtio_net_probe` accepts
269the caps: add `aienos_virtio_net.c` to the stage sources, enable memory space
270and bus mastering, map the BARs named by the caps, supply `vnet_ops` (volatile
271MMIO at BAR + cap offset + off; notify = 16-bit write at the notify window +
272off), give a DMA-visible region of `vnet_mem_size(qsize)` bytes with its bus
273address, and call `vnet_init`; then poll `vnet_rx` / `vnet_tx_reclaim`.