Skip to content

gotc: writes for pedit, tunnel_key, ife, ct, gate, bpf and the bpf filter (increment 23) - #378

Open
randomizedcoder wants to merge 13 commits into
mainfrom
gotc/act2write
Open

randomizedcoder wants to merge 13 commits into
mainfrom
gotc/act2write

Conversation

@randomizedcoder

Copy link
Copy Markdown
Owner

Increment 23: dry-run writes for tc 7.2.0's last six action kinds (pedit, tunnel_key, ife, ct, gate and bpf) and for the bpf filter (cBPF). The ported code is m_pedit.c and its p_*.c headers, m_tunnel_key.c, m_ife.c, m_ct.c, m_gate.c, m_bpf.c, f_bpf.c and bpf_legacy.c's cBPF parser. Flower is now the only tc write gotc refuses (increment 24).

  • 23C: a new tcact2write capture space with 418 rows: 258 writes and 160 refusals. It covers every verb and keyword of the six kinds and the bpf filter, a row for each lead W216–W320, the size limits and the batches. Two batches on one boot agree (V065).
  • 23P: Append encoders for TcPeditKey, TcPeditSel, TcTunnelKey, TcIfe (with its two zero bytes of tail padding) and TcBpfInsn, each cited to the kernel headers at v7.4-rc4 (V066).
  • 23W: gotc writes for the six kinds and the bpf filter (V067).
    • tcact2write replays 418/418. 12 of those rows are refusals by name: eight eBPF rows (eBPF program via bpf(2)), W280 (ct reads past its unterminated nat argument) and W297 (gate times that tc casts with undefined behaviour). W294 (gate's uninitialised maxoctets) is refused by name in a unit test.
    • tcactwrite ec-217–ec-222, tcfwrite ec-117, and tcematch ec-137 and ng-095 are now sent instead of refused.
    • tdc: no action write is refused any more (516 sent). Only flower's two filter writes are still refused (293 sent).
    • fops now checks tc's addattr_l and addraw_l bounds as it records each call. A failed nest leaves a mark that its nest end patches, as tc's does. That reproduces W97, W151, W248, W293 (broken gate entries past the 1024-byte nest bound) and W307 byte for byte.
    • 10/10 mutants killed; internal/gotc coverage is 86.6%. Four fuzz targets, including a new FuzzCbpfParseOps, ran 60s each and found nothing.
    • Fixed on the way: no-write-encoders' list of gotc write files missed aw_pedit_hdr.go, aw_tunnel_key.go and cbpf.go. The rule now covers them.
  • 23B: each of W216–W320 has an entry. Its trigger and outcome are generated from the corpus rows. Kernel notes K77–K89 are in docs/netlink/upstream/iproute2-tc-action-write.md, which is not sent to netdev (DOC016).
    • Extensions are recorded in the older leads' own docs: 21 in this doc, five in iproute2-tc-filter-write.md and two in iproute2-tc-action.md.
    • HEAD check: 5faf18f672c1 (ll_addr.c, in v7.3.0) partly fixes W232. c4d6334c55aa fixes increment 22's W182. addattr_l is unchanged, so W248, W293 and W307 still stand. gotc keeps v7.2.0's behaviour.
    • Five bug-class candidates are listed in the doc. bug-classes.md is unchanged.
  • 23L: a live diff on the workbench, 413/425 identical (V068). The other 12 are the refusals by name. In 78 of the identical rows the request matches and only tc hears the kernel's reply. tc's output matches the corpus on every row.

Gates: go test ./..., test-go-race, lint-baseline (tiers 0-2) and no-write-encoders pass.

🤖 Generated with Claude Code

randomizedcoder and others added 13 commits November 30, 2026 22:00
Add the tcact2write space for increment 23's six action kinds (pedit,
tunnel_key, ife, ct, gate, bpf) and the bpf filter: 418 rows, 258
writes and 160 refusals, captured on the workbench in two batches that
agree. Every lead W216-W320 is pinned by a row except W294, whose
uninitialised maxoctets sends a different stack value each run.

Load act_meta_mark, act_meta_skbprio and act_meta_skbtcindex in the
guest. Without them a fresh ife decode is EINVAL (K79).

Write up the increment's leads in the upstream doc: the summary table,
the corrections to the sweep, and kernel notes K77-K89.

The bench pin for the largest NLMSG_ERROR now names ng-157 (W248). Its
extack costs one allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add Append for tc_pedit_key and tc_pedit_sel with its keys,
tc_tunnel_key, tc_ife (with the two zero bytes of tail padding tc
sends) and sock_filter. The layouts are those of the kernel headers at
v7.4-rc4. ct, gate and the bpf action's parms are tc_gen, which
TcGen.Append already lays out.

TestAppendTcAct2Structs checks 21 tcact2write payloads: each one,
decoded by the read side and laid out again, gives back tc's bytes. It
also round-trips 14 hand-built structs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…7) and get_addr

fops now checks tc's addattr_l and addraw_l bounds as each call is
recorded, from the running request length: a call past its bound prints
tc's "addattr_l ERROR: message exceeded bound of N" (or addraw_l's), the
attribute is dropped and the request is still sent, as tc ignores the
result. A failed addattr_nest leaves a Mark (xtcpnl AttrBuilder.Mark) and
its addattr_nest_end patches rta_len over whatever was written since,
which is gate's broken entry nest (W293).

tcematch ec-137 and ng-095 are now replayed byte for byte instead of
refused; the fw W97 and ematch W151 rows pin tc's errors and sends.

inet.go gains getAddr (utils.c:738: "Error: <family> address is expected
rather than ..." then exit(1)), used by flow's addend. TestGotcAct2Corpus
replays the tcact2write space, skipping the six kinds still refused by
name while 23W ports them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cbpf.go is lib/bpf_legacy.c's parse side: bpf_do_parse's mode words
(bytecode/bc, bytecode-file/bcf, object-file/obj, object-pinned, pinned,
fd and their prefixes), the eBPF option words read before any bpf(2), and
bpf_ops_parse with glibc sscanf's %hu/%hhu/%u wrap and the bytecode-file
reader (newlines to commas, blank runs collapsed, a read error or a full
buffer silently -E2BIG), relative to the working directory.

aw_bpf.go is m_bpf.c (index ends the loop, a word after the program ends
it, help returns -1); fw_bpf.go is f_bpf.c (program loaded after the
loop, so OPS_LEN and OPS follow CLASSID, ACT and POLICE, then FLAGS_GEN
and FLAGS; no program sends OPS_LEN 0 and an empty OPS). eBPF programs
are refused by name as "eBPF program via bpf(2)" where tc first touches
bpf(2): bpf_obj_pinned in the parse, bpf_obj_open at the load (after the
filter's whole loop).

Every bpf row of tcact2write replays byte for byte bar the 8 eBPF
refusals; TestGotcBpfWrite, TestCbpfParseOps and FuzzCbpfParseOps added,
with bpf seeds for the write fuzzers and a skip for inputs that could
name a device as bytecode-file. The tdc and corpus pins are left for the
merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eBPF refused by name)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aw_pedit.go is parse_pedit, parse_munge, parse_offset, parse_cmd,
parse_val and the pack_key family, in tc's host-order words;
aw_pedit_hdr.go is p_ip, p_ip6, p_icmp, p_tcp, p_udp and p_eth as one
table. Any other kind is pedit_parse_nopopt. Copied as tc does it: the
"Bad pedit construct" word set by each parser's write-back (W218), the
silent 128-key limit (W220), invert as 0xff on eth and ip6 (W223), the
NULs that eth MAC colons leave in a batch (W232), and the ignored
addattr results (W248).

All 129 pedit rows in tcact2write and tcactwrite ec-217 now replay byte
for byte; TestGotcPeditWrite pins them. TestGotcActParsers and
TestGotcFilterWrite now expect pedit to be sent, not refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
parse_tunnel_key and parse_ife join actParsers. tunnel_key opens its
nest before NEXT_ARG (W254), writes each option as read, takes
addresses through get_addr's exit(1) (W250, 0-byte IPV6_* for any,
W251), always sends NO_CSUM (W263), tries tos/ttl in base 10 then 16
(W257), and splits geneve/erspan with a strtok_r clone whose NULs stay
in the batch buffer (W258, W261, W265). ife parses before opening its
nest (W274), counts index as a mode (W267), sends decode as PARMS alone
(W273) and METALST as mark, prio, tcindex (W271).

All 82 tcact2write tunnel_key and ife rows replay byte for byte;
TestGotcTunnelKeyWrite, TestGotcIfeWrite and TestStrtok pin them.
awReplayRow takes a space/row id; TestGotcActParsers moves both kinds
from refused to sent. The tdc pins and tcactwrite ec-218/219's refusals
are left for the merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aw_ct.go is parse_ct: the options nest first, each option's attributes as
read, nat's words each needing one after them (W276, W277), get_addr's
exit(1) for nat addresses with the second taking the first's family
(W279), 0-byte IPV6 for any (W281), base-10 ports (W282), the 3-field
helper scan (W283) with inet_proto_a2n by get_u8 base 10 then the
workbench's /etc/protocols (render.ProtoByName; W284), labels as tc
halves and reports them (W285-W287), index only inside the loop (W288),
and the NULs mark's and label's '/' leave in a batch (W291). A nat
argument of 63+ bytes is refused by name: tc reads past its
unterminated SPRINT_BUF copy (W280).

aw_gate.go is parse_gate: entries nested at addattr_nest(n, 1024, ...)
so the bound copy gives W293's errors and broken nests byte for byte;
get_s64/get_time64 times (W296, W298), 0 as unset (W299), closed entries
forced to -1 (W304), get_size's low-32-bit store on its failure (W295).
Refused by name: get_size's uninitialised store after a numeric ipv
(W294) and strtod times tc casts to __s64 out of range, inf and nan
(W297).

tcact2write: 117 of the 121 ct and gate rows replay byte for byte; ec-168
(W280) and ec-204..206 (W297) are the refusals. gotc may import
internal/goip/render for getprotobyname.

With all six kinds in, TestGotcCorpus replays tcact2write (418 rows,
12 refused by name: eBPF, W280, W297) and the temporary act2 test goes.
tdc: no action write is refused any more (516 sent), and only flower's 2
filter writes are (293 sent). tcactwrite ec-217..ec-222 and tcfwrite
ec-117 are sent byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shared word constants for the header fields u32, flower, pedit and
tunnel_key all spell (tos, ttl, nofrag, firstfrag, sport, dport,
icmp_type, icmp_code, type), with prio and flags moved to util.go so the
untagged readers use them too; get_time64's and get_size64's suffixes as
time64Scale and size64Scale, shared by gate; actParsers built from a
kind list; parseBpfFopt's handle, classid and action arms split out.

FuzzGotcActionWrite, FuzzGotcActionBatch and FuzzGotcFilterWrite gain
seeds for pedit, tunnel_key, ife, ct and gate, with the W232, W265 and
W291 NULs carried to a later line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gotc-status.md: the 23W bullet and V067 (the ports, the bound
emulation, refusals by name, corpus and tdc pins, unit tables, 60 s fuzz
of four targets, 10 mutants all killed, coverage 86.6%, lint tiers 0-2).
iproute2-tc-action-write.md: the gotc column for W216-W320 (copies, or
the refusal's text for W280, W294 and W297, and W314's eBPF modes), the
23W status, and W295's past-32-bits detail. No new lead or kernel note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iproute2-tc-action-write.md's "Increment 23" part gains a full entry
per lead W216-W320 (where, trigger and outcome from its tcact2write
rows, gotc, status) and the HEAD check: at 3f4b36e5b10a, ll_addr's
5faf18f672c1 partly fixes W232, and c4d6334c55aa fixes increment 22's
W182, now recorded in its row, entry and HEAD-check block. addattr_l is
unchanged, so W248, W293 and W307 stand; the kernel has no commit after
v7.4-rc4 in the cited files. Extensions are marked "Extended in
increment 23" in their own docs (21 in the increment-22 part, five in
the filter write-up, AC38 and AC70). No new lead; not submitted to
netdev; bug-classes.md untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tc 7.2.0 and the gotc_write build ran all 418 tcact2write rows,
tcactwrite ec-217..ec-222 and tcfwrite ec-117 on the workbench (kernel
7.3.1). 413/425 identical, 78 of them rows where only tc hears the
kernel (K77, K78, the kernel refusals, and gate's "Attribute isn't type
'entry'" after W293's broken entries); the other 12 are gotc's refusals
by name (eBPF, W280, W297). tc matched the corpus on all 425, so K77-K89
recurred. No lead added or changed. The VM was left as found: 40
modules removed with modprobe -r, no namespace, no core file, powered
off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gotcWriteFiles matched aw_[a-z0-9]+ only, so the check's exactness
control failed on the three new gotc_write files with an underscore in
the name or no prefix. Allow underscores after qw_, fw_ and aw_ and name
cbpf; no untagged file matches. Recorded in V067.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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