Skip to content

Add Landlock syscall tests#13740

Open
connrg wants to merge 1 commit into
google:masterfrom
connrg:landlock-syscall-tests
Open

Add Landlock syscall tests#13740
connrg wants to merge 1 commit into
google:masterfrom
connrg:landlock-syscall-tests

Conversation

@connrg

@connrg connrg commented Jul 17, 2026

Copy link
Copy Markdown

What this is

Tests for Linux Landlock — the kernel feature that lets a process lock itself into a limited set of files, network ports, and so on.

This follows the approach @EtiennePerot suggested in #13439: start by adding tests against the real Linux kernel, cover the rule types we'd want gVisor to support, and skip under gVisor (which doesn't implement Landlock yet). Once the suite is in, gVisor can be matched against it one feature at a time, dropping the "skip on gVisor" guard for each feature as it's implemented.

How the tests work

Landlock is one-way: once a process locks itself down it can't undo it, so a test can't apply a policy to itself without poisoning the whole test binary. As Etienne suggested, each test forks a child, locks the child down, has it try something, and the parent checks from the outside whether it was allowed or blocked (via the child's exit code). I used the existing seccomp.cc tests as a model, as he recommended.

What's covered

Grouped by the Landlock version that introduced each feature. Each test skips itself if the kernel is too old:

  • files — reading, writing, listing directories, executing, creating, deleting, and truncating files (and creating/deleting directories)
  • renaming/moving a file across directories
  • binding and connecting TCP ports
  • ioctls on device files
  • "scopes" — blocking signals and abstract Unix sockets to processes outside the sandbox
  • error cases for the three Landlock syscalls (bad fd, missing no_new_privs, unknown flags, and so on)

Plus two of the trickier guarantees: that the sandbox is inherited by child processes, and that stacking a second policy can only ever take access away, never add it.

The newest Landlock version (v7, audit) isn't covered yet — it needs a newer kernel than our test machines run. There's a TODO in the file.

Testing

Ran on Linux 6.14 (Landlock v6): 38 tests, all passing. On older kernels, the unsupported tests skip, and under gVisor everything skips.

Updates #13439.

@google-cla

google-cla Bot commented Jul 17, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@connrg

connrg commented Jul 17, 2026

Copy link
Copy Markdown
Author

I signed it!

@connrg
connrg force-pushed the landlock-syscall-tests branch from 01c716e to 9ae9b2a Compare July 17, 2026 14:49
Adds a syscall test suite for Linux Landlock under test/syscalls/linux.
Each test builds and applies a Landlock ruleset inside a forked child,
then checks from the parent that the rules were actually enforced: files
outside an allowed directory can't be read, written, listed, created or
removed; cross-directory renames are blocked; truncate, TCP bind/connect
and device ioctls are gated; and signals and abstract unix sockets are
scoped.

gVisor doesn't implement Landlock yet, so every test skips under gVisor
and runs against a real Linux kernel as the reference. Tests are grouped
by the ABI version that introduced each feature and skip themselves on
kernels that are too old to support it. As gVisor gains Landlock support
we can drop the per-test gVisor skips one at a time.

Updates google#13439.
@connrg
connrg force-pushed the landlock-syscall-tests branch from 9ae9b2a to 1465227 Compare July 17, 2026 15:26
@EtiennePerot
EtiennePerot requested a review from aaltinaydev July 17, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant