Linux Landlock Unprivileged Sandboxing Playbook

2026-04-10 · software

Linux Landlock Unprivileged Sandboxing Playbook

Date: 2026-04-10
Category: knowledge
Domain: software / linux security / sandboxing

Why this matters

A lot of Linux hardening tools are powerful, but awkward in different ways:

Landlock matters because it offers a different shape of control:

The useful mental model is not “Linux mandatory access control replacement.” It is closer to:

portable, app-driven least-privilege sandboxing for file/network access, layered on top of existing Linux security controls.

That makes it interesting for:


1) Quick mental model

Landlock is an allowlist over explicitly handled rights.

High level flow:

  1. Create a ruleset that says which access classes you want to handle.
  2. Add rules that allow specific actions on specific objects.
  3. Call landlock_restrict_self().
  4. The current thread, and then its future children, run under that restricted domain.

Important nuance:

So Landlock is not “deny everything automatically.” It is deny everything you explicitly chose to manage.


2) What Landlock is good at

Strong fits

A) Self-sandboxing user applications

Examples:

B) Developer-facing safety wrappers

Good when you want:

C) Defense-in-depth around file and network access

Landlock is especially nice when you want to reduce the damage from:

D) Progressive hardening with runtime feature detection

Because Landlock is ABI-versioned and intended for best-effort adoption, it is friendly to software distributed across mixed kernel fleets.

Weak fits

A) Full system-wide MAC replacement

That is not Landlock’s job. If you need broad host policy, mature labeling, or organization-wide confinement, SELinux/AppArmor may still be the primary control.

B) Retroactive control over already-open resources

Landlock does not fully solve “what the process already opened before sandboxing.” Pre-opened file descriptors are a real caveat.

C) Policy based on rich identity semantics

Landlock understands kernel objects and rights, not business identity, tenancy metadata, or service-level intent on its own.

D) Complex exception-heavy IPC policy

Its IPC scoping model is intentionally simpler than a general-purpose policy engine.


3) The core API shape

Landlock uses three syscalls:

landlock_create_ruleset()

Creates a ruleset FD and defines the handled access rights.

This is the moment where you declare:

landlock_add_rule()

Adds specific allow rules to that ruleset.

Today, the main rule types are:

landlock_restrict_self()

Enforces the ruleset.

To do this safely, the caller must either:

In practice, the unprivileged pattern is:

prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
landlock_restrict_self(ruleset_fd, 0);

Once applied, the policy is one-way:


4) Best mental model for policy design

Design Landlock policies as minimal capability envelopes.

A solid pattern is:

Example mental sandbox for a document converter:

That is where Landlock shines.


5) ABI versions matter more than kernel version

This is one of the biggest operational points.

You should not gate behavior by “kernel 6.x” heuristics. Use the Landlock ABI version query instead:

abi = landlock_create_ruleset(NULL, 0, LANDLOCK_CREATE_RULESET_VERSION);

Why:

Practical ABI progression

ABI Mainline orientation New capability
1 Linux 5.13 baseline filesystem rules
2 Linux 5.19 LANDLOCK_ACCESS_FS_REFER
3 Linux 6.2 LANDLOCK_ACCESS_FS_TRUNCATE
4 Linux 6.7 TCP bind/connect control
5 Linux 6.10 LANDLOCK_ACCESS_FS_IOCTL_DEV
6 Linux 6.12 IPC scoping for abstract UNIX sockets and signals

Recent kernel docs also describe newer ABI growth such as:

Operational rule:

Probe ABI, mask unsupported rights/flags, and still enforce the strongest compatible subset.

That is the right Landlock rollout style.


6) Filesystem rights: the useful operator view

Landlock filesystem policy is path-hierarchy oriented. The main rights to remember are:

Read/execute basics

Write/mutation basics

Reparenting / linking

Device ioctl control

Two easy mistakes

A) WRITE_FILE and TRUNCATE are not the same

This catches people all the time.

If your app rewrites files in place, creates output with overwrite semantics, or uses O_TRUNC, then WRITE_FILE alone is often not enough.

The kernel docs explicitly recommend treating these together in most write scenarios. A classic gotcha is creat(2):

B) REFER is special

LANDLOCK_ACCESS_FS_REFER is the oddball. It is effectively denied by default and must be explicitly handled/allowed for relevant directories.

Also:

If your application depends on rename-heavy workflows, temp-file-then-atomic-move patterns, or moving files across dirs, you must test this explicitly.


7) Network rules: simple, but useful

Since ABI v4, Landlock can control TCP ports with:

This is not a full network policy language. That is fine.

It is still very useful for cases like:

One detail worth remembering:

This matters for servers or tooling that say “bind any free port.”


8) IPC scoping is powerful, but more rigid than path rules

Since ABI v6, Landlock can scope some IPC interactions to the same or nested Landlock domain:

This is important because file/network sandboxing alone does not solve all cross-process influence.

The big constraint:

So if you scope it, you cannot later poke holes for some external resource the way you can with path or port rules.

That makes IPC scoping best for:

It is less ideal for messy legacy apps with many exception cases.


9) The biggest practical caveat: pre-opened file descriptors

Landlock is not a time machine.

Files or directories opened before sandbox enforcement are a major caveat. Some rights are effectively checked at open time and then carried by the FD.

This matters for:

Operational lesson:

Sandbox as early as possible, before opening anything you do not want to keep.

If you must pre-open resources:

This is a classic place where a “secure design” quietly loses a lot of value.


10) Threading caveat: know what restrict_self really hits

Historically, landlock_restrict_self() applies to the calling thread and its future descendants. It does not magically retrofit sibling threads.

That makes Landlock adoption much cleaner in:

It is trickier for already-multithreaded processes.

Recent kernel docs describe a newer ABI flag for thread-synchronized enforcement (TSYNC, ABI v8), which is exactly meant to improve this story. But you still need runtime ABI handling and careful testing.

Operational rule:


11) Bind mounts, OverlayFS, and path-shape gotchas

This is an easy place to get surprised.

Bind mounts

Landlock restrictions can propagate through bind-mounted hierarchy views in a way that makes sense for path-based hierarchy control.

OverlayFS

OverlayFS is different. The kernel docs explicitly note that OverlayFS layers and merged hierarchies are treated as standalone from a Landlock perspective.

Meaning:

Operational consequence:

Policy should be written against the actual hierarchy the sandboxed process will access, not against what you hope is “the same data underneath.”

If your app runs in overlay-heavy container/runtime environments, test the exact mount topology. Do not assume storage-layer intuition is enough.


12) Landlock is layered, not singular

A process can enforce multiple rulesets over time. These compose into a Landlock domain.

Useful interpretation:

But there is a practical limit to the number of composed rulesets. Also, arbitrary repeated layering is usually worse than building one coherent ruleset.

Best practice:


13) Where Landlock fits relative to seccomp, SELinux/AppArmor, and BPF LSM

Landlock vs seccomp

Use seccomp when you need:

Use Landlock when you need:

They are complementary. A strong pattern is:

Landlock vs SELinux/AppArmor

Use SELinux/AppArmor when you need:

Use Landlock when you want:

They also compose.

Landlock vs BPF LSM

BPF LSM is better when you need:

Landlock is better when you want:

Landlock is much closer to “a practical application sandbox primitive.”


14) A safe rollout pattern

Stage 0 — Capability discovery

Before you promise anything:

Also remember:

Stage 1 — Read-only sandbox first

Start with the easiest high-confidence shape:

Avoid rename-heavy and device-heavy flows first.

Stage 2 — Add write paths carefully

Introduce:

This is where file workflow edge cases begin to appear.

Stage 3 — Add network restriction

If the application truly only needs:

encode that.

Stage 4 — Add IPC scoping only when process topology is clean

Do this after you understand the actual process graph and communication paths.

Stage 5 — Add seccomp or host policy on top

Landlock is usually strongest as one layer in a stack, not the only control.


15) Common failure modes in real deployments

A) Sandboxing too late

Symptoms:

B) Forgetting TRUNCATE

Symptoms:

C) Rename/link workflows break mysteriously

Symptoms:

Usually a REFER / source-destination rights issue.

D) Threading assumptions are wrong

Symptoms:

E) OverlayFS path assumptions are wrong

Symptoms:

F) Over-broad parent directory policy

Symptoms:

The kernel docs recommend defining rights as close to leaf hierarchies as possible. That is good advice.


16) Practical design checklist

Before shipping a Landlock sandbox, ask:

Resource model

Process model

Compatibility model

Validation model


17) Best practices worth keeping

Prefer leaf-scoped rules over giant parent trees

This reduces accidental ambient reach and makes directory moves easier to reason about.

Enforce early

The value of Landlock drops fast if you open half the world before calling it.

Probe ABI at runtime

Do not ship kernel-version folklore.

Build one coherent ruleset when possible

Use multiple rules, not arbitrary numbers of rulesets.

Treat write workflows as a matrix

Test separately:

Combine with other controls

Landlock is better with:


18) When I would reach for Landlock first

I would reach for Landlock first when I want:

I would not start with Landlock when the main problem is:


Bottom line

Landlock is one of the more practical Linux security primitives to adopt because it hits a rare sweet spot:

Its main traps are also predictable:

If you treat those as first-class design concerns, Landlock becomes less like a niche kernel feature and more like a genuinely deployable sandboxing tool.


References