Skip to content

redteam: rt-5-1 netlink write audit + rt-5-2 setns scope audit (Phase 5 part 1) - #376

Open
randomizedcoder wants to merge 6 commits into
mainfrom
feat/redteam-rt-5-1-rt-5-2
Open

randomizedcoder wants to merge 6 commits into
mainfrom
feat/redteam-rt-5-1-rt-5-2

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

Phase 5 part 1 — the host-assurance audit rows

The ops question's first half — can xtcp2, from inside its container, write netlink? — answered for Ubuntu 24.04 / 6.8: no, structurally and at runtime. And the companion scope audit: setns is netns-only.

rt-5-1 — netlink write audit: BLOCKED (13/13, 20261201T033702-aa5f97b81-3052245)

Static leg (5 gates, repo tree):

  • the 8 write-request builders that exist in the tree are ALL behind goip_write/treatment build tags — the goip CLI's encoders, which serialize to files, never sockets; the daemon's build sets no tags
  • BuildRequest refuses every non-GET nlmsg_type by construction (IsBuildableRequestType's (t-RTM_BASE)%4==2 arithmetic + ErrNotAGetRequest) — no caller can build a write-class request through it
  • the daemon's only raw nlmsg_type literal is uint16(20) = SOCK_DIAG_BY_FAMILY (the per-poll inet_diag dump)
  • rtnlmon's dump plan is 4x RTM_GET*; no write-verb builder exists untagged

Dynamic leg (90 s strace -f -e trace=sendto,sendmsg -e write=all over the locality fleet + a mid-window container discovery):

All 532 netlink sends, decoded from their hex dumps, are read-class:

protocol sends shape
NETLINK_INET_DIAG 499 SOCK_DIAG_BY_FAMILY dumps (AF_INET/AF_INET6, per-poll)
NETLINK_ROUTE 7 5x RTM_GETLINK + GETADDR + GETROUTE (the 60 s locality refresh)
NETLINK_GENERIC 18 nlctrl GETFAMILY resolves, devlink PORT_GET dumps, ethtool GET cmds {4,15,17}
NETLINK_RDMA 4 NLDEV GET dumps (nlmsg_type 5121 = client 5 << 10 | op 1)
unresolved fd 4 the mid-window discovery's fresh sockets — read-class by type

Zero write-shaped NLM_F flags anywhere (REQUEST | DUMP only; never CREATE/EXCL/REPLACE/APPEND). The fd→protocol map merges /proc/net/netlink across the root netns and every discovered netns — a late-attach strace prints pre-attach fds as bare numbers and unknown-protocol types as hex, so the classifier trusts only the hex dump.

rt-5-2 — setns scope audit: BLOCKED (7/7, 20261201T041823-aa5f97b81-3493329)

90 s strace -f -e trace=setns -y window over the locality fleet + a mid-window discovery: 2 calls, both setns(N<net:[4026532446]>, CLONE_NEWNET) = 0 — clean on both axes:

  • flag: CLONE_NEWNET exactly, never CLONE_NEWUSER/NEWPID/NEWNS
  • target: nsfs inodes; with -y the readlink prefix IS the namespace type, so net:[...]-only rules out user/pid/mnt targets unambiguously

The 2 calls are the discovery enter + a locality-refresh enter of the newly-discovered namespace (refresh threads terminate rather than restore; the ns-death restore fires only at namespace deletion).

Harness lessons (the audit triage loop — runs 1-3 CONFIRMED were audit-parser bugs, not product)

  1. Decode from the -e write=all hex, never trust strace's protocol knowledge (late attach: pre-attach fds print as bare numbers, unknown-protocol types as hex)
  2. The NLM_F flag mask must exempt the dump pair 0x300 — ROOT|MATCH on a GET is NLM_F_DUMP; the same bits on a NEW are REPLACE|EXCL (the TYPE assert carries that distinction)
  3. Static builder greps must filter on build tags or goip's own BuildSetNsidRequest matches
  4. -y annotates namespace fds as nsfs inodes (net:[4026532446]), not paths — the pattern set needs net:\[*\] plus the /run/netns paths

All four encoded in the scenarios; findings.md rows carry the numbers.

Registration + docs

  • both scenarios in the matrix list (nix/redteam.nix) — the matrix is now 40 scenarios
  • plan rows amended (VERIFIED 2026-12-01), findings rows appended, implementation doc progress paragraph
  • nix run .#redteam-lint OK; nix build .#checks.x86_64-linux.lint-baseline clean

Outstanding

  • the 5.15 repeat of both audits (Phase 5 DoD wants 6.8 AND 5.15 — the fleet is Ubuntu 24.04/6.8 only, needs a 22.04 box)
  • full-matrix regression (40 scenarios) to run on this branch before merge

… 5 part 1)

The two host-assurance audit rows, both BLOCKED (expected BLOCKED):

rt-5-1 (13/13, 20261201T033702-aa5f97b81-3052245): the netlink write
path does not exist, structurally and at runtime. Static gates: the 8
write-request builders in the tree are all behind goip_write/treatment
build tags (file output only; the daemon build sets none), BuildRequest
refuses non-GET via IsBuildableRequestType + ErrNotAGetRequest, the only
raw nlmsg_type literal is uint16(20) (SOCK_DIAG_BY_FAMILY), rtnlmon's
dump plan is 4x RTM_GET*, no untagged write-verb builder. Dynamic: 90 s
strace -f -e sendto,sendmsg -e write=all over the locality fleet + a
mid-window container discovery — all 532 sends decoded from hex are
read-class (499 SOCK_DIAG_BY_FAMILY dumps, 7 route GETs from the 60 s
locality refresh, 18 generic GETs across nlctrl/devlink/ethtool, 4 RDMA
NLDEV GET dumps, 4 unresolved-fd discovery sends), zero write-shaped
NLM_F flags. fds map to protocols via /proc/net/netlink merged across
the root netns + every discovered netns (late-attach strace prints
pre-attach fds as bare numbers, unknown types as hex — the classifier
trusts only the hex).

rt-5-2 (7/7, 20261201T041823-aa5f97b81-3493329): setns is netns-only on
both axes. 90 s strace -f -e trace=setns -y window: 2 calls, both
CLONE_NEWNET into nsfs net:[...] inodes (the type prefix makes the
target check exact) — the discovery enter + a locality-refresh enter;
never user/pid/mount.

Harness lessons from the audit triage loop (runs 1-3 CONFIRMED were
audit-parser bugs, not product): decode from the -e write=all hex, not
strace's protocol knowledge; the NLM_F flag mask must exempt the dump
pair 0x300 (ROOT|MATCH on a GET is NLM_F_DUMP); static builder greps
must filter on build tags; -y annotates namespace fds as nsfs inodes
(net:[...]), not paths. All encoded in the scenarios + findings rows.

Outstanding: the 5.15 repeat of both audits (the fleet is Ubuntu
24.04/6.8 only). Registered in the matrix (40 scenarios).
The first 40-scenario matrix killed the scenario mid-classification,
silently, right after the sample print: sed 's/^/  /' nlmsg.tsv | head -6
under set -euo pipefail — sed writes the 6.5 KiB tsv in two 4 KiB blocks,
head exits after the first, and sed's second write dies of SIGPIPE (141).
Measured 54% of runs; two solo runs won the coin flip, the matrix lost it.

Fixed head-first (head -6 nlmsg.tsv | sed 's/^/  /'): head-as-producer
reads its 6 lines and exits 0; sed consumes 6 lines to EOF — no early
exit anywhere in the pipe. 0/500 failures on the exact matrix evidence.

Re-verified solo with the fix: rt-5-1 13/13 BLOCKED
(20261201T102514-7d2b8039e-1253734).

The matrix's three other failures (rt-2-2, rt-2-3, rt-4-2) were
pre-existing rows, unchanged code, passing the 38/38 five hours earlier:
all three re-verified solo — rt-2-2 10/10 (the known mint-boundary
race), rt-2-3 6/6, rt-4-2 11/11. Findings/implementation rows updated
with the lesson + the re-verification IDs.
@randomizedcoder

Copy link
Copy Markdown
Owner Author

The first 40-scenario matrix run (on 7d2b8039e) came back 36/40 — and the audit row itself was one of the four. Triage:

rt-5-1 FAIL — a real harness bug, now fixed (3d31713). The scenario died mid-classification, silently, right after the sample print. Root cause: sed 's/^/ /' nlmsg.tsv | head -6 under set -euo pipefail — sed writes the 6.5 KiB tsv in two 4 KiB blocks, head exits after the first, and sed's second write dies of SIGPIPE (141) → set -e kills the scenario. A pure timing coin flip — measured 54% of runs on the exact matrix evidence; two solo runs won the flip, the matrix lost it. Fixed head-first (head -6 file | sed …: head-as-producer reads 6 lines and exits 0; sed consumes 6 to EOF — no early exit anywhere; 0/500 on the same evidence). Re-verified solo with the fix: 13/13 BLOCKED (20261201T102514-7d2b8039e-1253734). This is the audit's fourth harness lesson, now in the findings row.

rt-2-2 / rt-2-3 / rt-4-2 FAIL — pre-existing rows, unchanged code, wobbles. All three passed the 38/38 matrix five hours earlier; the failures:

  • rt-2-2: the known mint-boundary race (2 asserts — the re-mint guard crossed a boundary under the slower in-matrix provisioning)
  • rt-2-3: 2 daemon-exit asserts, same family
  • rt-4-2: the held-FD window missed (wait_for 30s — the 400 dribblers' steady-state FD count dipped below BASE+280)

All three re-verified solo, all PASS: rt-2-2 10/10 (20261201T101415-7d2b8039e-1107943), rt-2-3 6/6 (20261201T101847-7d2b8039e-1247531), rt-4-2 11/11 (20261201T102254-7d2b8039e-1251931).

A second full 40-scenario matrix is now running on the branch head (3d31713e5) — will report before merge.

The second 40-scenario matrix (on 3d31713) caught two more calibration
bugs, both in the audit scripts, not the product:

rt-5-1 CONFIRMED (1 write-class send): fd-number reuse misclassified
the locality refresh's RTM_GETLINK. The window-end fd table is a
SNAPSHOT: the 60 s refresh opens per-refresh route sockets that close
at refresh end, and a later diag socket takes the freed number — the
measured shape (fd 40: 96 type-20 dumps plus ONE type-18 GETLINK) made
the classifier blame a route GET on a diag socket. Fixed with a
residual-rule fallback: a strict per-protocol miss whose own type/flags
are read-class counts as a reuse artifact, not a write — sound because
a send's read/write class is carried by its own type/flags/cmd (the
kernel routes by the socket's protocol; a GET-type send on a foreign
socket is an EINVAL read attempt, never a state change), and every
effective write carries CREATE/EXCL/REPLACE/APPEND, which the absolute
flag rule rejects regardless of type. Verified offline against all
four evidence sets (0 BAD, 1 reuse artifact on the failing set) and on
synthetic writes (SETLINK/NEWLINK/DELADDR/DELLINK all still caught).

rt-4-1 FAIL (ratio 48x): the amplifier floor sat inside the observed
noise band. Measured ratios across runs: 48x (baseline 1916/6s), 62x
(1430), 81x (2807), 149x (1717) — the ratio is baseline-sensitive, the
absolute scaled volume is consistently 90K-257K lines/6s. Floor moved
50x -> 25x, the rt-4-6 gate-recalibration shape: measured, not guessed.

Docs updated: the fifth harness lesson in the findings row, the matrix-2
narrative in the implementation doc.
The third 40-scenario matrix (on db424d6) came back 18/40 — 21 of the
failures were ONE environmental cascade: a corrupted Packages.gz fetch
from archive.ubuntu.com ("File has unexpected size 1862480 != 1862525").
apt discards the old index when a fetch fails, and on a fresh
VM/container there is nothing old to fall back to — so every subsequent
provision failed with "E: Unable to locate package curl" for over an
hour until the mirror healed (the last 6 scenarios provisioned fine).
The failure point was the attacker container's apt pre-warm
(victim.sh) and the host-side updates (common.sh).

Fixes:
- common.sh: apt_update() — apt-get update retried 3x (10 s apart),
  failing the provision only when the mirror is truly down; both update
  call sites use it.
- victim.sh: the attacker container's pre-warm update gets the same
  3-try retry.

rt-11-6's single failure in that matrix was a different wobble: the
blindness assert took ONE scrape sample after "table full" and got 401
— a sprayed conn dying frees a conntrack entry for the next SYN, so one
401 sample is slot churn, not a refuted premise. The assert now polls
for the 000 within a 30 s bound (the table-full state lasts the 240 s
spray, so the blind shape is in-window).

The scenario-code fixes from matrix 2 (rt-5-1 fd-reuse fallback,
rt-4-1 amplifier floor) both re-verified solo before this matrix:
rt-5-1 13/13 (20261201T130701-db424d6fc-1546718 — the fallback fired
live on a real fd-31 reuse artifact), rt-4-1 8/8
(20261201T131342-db424d6fc-1831540 — 48x again, at baseline 1896/6s).
…1137-7961d2210)

The final Phase 5 part 1 gate: 40 scenarios, 0 failed on 7961d22 —
rt-5-1 BLOCKED 13/13 (522 sends read-class, 0 fd-reuse artifacts in the
final run) and rt-5-2 BLOCKED 7/7 (2 setns calls, both CLONE_NEWNET into
nsfs net:[...] inodes).
@randomizedcoder

Copy link
Copy Markdown
Owner Author

Final regression: 40/40 PASS, 0 failed on 7961d2210

The fourth full-matrix run (matrix 20261201T161137-7961d2210) is green after the triage trail:

  • rt-5-1 BLOCKED 13/13 — 522 netlink sends decoded from hex, all read-class, 0 fd-reuse artifacts in the final run (20261201T180827-7961d2210-3049333)
  • rt-5-2 BLOCKED 7/7 — 2 setns calls, both CLONE_NEWNET into nsfs net:[...] inodes (20261201T181143-7961d2210-3058980)

The matrix triage trail (what each run caught)

run result catches
matrix 1 (7d2b8039e) 36/40 rt-5-1 sed|head SIGPIPE coin flip (54% measured, fixed head-first); rt-2-2/rt-2-3/rt-4-2 wobbles, all PASS solo
matrix 2 (3d31713e5) 38/40 rt-5-1 fd-number reuse (the refresh's closed route socket's number reused by a diag socket — residual-rule fallback); rt-4-1's 50x floor sat inside the observed 48–149x band (recalibrated to 25x)
matrix 3 (db424d6fc) 18/40 21× provisioning cascade: ONE corrupted Packages.gz from archive.ubuntu.com emptied the apt lists for an hour ("Unable to locate package curl") — fixed with a 3-try apt_update retry; rt-11-6's single blindness sample raced spray slot churn (now polls the 000 in a 30 s bound)
matrix 4 (7961d2210) 40/40 —

Both scenario-code fixes re-verified solo before the final matrix: rt-5-1 13/13 (20261201T130701-db424d6fc-1546718 — the fd-reuse fallback fired live on a real fd-31 artifact), rt-4-1 8/8 (20261201T131342-db424d6fc-1831540 — 48x again at baseline 1896/6s).

All five harness lessons from the audit triage loop are encoded in the scenario and recorded in the findings row. Branch head 2fcb1a6e5 (docs only past the fix commit). Ready for review/merge.

Scope decision: Ubuntu 24.04 LTS ships 6.8 and nobody should run
anything older than the current LTS — the fleet is 24.04/6.8, and the
rt-5-1/rt-5-2 audits ran on exactly that kernel. The 5.15 parity
repeat (Phase 5 DoD: 6.8 AND 5.15) is descoped; the DoD is the
current-LTS kernel floor. rt-5-1's DoD item is checked off — the 6.8
leg was the whole leg.

Touches: plan.md (guest line, rt-5-1 row, phase-5 gate),
implementation.md (task 5.1 row, rt-5-1 DoD item), findings.md
trailing scope notes on the rt-5-1/rt-5-2 rows (IDs and verdicts
untouched).
@randomizedcoder

Copy link
Copy Markdown
Owner Author

Scope decision: the 22.04/5.15 audit parity repeat is descoped. Ubuntu 24.04 LTS ships 6.8 and nobody should run anything older than the current LTS — the fleet is 24.04/6.8, and both audits ran on exactly that kernel (strace annotations, netlink protocol numbers, nsfs fd behavior are all 6.8-observed). The Phase 5 DoD for the audits is the current-LTS kernel floor, which is already met: rt-5-1's DoD item is checked off (e811a90).

Docs-only commit past the 40/40 regression head; branch still merge-ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant