Skip to content

luaebpf: a program file names the verdict an error returns - #72

Open
lneto wants to merge 1 commit into
masterfrom
error-verdict
Open

lneto wants to merge 1 commit into
masterfrom
error-verdict

Conversation

@lneto

@lneto lneto commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

A compiled program that stops, at a read past the packet, a division by 0 or a map update the map refuses, drops the packet whatever its default verdict, so a filter in a device's forwarding path that is to fail open cannot be written as a program file.

xdp.program and tc.program now take error, the verdict every stop of the program returns, an action of its type as default is. A frame too short for byte 20 stops the program below, which counts the stop at its line, logs <file>:<line>: out of bounds to the trace ring as today, and returns XDP_PASS, so the frame goes on:

local xdp    = require("bpf.xdp")
local action = require("linux.xdp").action

return xdp.program(function(ctx)
	local p = ctx:packet()
	if p:getbyte(20) == 6 then
		return action.DROP
	end
end, {default = action.PASS, error = action.PASS})

A file that names no error returns XDP_ABORTED in XDP and TC_ACT_SHOT in TC, as today; a stop that is to take the default names the same action twice, and an error that is no action is refused at the line of the program's function, "xdp.program's error verdict is not an XDP action". The verdict is the program's, so two programs of one file may name two. Nothing else is added: no kernel API, no change to the license a program that may stop needs. The kernel fires xdp:xdp_exception for XDP_ABORTED, and for an XDP_TX or an XDP_REDIRECT it fails to carry out, so the stops of an XDP program whose error verdict is another action are not read there, but in the trace ring and with lunatik bpf --errors.

The change reaches a device with Lunatik's move of its luaebpf/ mount to this commit, and the programs that run a short frame through error, in XDP and in TC, come with that move: until it no program of Lunatik's suite names error, and none has run on a device. No example of Lunatik's is a program file or requires a module this changes, so none ran.
#45, which it does not close

xdp.program and tc.program take `error`, an action of the program's
type, which every stop of the program returns, from any frame: the tail
each stop's block jumps to after it counts the stop and logs its line
loads it in place of the type's constant. A file that names none gets
XDP_ABORTED in XDP and TC_ACT_SHOT in TC, as before, and a stop that is
to take the default names the same action as `default`. The value is held
to the check the default verdict has, refused at the line of the
program's function as "xdp.program's error verdict is not an integer" or
"is not an XDP action", tc.program's alike.

The kernel fires xdp:xdp_exception for XDP_ABORTED, and for an XDP_TX or
an XDP_REDIRECT it fails to carry out (netif_receive_generic_xdp and
generic_xdp_tx in net/core/dev.c, ixgbe_run_xdp among the drivers), so
the stops of an XDP program whose error verdict is another action are
not read there: they are read in the trace ring and with
`lunatik bpf --errors`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@lneto lneto added complexity: medium Several call sites, a new test, or a core path to audit workflow-reviewed reviewed end to end by a review workflow labels Nov 27, 2026
@lneto

lneto commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Note

This comment was written by an LLM, not a human.

What #45 requires, as the review read the change meeting it:

  • Met: Issue luaebpf: a program file says the verdict a stop of the program returns #45: "a program file says which verdict a stop of the program returns, its own default among them, for XDP and for TC" Each constructor passes the file's error, or the type's constant where it is nil (lib/bpf/xdp.lua:96, lib/bpf/tc.lua:105). The one tail loads it (emit/init.lua:158, unchanged). Case: None in this repository; the cases are Lunatik's run. Host probe: tails r0 = 2 (XDP PASS), r0 = 3 (TX), r0 = -1 (TC UNSPEC) against r0 = 0 and r0 = 2 with no error.
  • Met: Issue luaebpf: a program file says the verdict a stop of the program returns #45: "a stop is still logged and counted as today" No line under emit/ changes. Each stop's block counts and logs before it jumps to the tail (frame.stops, emit/frame.lua:535), and the tail alone reads unit.error. Case: None here; Lunatik's run reads the count at the stop's line and one logged line under error = PASS. Probe: the object compiled with error = PASS carries the stop's line body.bpf.lua:6: out of bounds.
  • Differs: Issue luaebpf: a program file says the verdict a stop of the program returns #45: "a test holds a program declared to pass on a stop, which reads past a short packet and lets it through, counted as a stop, and one declared as today, which drops it" Not in this diff. The Update's point 2 puts the cases in Lunatik's tests/luaebpf with the move of the mount, and the body says #45, which it does not close. Case: No case can exist in this repository, which has no suite (luaebpf AGENTS.md, Build, install, test).
  • Met: Issue luaebpf: a program file says the verdict a stop of the program returns #45, Update of 2026-11-27 (D212 A): "a stop a file declares is still logged and counted, and a file that declares none keeps XDP_ABORTED and TC_ACT_SHOT" opts.error == nil and action.ABORTED or opts.error, and action.SHOT in TC (lib/bpf/xdp.lua:96, lib/bpf/tc.lua:105). Case: Lunatik's existing bounds.sh, divzero.sh, verdict.sh and ctx.sh fail if a file that names none returns anything else; they run with the Lunatik pull request. Probe: r0 = 0 and r0 = 2.
  • Met: Run's Update: "The option is error, on xdp.program and on tc.program ... under the name programs.declare already takes it by" opts.error is read in both constructors (lib/bpf/xdp.lua:96, lib/bpf/tc.lua:105) and documented in each @tparam (xdp.lua:82-83, tc.lua:91-92). Case: None here; Lunatik's run. Probe: both constructors answer the named action in .error.
  • Met: Run's Update: "error is optional, and is an action of the program's type, held to what default is held to: an integer within linux.xdp.action or linux.tc.action. A file that names none gets XDP_ABORTED in XDP and TC_ACT_SHOT in TC, as today." unmet(verdict, actions) is run over both by checkverdicts (programs.lua:44-52, 70-77), called from programs.declare (programs.lua:97). Case: None here. Probe: 5, -1, 99 and -2 are refused, and 0 to 4 and -1 to 8 are accepted.
  • Met: Run's Update: "A value that is no action is refused at the line of the program's function, as default is: <file>:<line>: xdp.program's error verdict is not an integer, or is not an XDP action; tc.program's and is not a TC action alike." refuse() names info.linedefined of fn (programs.lua:65-68); the message is composed at programs.lua:74. Case: None here; the two refusals are cases of Lunatik's run. Probe prints the four messages at the function's line, and false is refused as not an integer.
  • Met: Run's Update: "A stop that is to take the program's default names the same action in both ... There is no value that means "the default"." No sentinel exists: any value that is not an integer within the actions is refused (programs.lua:44-52). The guide says to name both at doc/guide/08-luaebpf.md:150-151. Case: None here. Probe: {default = PASS, error = PASS} compiles to r0 = 2 in both places.
  • Met: Run's Update: "It is the program's and not the object's, unlike license: two programs of one file may name two, and a function both call stops each with its own." emit.program builds a unit per program with its own error (emit/init.lua:273-276). A callee's tail raises the flag and returns 0 (emit/init.lua:160-164), and its caller takes its own tail. Case: None planned by the Update. Probe two.bpf.lua: four programs sharing half end r0 = 2, 3, -1 and 2.
  • Met: Run's Update: "Every stop takes it, from any frame: a read past the packet, a division or a modulo by 0, a for step of 0, a for past the kernel's budget, a map key or value its spec cannot pack, an update or a delete the map refuses, a skb:priority outside its range, a verdict the program computed that is no action, and any of these in a function it calls." All 12 frame.stop sites (emit/arithmetic.lua, call.lua, forloop.lua, map.lua, packet.lua) and the callee flag (emit/call.lua:142) route through abort(f) (emit/frame.lua:467) to the one tail, emit/init.lua:153-166. Case: Lunatik's run holds a read past the packet alone. The other stop kinds under a named error have no case; the trace is what holds them.
  • Met: Run's Update: "A stop returns at once and undoes nothing. What the program wrote before it, a map entry or skb:priority, stays written, and under a verdict that lets the packet go on the packet goes on with it." No stop block changes; the guide states it at doc/guide/08-luaebpf.md:152-154. Case: None: no case of the Update reads a map entry or a priority written before a stop under a verdict that passes.
  • Differs: Run's Update: "xdp:xdp_exception is the kernel's, fired for XDP_ABORTED (netif_receive_generic_xdp in net/core/dev.c, and the drivers): an XDP program whose error is another action fires it at no stop, and its stops are read in the trace ring and with lunatik bpf --errors." The page says the kernel fires it for XDP_ABORTED and for an XDP_TX or XDP_REDIRECT it fails to carry out, so such a program's stops are read in the trace ring and with lunatik bpf --errors (doc/guide/08-luaebpf.md:154-157, fixup c2ca866). "At no stop" does not hold in the source: generic_xdp_tx (net/core/dev.c:5075 in 6.8) and ixgbe_run_xdp (ixgbe_main.c:2233) fire it for a failed TX or REDIRECT. Case: None can on this host: bpftool prog run does not reach netif_receive_generic_xdp, and no native-XDP driver is present. The reading is from source at v6.6, 6.8, v6.12 and master.
  • Met: Run's Update: "No kernel API is added: the verdict is a value of the type's uapi actions, which the program already returns, so the option holds on every kernel the compiler supports. The license a program that may stop needs does not change." Nothing changes under emit/, writer.lua or loader.c. The tail's instruction is the same code:set with another immediate (emit/init.lua:158; insn.lua:156 takes -1). Case: None needed: the object differs in one immediate, as the probe's open and closed objects show.
  • Met: Run's Update, point 1: "luaebpf, this run: the two constructors, the check in programs.lua, and the documents, under #45, which it does not close. The documents are the docs of bpf.xdp and bpf.tc, doc/guide/08-luaebpf.md (what a program returns and its diagram, the three places a file fails, the rows of the refusals) and doc/guide/09-luaebpf-by-example.md and doc/design/luaebpf/api.md where they say what a stop returns ... The sentence "a program that must let it through tests #p before it reads" becomes the option." Changed: lib/bpf/xdp.lua, lib/bpf/tc.lua, lib/bpf/map.lua:162, guide 08 (diagram :109-111, paragraph :138-159, second diagram :168-173, Refused and Stops bullets :194-208, "Stops" :266-268, rows :669 and :672), guide 09 (:14-16, :91-93) and api.md:113-116. The #p sentence is replaced at guide 08:143-148. Past the list, compiler.md:62-63 and :203-204 and kernel-notes.md:232-233 are corrected by fixup 4bbbc0f. Case: ldoc . exits 0. A grep for "error verdict of" finds testing.md alone, which describes cases whose programs name none.
  • Met: Run's Update, point 2: "Lunatik, a second run: the move of the luaebpf/ mount to that commit with the cases above, described in tests/README.md, which closes luaebpf: a program file says the verdict a stop of the program returns #45." Not this diff, by the Update's own split. The commit the mount moves to is now 40c3655. Case: The second run's.
  • Met: Run's Update: "Not part of this change: the first bullet of .agents/rules/luaebpf.md, which is rules: luaebpf.md says a stop takes the default verdict #22's, and pcall in a compiled function." .agents/rules/luaebpf.md is untouched, and no file under emit/ changes. Case: None: git diff --stat over the nine files.

The matrix the change is held to:

The diff carries no test: luaebpf's cases live in Lunatik's tests/luaebpf, and the Update's point 2 puts them in Lunatik's run. The cells below marked "probe" are what this review ran on the host with lua5.5 over the branch's compiler (scratch/luaebpf-45/review-error-verdict/probe.lua, compile.lua, progs/). The probes compile and disassemble; they load nothing and touch no device.

Matrix, operation by type by outcome:

  • No error, XDP: the tail is r0 = 0, XDP_ABORTED (probe, closed.bpf.lua). At run time, Lunatik's existing bounds.sh, divzero.sh, verdict.sh, forvar.sh, call.sh and mapset.sh hold it once the mount moves.
  • No error, TC: the tail is r0 = 2, TC_ACT_SHOT (probe, two.bpf.lua program "four"). At run time, Lunatik's bounds.sh and ctx.sh.
  • error an action, XDP: PASS gives r0 = 2 under a default of DROP (r0 = 1), TX gives r0 = 3 (probe). The run-time case, a short frame returning XDP_PASS with the stop counted and logged once, is Lunatik's run; none here.
  • error an action, TC: UNSPEC gives r0 = -1 (probe). The run-time case with action.OK is Lunatik's run.
  • error equal to default: the body's own example compiles to r0 = 2 in both places, and its stop's line is body.bpf.lua:6: out of bounds (probe).
  • error not an integer ("pass", true, false, 2.0, a table): refused "xdp.program's / tc.program's error verdict is not an integer" at the function's line (probe). The suite case is Lunatik's run.
  • error an integer outside the actions (5 and -1 in XDP, 99 and -2 in TC): refused "is not an XDP action" / "is not a TC action" (probe). The suite case is Lunatik's run.
  • default and error both invalid, or default missing: the default's refusal comes first (probe).
  • Two programs of one file sharing a callee: the tails are r0 = 2, r0 = 3, r0 = -1 and r0 = 2, each its own, and the callee's own tail is r0 = 0 with the flag (probe, two.bpf.lua). No suite case is planned by the Update.
  • Every stop kind from any frame: by trace only. All 12 frame.stop sites and the callee flag (emit/call.lua:142) route through abort(f) (emit/frame.lua:467) to the one tail (emit/init.lua:158). The Update plans a case for a read past the packet alone.
  • A stop still logged and counted: no line under emit/ changes; the run-time case is Lunatik's run.

What nothing on this kernel can see:

  • The xdp:xdp_exception behaviour was read in source (6.8 tree, and net/core/dev.c fetched at v6.6, v6.12 and master) and not run. bpftool prog run does not pass through netif_receive_generic_xdp, and no native-XDP driver path (ixgbe's failed TX or REDIRECT) exists on this host.
  • Kernels other than the host's 6.8 were not run.

Also checked: ldoc . exits 0 with the workflow's inputs, and advisory.sh, author-email, title.sh and pr-body.sh pass on the folded tip.

This branch has not been deployed

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

Labels

complexity: medium Several call sites, a new test, or a core path to audit workflow-reviewed reviewed end to end by a review workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant