Home / Software y Cloud / Can you run code inside the Linux kernel without compiling or rebooting?

Can you run code inside the Linux kernel without compiling or rebooting?

eBPF programs running in the Linux kernel

The short answer is yes, and the name of that possibility is eBPF (extended Berkeley Packet Filter). Even though the name smells like the packet filtering of the 1990s, eBPF has become the infrastructure on which much of the observability, networking and security of modern servers is now built. It is not a patch: it is a change in architecture so deep that it is reshaping the relationship between applications and the operating system.

To understand it you have to look at the kernel (the core of the operating system that manages memory, processes, hardware and networking) and at how guarded it is. For decades, the only way for your program to touch the kernel was to recompile the system itself or to load a kernel module: bespoke C code that, if it contained an error, could bring down the whole server or open a security hole. That is why modules demand absolute root privileges and few dare touch them in production.

eBPF changes the rules: it lets you load, hot, without rebooting, tiny programs that run inside the kernel but within a sandbox (an isolated zone that limits what that code can do). The key lies in three pieces: the verifier, the JIT and the BPF maps.

The verifier is a static analysis that checks your program before running it. It walks every instruction, verifying that the loop terminates, that there are no out-of-bounds memory accesses, that two threads cannot deadlock and that the code completes in bounded time. If anything does not add up, it rejects the program and it never runs. That check is what allows third-party code to run in the core without becoming a security risk.

The JIT (just-in-time compiler) translates that eBPF bytecode into native CPU instructions for the server on the fly. Without JIT, eBPF would still work, but by interpreting bytecode (slower). With JIT, the overhead (extra cost) of each program is nanoseconds: network packets pass through without measurable performance loss in most workloads.

To talk to the outside world there are the BPF maps: data structures (hash maps, lists, counters, queues) shared between eBPF programs and user space. A kernel program writes to a map, and your user-space daemon reads it via a system call. That bidirectional, real-time interaction is what turns eBPF into a control tool, not just an observation one.

Where do these programs hook in? At hook points. There are dozens: kprobes and tracepoints for tracing any kernel or driver function; XDP (eXpress Data Path) for intercepting network packets as they arrive at the card and before they climb the TCP/IP stack; and tc (traffic control) for pinning classifying rules one layer higher. Deciding where to hook is deciding when you get to see the world.

With that in hand, the ecosystem has exploded on three fronts. Observability is the most visible: tools such as bpftrace let you write traces in a small awk-like language and watch in real time what each process does, with data at kernel event level (syscalls, context switches, memory allocations), far from the noise that injecting code used to mean. Networking is the second front: Cilium is a networking and policy implementation for Kubernetes built almost entirely on eBPF, replacing iptables (Linux’s classic firewall rule table) with programmatic rules that perform better and are easier to manage. And security is the third: Falco watches syscalls and events to detect anomalous container behaviour — someone opening a root shell, a process reading /etc/shadow — in real time.

There are, of course, nuances. eBPF is not for everyone: it is programmed in C or Rust, it needs recent kernel hooks (enterprise distros with old kernels support it poorly), and although the verifier is very strict, the set of prohibited rules (long loops, some functions) limits what you can do inside. Tools like Cilium or Falco use it transparently, so the benefit arrives without writing a single line of BPF.

Perhaps the best metaphor is an engine that is allowed to change gear while still rolling. Linux was always a monolith that you touched with gloves or by recompiling. eBPF turns it into a system where the supervised kernel code can evolve piece by piece, with validation up front and no reboots. And for a server operating system that is not a curiosity: it is the difference between straining the cable and replacing it while hot.