Linux Security Modules (LSM) is the kernel framework of security hooks that allows pluggable access control modules, such as SELinux and AppArmor, to approve or deny sensitive operations inside the Linux kernel. In Linux security, LSM is the layer that turns the traditional owner, group and permission bits into an extensible system where mandatory access control policies can be added without patching the kernel for each new model.
The framework was merged into the Linux 2.6 kernel series after a 2001 discussion in which kernel maintainers declined to adopt any single security model directly. Instead of choosing one policy, the kernel offers a common interface of hooks, and each module decides how to answer them. LSM itself enforces nothing; it only provides the points where enforcement can happen.
How LSM hooks mediate kernel operations
LSM works by placing hook calls at critical decision points in the kernel, immediately before an object is accessed. When a process opens a file, sends a signal, binds a socket or loads a kernel module, the kernel first performs its usual discretionary access control (DAC) checks and then calls the registered LSM hooks. If any active module returns an error, typically -EACCES or -EPERM, the operation fails.
Hooks fall into two broad groups. Authorization hooks ask whether an action is allowed, for example file_open or socket_connect. Security blob management hooks allocate and free per-object security data, such as the label attached to an inode, a task credential or an IPC object. Modules store their own context in these security blobs, which is how SELinux attaches a security context to every file and process.
The design is restrictive only: an LSM hook can deny an action that DAC would allow, but it cannot grant an action that DAC already refused. This property, sometimes called additive restriction, keeps the framework simple to reason about and prevents a faulty module from silently widening privileges. The main exception is the capability check path, where the capabilities module itself is implemented through LSM hooks.
The following table lists representative hook categories and what they control.
| Hook category | Example hooks | What is mediated |
|---|---|---|
| File and inode | file_open, inode_permission | Opening, reading, writing and executing files |
| Task and credentials | task_kill, cred_prepare | Signals, process creation and identity changes |
| Network | socket_bind, socket_connect | Socket creation, binding and connections |
| Program execution | bprm_check_security | Loading a new executable and label transitions |
| Kernel and system | kernel_module_request, locked_down | Module loading and lockdown restrictions |
| BPF and keys | bpf, key_permission | eBPF programs, maps and kernel keyrings |
Major and minor LSM modules
Modules are usually divided into major (exclusive) modules and minor (stackable) modules. Historically only one major module could be active, because each needed exclusive use of the security blobs. Minor modules keep little or no per-object state, so they could always run alongside a major module.
The table below compares the best-known modules shipped in the mainline kernel.
| Module | Access control model | Policy basis | Typical use |
|---|---|---|---|
| SELinux | Type enforcement, RBAC, MLS | Labels on every object | Red Hat, Fedora, Android |
| AppArmor | Path-based confinement | Per-program profiles | Ubuntu, Debian, SUSE |
| Smack | Simplified label comparison | Short text labels | Embedded systems, Tizen |
| TOMOYO | Path and domain history | Learned execution paths | Analysis and appliances |
| Yama | Ptrace scope restriction | Sysctl setting | Limiting process debugging |
| Landlock | Unprivileged sandboxing | Rules set by the process | Self-confining applications |
| Lockdown | Kernel integrity restriction | Integrity or confidentiality mode | Secure Boot systems |
Landlock is notable because it lets an unprivileged process restrict itself, much like Seccomp filters system calls, while Lockdown implements the separate concept of kernel lockdown. The BPF LSM, introduced in kernel 5.7, allows administrators to attach eBPF programs to LSM hooks, so custom policies can be written and loaded at runtime.
LSM stacking and boot configuration
LSM stacking is the ability to run several modules at the same time, with every hook consulted in order. Since kernel 5.1, the kernel manages blob allocation centrally, so minor modules stack freely and work continues on full stacking of major modules, for example running AppArmor inside a container on an SELinux host.
The active set is chosen by the `CONFIG_LSM` build option and can be overridden with the `lsm=` kernel parameter at boot. The current list is visible in /sys/kernel/security/lsm, and the order matters because the first denial ends the check. The table shows the main configuration points.
| Setting | Location | Effect |
|---|---|---|
| `CONFIG_LSM` | Kernel build configuration | Default ordered list of modules |
| `lsm=` parameter | Boot loader command line | Overrides the default list at boot |
| `security=` parameter | Boot loader command line | Legacy selection of one major module |
| Active list | /sys/kernel/security/lsm | Shows modules currently initialized |
| Policy files | Module-specific paths | Rules loaded after the kernel starts |
LSM modules are compiled into the kernel rather than loaded as ordinary loadable modules. This restriction exists because a security module must be active before the first user process starts; otherwise early objects would carry no labels and policy could be bypassed.
How LSM relates to other Linux security controls
LSM complements, rather than replaces, the other access controls in the kernel. Each control answers a different question, and defense in depth comes from combining them.
| Control | Question it answers | Who sets policy |
|---|---|---|
| DAC permissions | Does the owner allow this access | File owners |
| Linux capabilities | Does the process hold the privilege | Administrators and binaries |
| Seccomp | Is this system call permitted | The application itself |
| LSM modules | Does system policy allow this object access | Central security policy |
| Namespaces and chroot | What can the process see | Container runtimes |
A key difference is the scope of decisions. Seccomp filters system call numbers and arguments, but it cannot inspect the object behind a file descriptor. An LSM hook runs with full kernel context, after path resolution, so it knows exactly which inode, socket or process is involved. This makes LSM resistant to the time-of-check to time-of-use (TOCTOU) problems that affected earlier system call interposition tools.
Limitations and common misconceptions
LSM is powerful, but several limits are often misunderstood by administrators who encounter it for the first time.
- LSM is not a module itself. Saying a system runs LSM means only that the framework is present; protection depends on which modules are enabled and how strict their policies are.
- A permissive or complain mode logs but does not block. SELinux permissive mode and AppArmor complain mode are useful for tuning, yet they provide no enforcement.
- Kernel bugs bypass every hook. An attacker with arbitrary kernel code execution can disable modules, so LSM protects against user space compromise, not kernel compromise.
- Hooks add measurable overhead. The cost is usually a low single-digit percentage for typical workloads, but heavy file or network activity with complex policies can cost more.
- Disabling a module to fix an error is a common mistake. Turning off SELinux or AppArmor removes confinement for every service; adjusting the specific policy rule is the correct fix.
In simple terms
Think of the Linux kernel as a large building where every door already has a basic lock. Linux Security Modules adds a set of checkpoints at those doors. The checkpoints themselves do not decide anything; they simply ask a guard whether the visitor may pass.
The guard is a security module such as SELinux or AppArmor, and each guard follows its own rulebook. A guard can stop someone the basic lock would allow, but it can never let in someone the lock already refused. The key idea is flexibility: the building can switch guards or employ several of them without rebuilding the doors.
A practical example
A hosting company runs a public web server on Ubuntu with AppArmor enabled in enforce mode. The Nginx profile allows the server to read its content directory and write to its log files, and nothing else. An attacker exploits a vulnerable PHP plugin and tries to read /etc/shadow and download a tool into /tmp for execution.
The traditional permission checks do not stop everything, because the compromised process runs as a user that can write to /tmp. However, the LSM hooks file_open and bprm_check_security ask AppArmor, which denies both operations because neither path appears in the profile. The kernel logs the denials, the monitoring system raises an alert, and the operator patches the plugin. The breach stays contained to one process instead of spreading across the server.