Skip to main content
  1. Index/

LSM (Linux Security Module)

Linux Security Modules (LSM) is a hook-based framework integrated into the Linux kernel since 2.6 (2003) that provides a general mechanism for implementing Mandatory Access Control (MAC) without modifying the core kernel. Its origin is the NSA’s presentation of SELinux at the 2001 Linux Kernel Summit: Linus Torvalds accepted the need for flexible access control but refused to hardcode a single security model, directing instead the development of a framework into which any security model could be plugged. The result is LSM: a set of strategically placed hook functions throughout the kernel’s execution paths — over 240 hooks in recent kernels — at points where security-relevant decisions occur: file open, process creation, capability checks, socket operations, IPC access, memory mapping, and more. Each hook is a call into the currently active security module(s), which examine the operation’s context and return allow or deny. The core kernel enforces whatever the security module decides.

LSM separates modules into two categories. Major LSMs implement a full MAC policy and have exclusive access to the kernel’s per-object security blobs — the opaque storage attached to inodes, tasks, credentials, and sockets where the security module stores its labels and policy state. Only one major LSM can be the primary module at boot (selected via the security= kernel parameter or compile-time default), though the stacking architecture introduced in kernel 4.x allows multiple major modules to coexist under specific conditions. The accepted major modules in the upstream kernel are SELinux, AppArmor, Smack, and TOMOYO. Minor LSMs implement narrower, non-policy security features and stack freely: Yama (restricts ptrace scope), Lockdown (controls kernel integrity under Secure Boot), LoadPin (restricts the origins from which the kernel loads modules and firmware), and SafeSetID (constrains setuid/setgid transitions). BPF LSM (kernel 5.7) is a stackable minor module that allows eBPF programs to attach to LSM hooks at runtime, implementing custom access control logic without loading a kernel module or configuring a major LSM — enabling programmatic, per-workload policy without the compile-time commitment to SELinux or AppArmor. LSM hooks are always evaluated after standard Linux Discretionary Access Control (DAC) — file permission bits and ACLs — so an LSM module can only further restrict what DAC has already permitted; it cannot grant access that DAC denies.

From an operational perspective, LSM is the reason that SELinux and AppArmor are mutually exclusive on a given system without kernel recompilation — both are major LSMs competing for the same hook slot. Distribution defaults encode this choice: RHEL, Fedora, and CentOS use SELinux; Ubuntu and Debian use AppArmor. Container runtimes interact with LSM directly: containerd and CRI-O apply AppArmor profiles and SELinux labels to containers via the OCI runtime spec’s linux.appArmorProfile and linux.seccomp fields, and the PSA Restricted profile mandates that a seccomp profile is set, which in turn passes through the kernel’s seccomp(2) syscall — a separate mechanism from LSM hooks but complementary to them. In confidential computing environments, LSM policies on the host remain relevant for KubeVirt and Kata Containers workloads: the host’s LSM confines the QEMU/virt-launcher process itself, providing a containment layer outside the VM boundary that bounds the damage from a QEMU vulnerability.

Related

AppArmor (Application Armor)

AppArmor (Application Armor) is a Mandatory Access Control (MAC) system implemented as a major LSM (Linux Security Module), developed originally by Immunix and now maintained by Canonical. It is the default MAC system on Ubuntu, Debian, and their derivatives, and the default container confinement mechanism for containerd and Docker on those distributions. Where SELinux assigns security labels to every object on the system and enforces policy based on label interactions, AppArmor takes a fundamentally different approach: it confines programs by filesystem path. A profile for nginx lists the specific file paths that nginx is allowed to read, write, and execute, the network operations it may perform, and the Linux capabilities it may use — anything not listed is denied. No relabelling of the filesystem is required and no extended attributes are set: AppArmor’s confinement decisions are made purely from the path of the file being accessed and the identity of the confined process. This path-based model makes AppArmor profiles far simpler to read, write, and audit than SELinux policy, and eliminates the mislabelled-file failure mode that is the most common SELinux operational problem.

SELinux (Security-Enhanced Linux)

SELinux (Security-Enhanced Linux) is a Mandatory Access Control (MAC) implementation developed by the NSA and released as open source in 2000, merged into the mainline Linux kernel in 2.6 via the LSM framework in 2003. Its defining characteristic is default deny: unlike the standard Linux Discretionary Access Control model (file permission bits), where anything not explicitly forbidden is permitted, SELinux refuses all access that is not explicitly allowed by policy. Every process and every object — every file, socket, pipe, device node, and IPC object — carries a security context (also called a label) of the form user:role:type:level. The policy is a compiled set of rules, loaded at boot, that defines precisely which combinations of process context and object context may interact and how. An Apache web server process running in the httpd_t domain can read files labelled httpd_sys_content_t but is denied access to files labelled user_home_t or shadow_t, regardless of what Unix file permission bits say. If the web server is compromised, the attacker is confined to what httpd_t permits — typically a narrow, well-defined set of files and network operations — rather than having the full access of the user account running Apache.

IMA (Integrity Measurement Architecture)

IMA (Integrity Measurement Architecture) is a Linux kernel subsystem, merged in kernel 2.6.30, that hooks into the kernel’s file access paths — execve(), mmap(), open() — and computes a cryptographic hash of each file’s contents before it is accessed, according to a configurable policy. It is the runtime half of the Linux integrity story: where TPM PCR measurements and Secure Boot cover what was loaded during the boot sequence, IMA covers what happens after the OS is running, hashing executables, libraries, kernel modules, firmware, and configuration files as they are opened, creating a continuously updated record of everything the system has actually used.