- Unprivileged Access Control: Restrict process filesystem and network access without requiring root (CAP_SYS_ADMIN) privileges.
- File Hierarchy Restriction: Restrict application read/write access exclusively to pre-approved directory paths.
- Network Socket Binding Limits: Restrict TCP bind and connect calls at the process level.
- Inherited Security Rules: Landlock rules automatically apply to all child processes spawned by the sandboxed process.
1. Landlock LSM Architecture & Unprivileged Security Paradigm
Traditional Linux Security Modules (SELinux, AppArmor) require root privileges and system-wide administrative policy configuration. This security model creates barriers for unprivileged applications that want to sandbox themselves.
Introduced in Linux 5.13 and expanded in subsequent kernel releases, Landlock is an unprivileged LSM that allows any process to restrict its own filesystem and network access rights dynamically.
Once a Landlock ruleset is applied and enforced via landlock_restrict_self(), the security restrictions are permanent for that process and all future child threads, even if the application is compromised later.
Landlock operates as a stacked security module, complementing existing LSMs like AppArmor or SELinux without conflict.
By enabling applications to enforce self-restriction, Landlock prevents compromised worker threads from traversing host file systems.
This granular containment architecture reduces blast radius when processing untrusted user data.
Implementing automated continuous monitoring across production nodes ensures that compliance policies remain enforced during infrastructure updates.
Regular security audits should be integrated into DevOps CI/CD pipelines to verify that system configurations conform to zero-trust architecture standards.
Documenting system architecture and access control rules facilitates compliance verification during independent third-party security audits.
Enforcing strict runtime isolation boundaries prevents privilege escalation vectors across multi-tenant cloud environments.
// Example: Restricting Filesystem Access with Landlock C API
#include
#include
#include
#include
static inline int landlock_create_ruleset(
const struct landlock_ruleset_attr *attr, size_t size, __u32 flags) {
return syscall(__NR_landlock_create_ruleset, attr, size, flags);
}
2. Defining Filesystem Access Rulesets
A Landlock ruleset explicitly specifies allowed filesystem operations, such as LANDLOCK_ACCESS_FS_READ_FILE, LANDLOCK_ACCESS_FS_WRITE_FILE, and LANDLOCK_ACCESS_FS_EXECUTE.
By constructing a ruleset struct and populating allowed directory file descriptors, applications construct an explicit allowlist (default-deny enforcement).
Any attempt to access directories outside the allowed path list returns EACCES (Permission Denied) immediately at the VFS layer.
This granular control prevents compromised web workers or data parsers from reading sensitive configuration files such as /etc/passwd or SSH private keys.
Developers can apply different access rule masks to different sub-directories according to application least-privilege principles.
Restricting execute permissions prevents malicious code injection payloads from executing arbitrary shell scripts.
Implementing automated continuous monitoring across production nodes ensures that compliance policies remain enforced during infrastructure updates.
Regular security audits should be integrated into DevOps CI/CD pipelines to verify that system configurations conform to zero-trust architecture standards.
Documenting system architecture and access control rules facilitates compliance verification during independent third-party security audits.
Enforcing strict runtime isolation boundaries prevents privilege escalation vectors across multi-tenant cloud environments.
/* Construct Landlock Ruleset allowing read access to /tmp only */
struct landlock_ruleset_attr attr = {
.handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE |
LANDLOCK_ACCESS_FS_READ_DIR |
LANDLOCK_ACCESS_FS_WRITE_FILE,
};
int ruleset_fd = landlock_create_ruleset(&attr, sizeof(attr), 0);
struct landlock_path_beneath_attr path_attr = {
.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
.parent_fd = open("/tmp", O_PATH | O_CLOEXEC),
};
syscall(__NR_landlock_add_rule, ruleset_fd, LANDLOCK_RULE_PATH_BENEATH, &path_attr, 0);
3. Enforcing Self-Restriction & Drop Privileges
To activate the ruleset, the process must first set the PR_SET_NO_NEW_PRIVS prctl flag to prevent execution of setuid binaries that could bypass the sandbox.
Calling landlock_restrict_self() locks down the process environment permanently. The ruleset file descriptor can then be closed to prevent tampering.
Landlock restrictions persist across execve calls, ensuring that spawned subprocesses inherit the exact same sandbox boundaries.
Combining Landlock with Seccomp-BPF creates a multi-layered defense: Seccomp blocks dangerous system calls while Landlock restricts filesystem path access.
This multi-layered approach ensures robust isolation even when operating in unprivileged user environments.
Process isolation verified via Landlock ensures that container breakout attacks are contained at the filesystem boundary.
Implementing automated continuous monitoring across production nodes ensures that compliance policies remain enforced during infrastructure updates.
Regular security audits should be integrated into DevOps CI/CD pipelines to verify that system configurations conform to zero-trust architecture standards.
Documenting system architecture and access control rules facilitates compliance verification during independent third-party security audits.
Enforcing strict runtime isolation boundaries prevents privilege escalation vectors across multi-tenant cloud environments.
/* Enforce NO_NEW_PRIVS and lock down Landlock Sandbox */
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
syscall(__NR_landlock_restrict_self, ruleset_fd, 0);
close(ruleset_fd);
close(path_attr.parent_fd);
4. Verification & Audit Checklist
Verify kernel Landlock ABI version support prior to enforcing sandbox rules. Test application behavior using strace to confirm permission denials on unauthorized paths.
Audit process security state in production by checking audit logs for EACCES denials triggered by sandboxed applications.
Ensure application fallback mechanisms degrade gracefully when file access is restricted by Landlock policies.
Incorporate Landlock ABI version checks into startup scripts to handle kernel updates seamlessly.
Automated integration tests should verify that Landlock sandbox rules enforce default-deny behavior across all deployment environments.
Documenting sandbox policies ensures clear security compliance during third-party infrastructure audits.
Implementing automated continuous monitoring across production nodes ensures that compliance policies remain enforced during infrastructure updates.
Regular security audits should be integrated into DevOps CI/CD pipelines to verify that system configurations conform to zero-trust architecture standards.
Documenting system architecture and access control rules facilitates compliance verification during independent third-party security audits.
Enforcing strict runtime isolation boundaries prevents privilege escalation vectors across multi-tenant cloud environments.
# Check Landlock ABI version on current Linux kernel
cat /sys/kernel/security/landlock/status || dmesg | grep -i Landlock
# Audit process file access with strace
strace -e trace=file ./my_landlocked_app
Frequently Asked Questions (FAQ)
Does Landlock require root or CAP_SYS_ADMIN privileges?
No. Landlock is specifically engineered for unprivileged processes, requiring only PR_SET_NO_NEW_PRIVS.
How does Landlock compare to chroot?
chroot requires root privileges and is vulnerable to breakouts. Landlock is unprivileged, kernel-enforced, and restricts specific API permissions across arbitrary filesystem paths.
Utility Security Tools Related to this Article:
Gunakan CHMOD Permission Calculator dan Unix Epoch Converter untuk membantu alur kerja konfigurasi keamanan Anda secara privasi di browser.