News for hackers. Stuff that matters.
Re:Lua in the Kernel? by WalterGR on Friday September 18, 2020 @04:26AM (#24514311)
I'd be surprised if it could prevent a script from running indefinitely. In particular, limiting the number of Lua bytecode instructions is insufficient

FTA: “Lua has a facility to interrupt a script after it has run a certain number of instructions.”

Re:Lua in the Kernel? by OskarS on Friday September 18, 2020 @04:56AM (#24514510)
string.find is implemented in C, not Lua. As far as Lua is concerned, that call is a single instruction.
Re:Lua in the Kernel? by dathinab on Friday September 18, 2020 @12:00PM (#24518420)
You could have a string.find C implementation which gets an additional budget parameter and depending on it might limit search or similar (and reports back how much "budged" was used)

Through always under the assumption that the C function is implemented correctly and adding need to do some explicit budged keeping makes it more complex and in turn more prone to errors.

Re:Lua in the Kernel? by DarkWiiPlayer on Friday September 18, 2020 @06:57AM (#24515209)
A single instruction that can run for a long time. That's the point.
Re:Lua in the Kernel? by pctammela on Friday September 18, 2020 @09:00AM (#24516148)
ditto for eBPF when acessing the C helpers
Re:Lua in the Kernel? by raverbashing on Friday September 18, 2020 @05:01AM (#24514556)
Just add a time limit to the sandbox as well
Re:Lua in the Kernel? by lioeters on Friday September 18, 2020 @10:59AM (#24517593)
Apparently, the sandbox cannot enforce such a time limit.

From a similar thread to the one linked from the root comment:

> ..Attempts to control untrusted scripts may be in vain. E.g. string.find, string.rep and other C functions can be abused and will either run forever or allocate unlimited amounts of memory. This is true for both Lua and LuaJIT.

> The only reasonably safe way to handle untrusted Lua scripts is to isolate them in a process context and to make use of per-process quotas/limits provided by the operating system.

Improved functions sandboxing in Lua and LuaJIT - http://lua-users.org/lists/lua-l/2011-02/msg01106.html

Re:Lua in the Kernel? by smilliken on Friday September 18, 2020 @11:56AM (#24518365)
This solution is problematic because there's no one time limit that makes sense across all past and present CPUs that span orders of magnitude of performance.. your lua script would always fail on some CPU and there wouldn't be a way to fix it.