Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Go fuzzing (FP-7): every Fuzz* target in the module, found by
# `go test -list` in nix/scripts/fuzz-all.bash, so a new fuzzer is covered
# without editing this file.
#
# fuzz-pr every PR to main, 10 s per target
# fuzz-nightly daily and on demand, 2 min per target
#
# This is not a nix check: a derivation is cached by its inputs, so a nightly
# `nix build` would not fuzz again, and crashers would stay in the sandbox.
# On failure the new testdata/fuzz/ files are uploaded; commit the crasher as
# a seed once the bug is fixed.
#
# Actions are pinned by commit SHA; the comment names the tag it was taken from.
name: fuzz

on:
pull_request:
branches: [main]
schedule:
- cron: "0 15 * * *"
workflow_dispatch:
inputs:
fuzztime:
description: "Per-target budget (Go duration)"
default: "2m"
required: true

permissions:
contents: read

concurrency:
group: fuzz-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
fuzz-pr:
name: fuzz-pr
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
# About 50 targets at 10 s plus their instrumented builds.
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
- name: fuzz-all
env:
FUZZTIME: 10s
FUZZ_LOG_DIR: ${{ runner.temp }}/fuzz-logs
run: nix develop -c fuzz-all
- name: upload crashers and logs
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: fuzz-pr-crashers
path: |
**/testdata/fuzz/**
${{ runner.temp }}/fuzz-logs/
if-no-files-found: ignore

fuzz-nightly:
name: fuzz-nightly
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
# About 50 targets at 2 min each.
timeout-minutes: 180
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
- name: fuzz-all
env:
FUZZTIME: ${{ inputs.fuzztime || '2m' }}
FUZZ_LOG_DIR: ${{ runner.temp }}/fuzz-logs
run: nix develop -c fuzz-all
- name: upload crashers and logs
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: fuzz-nightly-crashers
path: |
**/testdata/fuzz/**
${{ runner.temp }}/fuzz-logs/
if-no-files-found: ignore
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- **Strings from tenants and the network are cleaned.** Container names and images, a tenant's interface names, LLDP and NIC strings, the ASN feed's network owner, netns names and congestion names are cut to 256 bytes (16 for interface and congestion names) at a UTF-8 boundary. Invalid UTF-8 and control characters (C0, DEL, C1) become U+FFFD. Each is cleaned once, where it enters, not per row.
- **Per-namespace caps.** `-maxDumpBytes` (default 256 MiB) and `-maxRecordsPerNetns` (default 262144) bound one namespace's dump per poll: packets past the byte cap are drained undecoded, and records past the record cap are dropped before decode. `-maxNetns` (default 4096) bounds the namespaces tracked. At the cap, tracked namespaces keep their slots, and new ones wait for a freed slot, first come, first served. Alert on `xtcp_netns_dropped_total`. Drops are counted in `xtcp_dump_dropped_total{reason}` and `xtcp_netns_dropped_total`, with one log line per truncated dump or short reconcile. `0` turns a cap off; the matching env vars are `MAX_DUMP_BYTES`, `MAX_RECORDS_PER_NETNS` and `MAX_NETNS`. The caps are startup-only: `ConfigService.Set` keeps the running values. No healthy host should reach the defaults; a host that does now loses that namespace's excess rows, where it used to collect them all ([polling and batching](docs/polling-and-batching.md#per-namespace-caps)).
- **Socket-count gate, reconcile limits, per-owner quota.** Before each poll xtcp2 reads each namespace's sockstat (an fd opened in the namespace; `pread`, or io_uring batches with `-ioUring`) and, when the total is over `-maxRecordsPerPoll` (default 1,048,576), degrades only the namespaces over their fair share: first TIME_WAIT/SYN_RECV are not asked for, then one of K port shards is dumped per poll. `-maxNetnsPerOwner` (default 64) caps namespaces tracked per owner (the container runtime's cgroup), `-maxNetnsAddsPerReconcile` (256) the adds per reconcile, and `-reconcileTimeout` (1s) the namespace scan; a timed-out scan deletes nothing. New metrics `xtcp_poll_sockets`, `xtcp_poll_degraded_total{level}` and `xtcp_reconcile_incomplete_total{reason}`; `xtcp_netns_dropped_total` gains `reason`. `0` turns each off; all are startup-only. Each tracked namespace now holds four fds (was two: sockstat and `ip_local_port_range` are new), and xtcp2 warns at startup when `RLIMIT_NOFILE` can't cover them ([polling and batching](docs/polling-and-batching.md#socket-count-gate), [network namespaces](docs/network-namespaces.md#configuration)). The analysis behind an upstream all-namespace dump is in [docs/kernel](docs/kernel/inet-diag-all-netns.md).
- **Fuzzing in CI.** `fuzz-all` (dev shell) finds every Go fuzz target with `go test -list` and fuzzes each in turn: 10 s per target on each PR, 2 min nightly (`.github/workflows/fuzz.yml`), with crashers uploaded as an artifact. Two new fuzzers cover tenant-reachable paths: `FuzzDockerProjection` (a Docker inspect body to a container's name and image) and `FuzzRowFromProto` (an S3 envelope through Parquet and back). `FuzzClean` now also checks idempotence and the fast path. The first run found `/ip/vrf/show/NAME` returning 500 for a name that is no VRF; it is now a 404. Docker API response bodies are now capped per endpoint, and an oversized `/events` line no longer stalls container-metadata refresh.
- **Vulnerability check.** `checks.govulncheck` runs govulncheck against a pinned snapshot of the Go vulnerability database, with no tags and with every flavor tag, and fails on a reachable finding not in its accepted list. One is accepted: GO-2026-6859 in `net/http`, fixed in go1.27.4, until the toolchain moves. `nix run .#govulncheck-fresh` checks against the live database and runs `go mod verify`; `nix build .#sbom-<binary>` writes a CycloneDX SBOM for any binary package.

## 0.2.1 (2026-11)
Expand Down
8 changes: 5 additions & 3 deletions docs/security-hardening/focused-implementation-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Non-blocking shortfalls found while implementing F1; none blocks R1.
| `BenchmarkS3Send` queue vs the old channel send | 52 ns vs 118 ns | faster ✓ |
| `microvm-x86_64-lifecycle-s3parquet` Check 14c: Garage stopped for 160 s (4× wait scale), `-s3QueueDepth 2` | polls kept running (343), 22 envelopes dropped, RSS 50.8 → 55.8 MB, a new object after restart | pass ✓ |

**Status:** open as #308.
**Status:** merged (#308).

**FP-6 follow-ups (in #308):**

Expand All @@ -230,8 +230,8 @@ Non-blocking shortfalls found while implementing F1; none blocks R1.

### FP-7 — fuzzers (D4)

- [ ] `FuzzDockerProjection` (`pkg/dockermeta`), `FuzzStrPolicy`, `FuzzRowFromProto`; corpora seeded from F0.5.
- [ ] CI runs every fuzzer (existing netlink ones included) for a fixed time budget per PR and longer nightly.
- [x] `FuzzDockerProjection` (`pkg/dockermeta`), `FuzzStrPolicy`, `FuzzRowFromProto`; corpora seeded from F0.5. *Done as:* `FuzzDockerProjection` drives a raw inspect body through `json.Unmarshal` and the new pure `project` (split out of `(*Index).inspect`); a projected name and image are always valid UTF-8, ≤ 256 bytes and control-free. `FuzzRowFromProto` (`dest_s3parquet`) takes arbitrary envelope bytes through the worker's row path (unmarshal, `rowFromProto`, event date, Parquet write) and reads the object back: every decoded row must round-trip unchanged. `FuzzStrPolicy` is `FuzzClean`, which now also checks idempotence and the fast path. Each fuzzer shares a table with a unit test (`TestDockerProjectionJSON` 12 rows, `TestRowFromProtoRoundTrip` 12, `TestCleanProperties` 7, plus `TestProject` 9), so every seed has a description and an expected result. F0.5 isn't captured yet, so the seeds are the fixtures and the real netlink dump; the F0.5 rows are a TODO below. Pinned on the way: invalid UTF-8 in a proto3 string fails the unmarshal, so the worker drops the whole envelope (the sources clean strings first, so it can't come from them).
- [x] CI runs every fuzzer (existing netlink ones included) for a fixed time budget per PR and longer nightly. *Done as:* `nix/scripts/fuzz-all.bash` (`fuzz-all` in the dev shell) finds every target with `go test -list` under the flavor tags (50 today), fails below `FUZZ_MIN_TARGETS`, runs them all even after a failure, and lists the crasher files. `.github/workflows/fuzz.yml`: `fuzz-pr` at 10 s per target, `fuzz-nightly` daily at 2 min (and `workflow_dispatch`); crashers and logs uploaded on failure. Not a nix check: a cached derivation would never fuzz again. `-fuzzminimizetime` is 5 s: with Go's 60 s default, `FuzzRowFromProto` spent a 10 s budget minimizing (0 execs/s after the first 3 s). First full run (50 targets at 10 s, loaded host): 588 s, one crasher in the existing `FuzzIPHandler`: `/i/v/s/0` (vrf show for a name that is no VRF) returned 500; `goip.ErrVrfInvalid` now maps to 404, the input is committed as a seed and a `TestFuzzIPHandlerRows` row.

### Phase F2 TODOs

Expand All @@ -248,6 +248,8 @@ Non-blocking shortfalls found while implementing F1; none blocks R1.
| ~~`microvm-x86_64-socket-scale`~~ done as FP-5.7 | — |
| Fix `RegisterIOWQMaxWorkers` signature in the giouring fork | giouring PR |
| Upstream RFC for an all-namespace inet_diag dump, only after the VM numbers and a lore.kernel.org search | F2 follow-up |
| Add the scrubbed F0.5 Parquet rows as `FuzzRowFromProto` seeds once F0.5 is captured | FP-7 follow-up |
| ~~Cap `dockermeta.getJSON`'s body~~ done in #312: per-endpoint caps (`/version` 64 KiB, `/containers/json` 32 MiB, inspect 1 MiB; over the cap the container is skipped or the re-list fails), and `drainClose` now discards at most 64 KiB: an `/events` line over the scanner's 1 MiB used to block the refresh goroutine draining the endless stream | — |
| Re-tune the three caps' defaults from the F0.6 baseline (≥ 10× p99) | F0.6 |
| The F2 gate's 1 M-socket synthetic netns run | after FP-6 |

Expand Down
2 changes: 2 additions & 0 deletions internal/godevlink/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var godevlinkClosure = []string{
modulePath + "/cmd/godevlink", modulePath + "/internal/godevlink",
modulePath + "/pkg/xtcpnl", modulePath + "/internal/jsonw",
modulePath + "/pkg/cint",
// Reached through xtcpnl's congestion-name decoder; stdlib only.
modulePath + "/pkg/strpolicy",
// Reached through xtcpnl's inet_diag decoders; see internal/gordma.
modulePath + "/gen/go/xtcp_flat_record",
}
Expand Down
7 changes: 4 additions & 3 deletions internal/goip/goiphttp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,17 @@ var (
// statusOf maps a show failure to its status. ErrNoSuchDevice is tested
// before ErrNotImplemented because netconf's missing device carries both.
// A refused write verb or option is the caller's request, so a 400, as is a
// device name no kernel takes (ip's "not a valid ifname"); a read goip does
// not serve is a 501.
// device name no kernel takes (ip's "not a valid ifname"); a vrf show NAME
// that names no VRF (ip's "Invalid VRF") is a 404, like a missing device; a
// read goip does not serve is a 501.
func statusOf(err error) int {
switch {
case errors.Is(err, errParam), errors.Is(err, goip.ErrWriteVerb), errors.Is(err, goip.ErrRefusedOption),
errors.Is(err, xtcpnl.ErrBadIfName):
return http.StatusBadRequest
case errors.Is(err, goip.ErrUnknownObject):
return http.StatusNotFound
case errors.Is(err, goip.ErrNoSuchDevice), errors.Is(err, unix.ENODEV):
case errors.Is(err, goip.ErrNoSuchDevice), errors.Is(err, unix.ENODEV), errors.Is(err, goip.ErrVrfInvalid):
return http.StatusNotFound
case errors.Is(err, goip.ErrNotImplemented):
return http.StatusNotImplemented
Expand Down
2 changes: 2 additions & 0 deletions internal/goip/goiphttp/handler_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ func TestFuzzIPHandlerRows(t *testing.T) {
method: "PROPFIND", path: "/i/a/s", expected: is(http.StatusMethodNotAllowed), noOpen: true},
{name: "method_lowercase", category: "corner", description: "methods are case-sensitive: get is not GET",
method: "get", path: "/ip/link", expected: is(http.StatusMethodNotAllowed), noOpen: true},
{name: "vrf_show_not_a_vrf", category: "negative", description: "/i/v/s/0: a name that is no VRF is ip's Invalid VRF, a 404 not a 500",
method: http.MethodGet, path: "/i/v/s/0", expected: is(http.StatusNotFound)},
{name: "write_verb", category: "negative", description: "/i/l/s is ip link set: a 400 before any open",
method: http.MethodGet, path: "/i/l/s", expected: is(http.StatusBadRequest), noOpen: true},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go test fuzz v1
string("GET")
string("/i/v/s/0")
string("")
2 changes: 2 additions & 0 deletions internal/gotipc/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var gotipcClosure = []string{
modulePath + "/cmd/gotipc", modulePath + "/internal/gotipc",
modulePath + "/pkg/xtcpnl", modulePath + "/internal/jsonw",
modulePath + "/pkg/cint",
// Reached through xtcpnl's congestion-name decoder; stdlib only.
modulePath + "/pkg/strpolicy",
// Reached through xtcpnl's inet_diag decoders; see internal/gordma.
modulePath + "/gen/go/xtcp_flat_record",
}
Expand Down
2 changes: 2 additions & 0 deletions internal/govdpa/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var govdpaClosure = []string{
modulePath + "/cmd/govdpa", modulePath + "/internal/govdpa",
modulePath + "/pkg/xtcpnl", modulePath + "/internal/jsonw",
modulePath + "/pkg/cint",
// Reached through xtcpnl's congestion-name decoder; stdlib only.
modulePath + "/pkg/strpolicy",
// Reached through xtcpnl's inet_diag decoders; see internal/gordma.
modulePath + "/gen/go/xtcp_flat_record",
}
Expand Down
25 changes: 25 additions & 0 deletions nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The flake currently exports `x86_64-linux` only. See
- [Development and maintenance](#development-and-maintenance)
- [Binaries, images, and artifacts](#binaries-images-and-artifacts)
- [Unit, flavor, and quality checks](#unit-flavor-and-quality-checks)
- [Fuzzing](#fuzzing)
- [Nix integration testing](#nix-integration-testing)
- [Netlink and RDMA fixture collection](#netlink-and-rdma-fixture-collection)
- [Link-monitor verification](#link-monitor-verification)
Expand Down Expand Up @@ -220,6 +221,29 @@ Use the full path: `nix build path:.#checks.x86_64-linux.NAME -L`.
| `test-ipmeta-bootstrap-artifact`, `test-oci-ipmeta-bootstrap-contents`, `test-ipmeta-bootstrap-snapshot`, `test-oci-ipmeta-bootstrap-snapshot-contents` | Fixture and real-snapshot bootstrap checks, also available as packages above |
| `microvm-lifecycle-x86_64`, `vm-*`, `vm-all` | Actual guest checks described next; `vm-*` here refers to guest checks, not the host helpers above |

## Fuzzing

`fuzz-all` (in the dev shell; source `nix/scripts/fuzz-all.bash`) finds every `Fuzz*` target with `go test -list` and fuzzes each in turn, so a new fuzzer needs no list entry. It runs every target even after a failure, then names the failures and the crasher files Go wrote under `<pkg>/testdata/fuzz/<Target>/`.

```bash
nix develop -c fuzz-all # every target, 10 s each
FUZZ_FILTER=dockermeta FUZZTIME=5m nix develop -c fuzz-all # one package, longer
```

| Variable | Default | Meaning |
|---|---|---|
| `FUZZTIME` | `10s` | Budget per target |
| `FUZZ_PARALLEL` | `2` | Fuzz workers per target |
| `FUZZ_MINIMIZE` | `5s` | `-fuzzminimizetime`. Go's 60 s default spends a short budget minimizing new inputs on slow targets |
| `FUZZ_TAGS` | `dest_s3parquet enrich_asn enrich_locality` | Build tags, so tagged fuzzers such as `FuzzRowFromProto` are found |
| `FUZZ_FILTER` | none | Extended regex on `pkg:target` |
| `FUZZ_MIN_TARGETS` | `50` | Fail if discovery finds fewer, so a broken discovery can't pass |
| `FUZZ_LOG_DIR` | a temporary directory | One log per target |

CI (`.github/workflows/fuzz.yml`) runs it on every PR to main at 10 s per target (`fuzz-pr`), and daily at 2 min per target (`fuzz-nightly`, also `workflow_dispatch` with a chosen budget). It is not a nix check, because a cached derivation would never fuzz again. A failed run uploads the crashers and logs as an artifact. Fix the bug, then commit the crasher file and add the input as a row of the fuzzer's table, which its unit test and seed corpus share.

`test-linkmonitor-fuzz` still fuzzes its own 10 targets for 30 s each under `nix build`.

## Nix integration testing

### Prerequisites and suite boundaries
Expand Down Expand Up @@ -662,6 +686,7 @@ as many guests at once as `max-jobs` allows; add `-j1` for one at a time.
| [../flake.nix](../flake.nix) | Inputs, supported system, public outputs, and overlay |
| [default.nix](default.nix) | Export names, package/app/check wiring, `integration-all` membership |
| [versions.nix](versions.nix), [packages.nix](packages.nix), [devshell.nix](devshell.nix) | Tool versions, developer tools, and shell helpers |
| [scripts/fuzz-all.bash](scripts/fuzz-all.bash) | `fuzz-all`: discover and fuzz every Go fuzz target (dev shell and CI) |
| [binaries.nix](binaries.nix), [containers/default.nix](containers/default.nix) | Binary and OCI flavor generation |
| [lib/goSource.nix](lib/goSource.nix), [lib/goModules.nix](lib/goModules.nix) | Source filtering and vendored dependency preparation |
| [checks/default.nix](checks/default.nix) | Static audits, lint tiers, and host harness checks |
Expand Down
18 changes: 18 additions & 0 deletions nix/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ let
# The five golangci-lint tiers, shared verbatim with nix/default.nix's
# `packages` so the shell and the flake cannot drift.
lintTiers = import ./lint-tiers.nix { inherit pkgs; };
# Every Go fuzz target, found by `go test -list` (FP-7). The script stays a
# plain file so CI and contributors run the same thing; the shebang is
# dropped because writeShellApplication adds its own.
fuzzAll = pkgs.writeShellApplication {
name = "fuzz-all";
runtimeInputs = [
pkgs.coreutils
pkgs.findutils
pkgs.gawk
];
text = pkgs.lib.removePrefix "#!/usr/bin/env bash\n" (builtins.readFile ./scripts/fuzz-all.bash);
};

# Shell-entry banner. A writeShellApplication rather than a shellHook
# function so its (admittedly trivial) bash is shellcheck'd like everything
Expand Down Expand Up @@ -98,6 +110,11 @@ let
flake.nix does not export `tests`,
so that name has never resolved.)

Fuzzing:
fuzz-all Fuzz every Fuzz* target in turn
(FUZZTIME=10s per target; set
FUZZ_FILTER=<regex> to pick some)

Nix:
nix flake check Tier 0+1 lint + all custom audits
nixfmt --check **/*.nix Verify nix formatting
Expand All @@ -115,6 +132,7 @@ pkgs.mkShell {
++ [
regenProtos
xtcp2Help
fuzzAll
];

shellHook = ''
Expand Down
Loading