Repository navigation
Conversation
A method a loop calls on a variable that a later pass sets to nil, or to another value, `p:getbyte(i)` in a loop that may write `p = nil`, compiled to a load through whatever word the register holds on that pass, a load the verifier refuses (check_mem_access, "invalid mem access 'scalar'"), where Lua raises. The call is refused at its line now: "'getbyte' takes the packet, not a packet that may be nil". The walk joins the method each pass reads at the call, and the join keeps the first pass's, whose receiver is the packet, while the register past it, which the call passes and the read goes through, holds the packet or nil. CALL holds that register to the method's receiver, as frame.same compares two values of the state, before it lowers the method. The kernel's answer is the verifier's refusal of a load through a register it does not know as a pointer, which the compiler gives at the line instead of an object that does not load. Every program file of Lunatik's tests/luaebpf, tests/tc and tests/xdp compiles to the same object. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A compiled function called no method, and read no field of a view or of a struct map value, once 256 constants preceded the name in its constant table, or for a name longer than 40 bytes: Lua writes `x:name(...)` as SELF and `x.name` as GETFIELD only while the name is a short string whose index fits the instruction, and otherwise as the MOVE of x past the result and a GETTABLE of the name in a register, or as that GETTABLE alone (luaK_self and luaK_indexed, lua/lcode.c). GETTABLE read the name off the receiver as an index into a table of the body, so `ctx:packet()`, `p:getbyte(0)`, `iphdr:view(p, 14)`, `limits:run(n)`, `ip.protocol` and `v.count` were refused by messages that named neither the name nor the limit. Each compiles now to what it compiles to below the 256th constant, and a name the receiver lacks takes the short form's refusal, "the packet has no method '<name>'" and its kin, the context's "'data_end' is a packet bound" among them. GETTABLE with a key the compiler holds as a string reads it as SELF does where the instruction before is that MOVE and the container is a receiver of a method, a runtime, a proxy or a struct codec, and as GETFIELD does otherwise, sharing each step with the instruction it stands for. Lua's own answer is that OP_SELF is that MOVE and that GETTABLE in one instruction (lua/lvm.c). A key held as any string of the body, `v[k]` with `k` the string "count", reads the field it names, as Lua does, where it was refused as an index; a table of the body that is no such receiver, read after that MOVE, keeps the reading of a table, so `s = t; m = t[k]` compiles as it did. That MOVE and that GETTABLE are also what `k = "getbyte"; s = p; m = p[k]` writes on three locals declared `m, s, k`, so a method may now sit in a variable, and CALL, which read the receiver past the method on the word of SELF having written it, holds the method to it: called on another value, or with no argument, which passes nothing past the method, it is refused, "'getbyte' takes the packet, not a number", and called from another register than the one it was read into, "'getbyte' is called through a variable, not where it was read", since where two paths read two methods into one variable the join keeps the first, and both paths would call it. The run method of a runtime is held to the three alike, by the refusal it has, "a runtime is called through its method", and carries the runtime it was read off as a method carries its receiver, where it kept the runtime's own value in `k`, which every lowering reads as a value of the body: kept in a variable, the method would be taken for its runtime, `r.key` its script and `r:run(1)` the call. Part of #10, which the cases of Lunatik's tests/luaebpf close. Every program file of Lunatik's tests/luaebpf, tests/tc and tests/xdp compiles to the same object, the refusal rows of refuse.sh, view.sh and struct.sh answer the same when compiled on the host, and each program of the issue compiles to its control's instructions with those of the pad of constants inserted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A program function cannot call a method, or read a field of a view or of a struct map value, whose
name comes after 256 other constants in it, the distinct strings and numbers it writes, small
integers aside. Nor can any function for a name longer than 40 bytes.
lunatik bpfrefuses bothwith a message that names neither the name nor the limit.
Each now compiles as it does in a shorter function. This script writes such a program file, 300
lines of
n = n + <number>before the calls, whichlunatik bpf long.bpf.luarefuses today atiphdr:view(p, 14)with "argument #1 is a table, and a compiled call passes numbers and packets":A name the receiver lacks gets the message a shorter function gets:
p:setbyte(0)past thoseconstants says "the packet has no method 'setbyte'", where today it says "'packet' is read from a
value the compiler cannot resolve". The same change lets a field be named by a string held in a
variable,
local key = "protocol"and thenip[key], which compiles asip.protocolin a functionof any length, where today every function refuses it.
Its first commit is the one of #50, which refuses a method call on a variable a
loop may set to nil or to a number, and is reviewed there. This change answers
#10, which it does not close: a Lunatik pull request, opened once this one
merges, moves Lunatik's luaebpf mount past this change, adds the tests to tests/luaebpf and closes
the issue. It needs no kernel and no build step of its own.