Landlock

On this page 7

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.

  1. Create a ruleset that lists the handled access types, for example reading files, writing files and binding TCP ports.
  2. Add rules that allow specific access, such as read access beneath a directory or connection to TCP port 443.
  3. Set no_new_privs with prctl, which prevents the process from regaining privileges through setuid binaries.
  4. 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 versionFirst kernelMain addition
ABI 1Linux 5.13Core file system rights: read, write, execute, create, remove
ABI 2Linux 5.19Control over renaming and linking files across directories
ABI 3Linux 6.2Control over file truncation
ABI 4Linux 6.7TCP bind and connect restrictions by port
ABI 5Linux 6.10Control over ioctl requests on device files
ABI 6Linux 6.12Scoping of abstract Unix sockets and signals
Landlock ABI versions and the capabilities they add

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.

MechanismWho sets policyWhat it controlsPrivileges needed
LandlockThe application itselfObjects such as paths and portsNone
SeccompThe application or launcherSystem calls and their argumentsNone with no_new_privs
AppArmorAdministrator profilesPaths, capabilities, networkRoot to load profiles
SELinuxSystem-wide policyLabeled objects and typesRoot to change policy
BubblewrapLauncher argumentsNamespaces and mount viewsUser namespaces
Landlock and related isolation mechanisms

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 typeAllowed accessReason
Image converterRead input directory, write output directoryBlocks access to home files and keys
Web serviceRead application files, bind one TCP portLimits damage after code execution
Archive extractorWrite only beneath the target directoryPrevents path traversal escapes
Package build stepRead sources, write build tree, no TCPStops unexpected downloads
Choosing a Landlock policy for typical programs

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.