[blog] From the Kernel to the Moon: A Journey into Lunatik Bindings

106 views
Skip to first unread message

Lourival Vieira Neto

unread,
Mar 19, 2025, 8:14:49 PM3/19/25
to lu...@googlegroups.com
Hi folks,

With GSoC approaching, I wrote an article on extending Lua with kernel
APIs and embedding the Lua interpreter into Linux subsystems using
Lunatik—an in-kernel Lua runtime that enables dynamic scripting
without requiring recompilation.

The post covers key aspects of Lunatik bindings, including runtime
management, integration into the framework, and practical examples
like Xtables and kfifo.

Whether you're considering a GSoC project or just interested in kernel
scripting with Lua, I hope this serves as a helpful resource!

📖 Read it here:
https://medium.com/@lourival.neto/from-the-kernel-to-the-moon-a-journey-into-lunatik-bindings-c2cac8816f9e

Best regards,
--
Lourival Vieira Neto

Rett Berg

unread,
Mar 21, 2025, 11:41:26 AM3/21/25
to lua-l
Cool stuff, another place where Lua can run!

Is there a motivation for the project besides "achieve[ing] a fast time-to-market for delivering a smart firewall solution based on Netfilter scripting to a major Internet Service Provider (ISP)"?

For example, could this be useful for the Linux kernel's test suite? Could it be used to intentionally add hooks for user programs to interact with the kernel unsafely on dev/test hardware for the purpose of debugging and real-time development?

Best,
Rett

Ką Mykolas

unread,
Mar 21, 2025, 11:58:30 AM3/21/25
to lu...@googlegroups.com
On Fri, Mar 21, 2025 at 5:41 PM Rett Berg <goog...@gmail.com> wrote:
> For example, could this be useful for the Linux kernel's test suite? Could it be used to intentionally add hooks for user programs to interact with the kernel unsafely on dev/test hardware for the purpose of debugging and real-time development?

I would guess so. Been using Lua for years in my former workplace for
wrapping and abstracting some test suites for big C codebase (well,
not as big as the Kernel goes, but still).

Lourival Vieira Neto

unread,
Mar 21, 2025, 1:38:17 PM3/21/25
to lu...@googlegroups.com
On Fri, Mar 21, 2025 at 12:41 PM Rett Berg <goog...@gmail.com> wrote:
>
> Cool stuff, another place where Lua can run!
>
> Is there a motivation for the project besides "achieve[ing] a fast time-to-market for delivering a smart firewall solution based on Netfilter scripting to a major Internet Service Provider (ISP)"?

Indeed; actually, I meant the motivation only for dropping the
framework approach and focusing on the Netfilter binding. The
motivation for scripting the kernel with Lua is the same as any other
application =). You can find some examples in the repository [1],
including an "extremely useful" konami code key-locker ;-).

> For example, could this be useful for the Linux kernel's test suite? Could it be used to intentionally add hooks for user programs to interact with the kernel unsafely on dev/test hardware for the purpose of debugging and real-time development?

Yes, you can even use kprobes for that. We have a luaprobe library.
For example, you can dynamically do something like this:

```
local probe = require("probe")

probe.new("my_symbol", {
pre = function () print("before") end,
post = function () print("after") end,
})
```
A more complete example on luaprobe usage is here [2], where we track syscalls.

We have also some GSoC project ideas for this year:

- Lunatik binding for Human Interface Devices (HID) drivers [3];
- Conntrack and NAT support for Lunatik [4];
- Lunatik Binding for Linux Traffic Control (TC) and eBPF Maps [5].

[1] https://github.com/luainkernel/lunatik/tree/v3.6?tab=readme-ov-file#examples
[2] https://github.com/luainkernel/lunatik/blob/v3.6/examples/systrack.lua
[3] https://github.com/labluapucrio/gsoc?tab=readme-ov-file#lunatik-binding-for-human-interface-devices-hid-drivers
[4] https://github.com/labluapucrio/gsoc?tab=readme-ov-file#conntrack-and-nat-support-for-lunatik
[5] https://github.com/labluapucrio/gsoc?tab=readme-ov-file#lunatik-binding-for-linux-traffic-control-tc-and-ebpf-maps
Reply all
Reply to author
Forward
0 new messages