Lion Cipher Lab
Sandbox a program's filesystem access from scratch with Landlock
- Cyber / Security Engineer
- Advanced
- ~70 min
- Free · no account required
Why it matters
Most Linux sandboxing is something an ADMINISTRATOR does TO a program from the outside: AppArmor and SELinux profiles are written by whoever owns the box, loaded into the kernel, and enforced on processes that have no say in it. That is powerful, but it means the developer who knows EXACTLY which files their parser should ever touch cannot express that knowledge — they have to file a ticket and hope the sysadmin writes the policy. Landlock flips this. It is a Linux Security Module — an LSM, a kernel subsystem that hooks security decisions like 'may this process open this file' — that lets an…
What you'll learn
- what Landlock is and where it sits: a Linux Security Module (LSM) that lets an UNPRIVILEGED process sandbox itself — no root, no policy file, no admin
- the three Landlock syscalls: landlock_create_ruleset(2), landlock_add_rule(2), landlock_restrict_self(2), and why each exists
- querying the supported Landlock ABI version with LANDLOCK_CREATE_RULESET_VERSION, and detecting a kernel that ships Landlock disabled (ENOSYS)
- the filesystem access rights (LANDLOCK_ACCESS_FS_READ_FILE / WRITE_FILE / READ_DIR ...) and what it means to HANDLE a right in a ruleset
- adding a path_beneath rule that grants only chosen rights beneath one directory file descriptor you opened
- the mandatory prctl(PR_SET_NO_NEW_PRIVS, 1) gate that lets an unprivileged process restrict itself, and why the kernel demands it
- proving confinement dynamically: the allowed dir reads, a WRITE to it fails EACCES, a read OUTSIDE the allowlist fails EACCES
- the named footguns: unhandled rights are UNRESTRICTED (deny-by-default only for rights you handle), fds opened BEFORE restrict_self are not covered, ABI right silently no-ops on older kernels
- the judgment of Landlock vs seccomp (objects vs syscall numbers) vs AppArmor/SELinux (self-sandbox vs admin-authored MAC), and layering them for defense-in-depth
Steps in this lab
- What Landlock is, and why 'self-sandboxing' is the whole point
- Set up a scratch box and confirm Landlock is actually enabled
- Create a ruleset — and understand what it means to HANDLE a right
- Add a rule: allow read-only access beneath one directory
- Lock it in: PR_SET_NO_NEW_PRIVS, then landlock_restrict_self — the full program
- Prove confinement: run it and read the EACCES
- The named failure modes (this is the advanced part)
- The judgment: Landlock vs seccomp vs AppArmor/SELinux — and layering them