Using LLM-Based Verification to Eliminate Bugs in Linux's Network Stack

gopiandcode1 pts0 comments

Basis | Using LLM-based Verification to Eliminate Bugs in Linux's Network Stack

Using LLM-based Verification to Eliminate Bugs in Linux's Network Stack

Using LLM-based Verification to Eliminate Bugs in Linux's Network Stack<br>Article:<br>Yiyun Liu, Kiran Gopinathan, Nikhil Pimpalkhare

Research: Yiyun Liu

We used LLMs to verify Linux's nftables `nft` CLI utility. Along the way, we found and patched bugs that had sat in the kernel for years.

Firewall rules act like railway signals, telling each packet whether it may pass.

LLMs have grown alarmingly capable at finding bugs in production<br>software. This accentuates an already severe risk: much of our<br>critical infrastructure is mediated by software, and every bug in that<br>software is a potential exploit. Formal verification offers the<br>potential to mitigate this risk by producing proofs that entire<br>classes of bugs are impossible, but it has seen limited real-world use because it demands scarce, expensive, specialist expertise.<br>Fortunately, LLMs are increasingly capable of verification too,<br>pointing toward a future where critical software infrastructure is<br>secure by construction.

lean-zip, a formally verified zlib implementation written by loosely supervised AI agentsIn this blog post, we report on results from LLM-guided verification<br>experiments at Basis. Our target was a key component of Linux&rsquo;s<br>network stack: the nftables firewall compiler and optimizer, which we<br>set out to verify in the Rocq theorem prover. nftables is one such piece of critical<br>infrastructure. It filters the traffic of almost every Linux machine,<br>and vulnerabilities in it are treated with the highest severity,<br>since a firewall that misfilters exposes every machine it was meant to<br>protect.<br>In the process of verifying nftables, we uncovered two critical<br>bugs affecting every version of Linux since 2022 (these have been<br>disclosed to maintainers1). Our verified<br>implementation was proven to be free of these semantics-altering bugs,<br>and a secondary experiment showed that the more severe of the two<br>would not be found via a naive LLM bug search.<br>Our experiments suggest that the effort involved in producing<br>proofs and constructing robust verified systems is increasingly<br>automatable. The rest of this post gives an overview of nftables, the<br>bugs we found, and our process for using LLMs to verify critical<br>networking software.<br>A quick primer on nftables and its bugs<br>nftables is one of the firewall mechanisms provided by the Linux<br>operating system. Every packet your OS receives passes through<br>nftables, which determines which packets are forwarded and which are<br>dropped. Having replaced iptables in 2014 as the default packet<br>filter of every major Linux distribution, nftables today guards<br>everything from home routers to container networks; if a Linux machine<br>filters traffic, nftables almost certainly decides what gets<br>through. Firewalls are a critical component of most network security<br>layers, and vulnerabilities in them can compromise whole systems. A<br>verified implementation of nftables would increase assurance in this<br>critical layer.<br>nftables rulesets and compilation pipeline<br>The full architecture of nftables is shown below and consists of a<br>userspace CLI tool and a kernel module:<br>The architecture of nftables. The nft cli tool's compiler and optimizer turn the ruleset into bytecode; the kernel's bytecode executor runs it over every packet flowing through the machine. The optimizer (highlighted) is where the bugs we found live.This CLI tool takes as input a series of user-supplied policies,<br>expressed as an ordered list of rules, where each rule matches on<br>some part of the packet (its source address, its destination port, its<br>TCP flags) and returns a verdict, i.e. accept or drop. For<br>example, the following rules tell nftables to accept any packets<br>where the destination address (daddr) is 192.168.50.1 or<br>192.168.50.2.<br>ip daddr 192.168.50.1 accept<br>ip daddr 192.168.50.2 accept<br>The nft command-line tool parses these rulesets and compiles them<br>into a compact register-based bytecode, which it then loads into the<br>kernel. There, the kernel&rsquo;s interpreter uses the bytecode to<br>compute a verdict for every packet passing through the network stack:<br>either accepting it through the firewall or dropping it.<br>As this bytecode runs on every packet the system sees, it sits on a<br>hot path of the kernel, and thus its efficiency is critical. For this<br>reason, the CLI tool also provides an optimizer module for the source<br>language that rewrites your input rules to run more efficiently<br>(reducing the number of reads, or removing redundant checks). A<br>critical security property that users rely on the optimizer to<br>guarantee is that it preserves the semantics of its input rules. In<br>other words, the verdict computed for a packet should be the same<br>regardless of whether it was passed through the optimized or<br>unoptimized ruleset.<br>We set out to prove the correctness of the nft command-line tool,<br>and in the process found two bugs in the...

nftables bugs linux critical packet verification

Related Articles