Landlock is a Linux security module that lets an unprivileged process restrict its own access to the file system, network ports and certain inter-process interactions. Merged into Linux 5.13 in 2021, it brings self-sandboxing to ordinary applications without root privileges, policy files or administrator involvement.
In Linux security, Landlock fills a gap between system-wide mandatory access control, such as SELinux and AppArmor, and system call filtering with Seccomp. The application itself declares what it legitimately needs, and the kernel then denies everything else for that process and all of its children.
How Landlock restricts a process
Landlock works through three dedicated system calls. A program first calls landlock_create_ruleset to declare which access rights it wants to handle, then adds exceptions with landlock_add_rule, and finally enforces the result on itself with landlock_restrict_self.
- Create a ruleset that lists the handled access types, for example reading files, writing files and binding TCP ports.
- Add rules that allow specific access, such as read access beneath a directory or connection to TCP port 443.
- Set no_new_privs with prctl, which prevents the process from regaining privileges through setuid binaries.
- Enforce the ruleset, after which any handled access not covered by a rule fails with a permission error.
Enforcement is irreversible and inherited. A restricted process cannot remove its own restrictions, and every child process inherits them. A process may add further layers, up to 16 stacked rulesets, and each new layer can only reduce access further, never expand it.
File system rules use the path beneath model: a rule attached to an open directory file descriptor grants access to that directory and its entire subtree. Landlock evaluates these rules in addition to standard Unix permissions and any other active security module, so it can only narrow what is already allowed.
Landlock ABI versions and access rights
Landlock evolves through numbered ABI versions, each adding new access rights. Applications query the running kernel with the LANDLOCK_CREATE_RULESET_VERSION flag and then apply the strongest policy the kernel supports, a pattern called best-effort sandboxing.
| ABI version | First kernel | Main addition |
|---|---|---|
| ABI 1 | Linux 5.13 | Core file system rights: read, write, execute, create, remove |
| ABI 2 | Linux 5.19 | Control over renaming and linking files across directories |
| ABI 3 | Linux 6.2 | Control over file truncation |
| ABI 4 | Linux 6.7 | TCP bind and connect restrictions by port |
| ABI 5 | Linux 6.10 | Control over ioctl requests on device files |
| ABI 6 | Linux 6.12 | Scoping of abstract Unix sockets and signals |
Distribution kernels may backport features, so the ABI number reported at runtime is more reliable than the kernel version string. Landlock must also be compiled in and listed in the active security module order, typically through the lsm= boot parameter on older configurations.
Landlock compared with other Linux security mechanisms
Landlock is distinctive because the sandboxed program defines its own policy. Most other mechanisms are configured by an administrator or a separate launcher, as the following comparison shows.
| Mechanism | Who sets policy | What it controls | Privileges needed |
|---|---|---|---|
| Landlock | The application itself | Objects such as paths and ports | None |
| Seccomp | The application or launcher | System calls and their arguments | None with no_new_privs |
| AppArmor | Administrator profiles | Paths, capabilities, network | Root to load profiles |
| SELinux | System-wide policy | Labeled objects and types | Root to change policy |
| Bubblewrap | Launcher arguments | Namespaces and mount views | User namespaces |
These tools are complementary rather than competing. Seccomp filters which system calls a process may make but cannot easily reason about file paths, while Landlock reasons about objects such as directories. A hardened application often combines Seccomp for the syscall surface and Landlock for resource access.
Practical use of Landlock
Landlock is most valuable for programs that process untrusted input, such as parsers, media decoders, archive tools, network daemons and build helpers. After initialization, the program knows exactly which directories and ports it needs and can lock itself down before touching hostile data.
Developers usually rely on wrapper libraries rather than raw system calls. Libraries exist for C, Rust and Go, and generic launchers can apply Landlock rules to unmodified programs from the command line.
| Program type | Allowed access | Reason |
|---|---|---|
| Image converter | Read input directory, write output directory | Blocks access to home files and keys |
| Web service | Read application files, bind one TCP port | Limits damage after code execution |
| Archive extractor | Write only beneath the target directory | Prevents path traversal escapes |
| Package build step | Read sources, write build tree, no TCP | Stops unexpected downloads |
Limitations of Landlock
Landlock restricts only the access types a ruleset explicitly handles. Anything not covered by the running ABI remains allowed, so an application on an older kernel may receive only partial protection, and best-effort code must handle that case deliberately.
- No UDP or raw socket control in current ABIs; network rules cover TCP bind and connect only.
- Not a system-wide policy: it protects only processes that opt in or are launched by a wrapper.
- Pre-opened descriptors remain usable, so files opened before enforcement can still be read or written.
- Kernel dependency: the module must be built and enabled, which varies by distribution.
A common mistake is enforcing too late, after the program has already parsed untrusted data. Another is granting broad rules such as read access to the whole root directory, which undermines most of the protection that Landlock is designed to provide.
Understanding it simply
Landlock lets a program lock itself into a smaller room before it starts risky work. The program tells the system which folders it needs and which network connections it will make, and the system then refuses everything else.
It works like a contractor who hands back every key except the ones for the rooms being renovated. If someone later tricks that contractor, the damage stays limited to those rooms. No administrator has to write rules, because the program sets the limits itself.
Applied in practice
A team maintains a document conversion service on Ubuntu that turns uploaded office files into PDF. Each conversion runs in a worker process that previously had the same access as the service account, including read access to API credentials stored in a configuration directory.
The team adds Landlock to the worker. After loading fonts and libraries, the worker restricts itself to reading one upload directory, writing one output directory and making no TCP connections, using ABI 4 where available. A later penetration test exploits a parser flaw and gains code execution in the worker, but every attempt to read the credentials or contact an external server fails with a permission error. The outcome is a contained vulnerability instead of a data breach.