Linux Security Modules

Also known as: LSM

On this page 7

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 categoryExample hooksWhat is mediated
File and inodefile_open, inode_permissionOpening, reading, writing and executing files
Task and credentialstask_kill, cred_prepareSignals, process creation and identity changes
Networksocket_bind, socket_connectSocket creation, binding and connections
Program executionbprm_check_securityLoading a new executable and label transitions
Kernel and systemkernel_module_request, locked_downModule loading and lockdown restrictions
BPF and keysbpf, key_permissioneBPF programs, maps and kernel keyrings
Representative LSM hook categories

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.

ModuleAccess control modelPolicy basisTypical use
SELinuxType enforcement, RBAC, MLSLabels on every objectRed Hat, Fedora, Android
AppArmorPath-based confinementPer-program profilesUbuntu, Debian, SUSE
SmackSimplified label comparisonShort text labelsEmbedded systems, Tizen
TOMOYOPath and domain historyLearned execution pathsAnalysis and appliances
YamaPtrace scope restrictionSysctl settingLimiting process debugging
LandlockUnprivileged sandboxingRules set by the processSelf-confining applications
LockdownKernel integrity restrictionIntegrity or confidentiality modeSecure Boot systems
Common modules built on the LSM framework

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.

SettingLocationEffect
`CONFIG_LSM`Kernel build configurationDefault ordered list of modules
`lsm=` parameterBoot loader command lineOverrides the default list at boot
`security=` parameterBoot loader command lineLegacy selection of one major module
Active list/sys/kernel/security/lsmShows modules currently initialized
Policy filesModule-specific pathsRules loaded after the kernel starts
Where the LSM configuration is controlled

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.

ControlQuestion it answersWho sets policy
DAC permissionsDoes the owner allow this accessFile owners
Linux capabilitiesDoes the process hold the privilegeAdministrators and binaries
SeccompIs this system call permittedThe application itself
LSM modulesDoes system policy allow this object accessCentral security policy
Namespaces and chrootWhat can the process seeContainer runtimes
LSM compared with related kernel controls

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.