What it is
Linux Security Modules (LSM) is a framework inside the Linux kernel that lets a security module, a separately written part of the kernel, decide whether the kernel may perform an operation on one of its internal objects, such as a file, a process or a network packet. The kernel calls the module through hooks, calls placed just before such operations, and gives objects opaque security fields that the module manages. Chris Wright, Crispin Cowan, Stephen Smalley, James Morris and Greg Kroah-Hartman described it in 2002.
Basis of this account
This account rests on the paper “Linux Security Modules: General Security Support for the Linux Kernel”, in the proceedings of the 11th USENIX Security Symposium, San Francisco, 5 to 9 August 2002, in the copy that USENIX, the Advanced Computing Systems Association, hosts (https://www.usenix.org/legacy/event/sec02/full_papers/wright/wright.pdf). The abstract and Sections 1 to 3 were read in full, Sections 4 and 5 in part, and Sections 6 to 8 not at all. The kernel’s own overview, “Linux Security Modules: General Security Hooks for Linux” by Stephen Smalley, Timothy Fraser and Chris Vance (https://docs.kernel.org/security/lsm.html), was read in full; that page warns that the interfaces it describes are outdated. The companion studies of hook placement that the paper cites were not read. Nothing was run.
What the paper claims
The authors make these claims.
The problem. Mainstream operating systems offer only discretionary access control §1.7 (DAC), in which the owner of an object decides who may use it. Stronger access control had not entered them, partly because the security community did not agree on one model. A framework that lets many models be added as modules avoids choosing one.
Origin. At the Linux 2.5 Kernel Summit, the NSA (National Security Agency of the United States) presented SELinux (Security-Enhanced Linux). Linus Torvalds, who leads Linux development, favored a general framework over adopting one project, and specified that it must be truly generic, conceptually simple, minimally invasive and efficient, and able to carry the existing POSIX.1e capabilities as an optional module. These capabilities split the unlimited rights of the superuser, the administrator account, into separate privileges; they come from a draft standard of the POSIX (Portable Operating System Interface) family. LSM was the response.
Hooks at kernel objects, not at system calls. A check at the system-call interface, the entry points through which programs ask the kernel for service, is not free of races, may duplicate kernel code, and may lack the context that a decision needs. LSM hooks sit inside the kernel just before it accesses an internal object, after the kernel has translated the names and handles that the user supplied into its own data structures. The authors state that this avoids time-of-check to time-of-use §9.26 (TOCTTOU) races and duplicate lookups.
Restrictive hooks. Most hooks can only deny an access that the kernel was about to allow; when the kernel itself denies, the module is not consulted. A few permissive hooks, tied to the kernel’s capability checks, let a module grant an access that DAC would deny. That is enough to move the POSIX.1e capability logic into a module.
Adoption. Existing projects, among them POSIX.1e capabilities, SELinux and DTE (Domain and Type Enforcement), had been adapted to LSM.
Low cost. On Linux 2.5.15 with the capabilities module, the worst microbenchmark overhead was 5.1%, for the
select()call, and building the kernel took at most 0.3% longer.
How it works
The framework has four parts.
Hooks. A hook is a call, placed in kernel code, to a function that the active module supplies. The question each access-control hook answers is, in the paper’s terms, whether a subject may perform a kernel operation on an internal kernel object; the subject is normally the process making the request. The module lets the access happen or denies it, and a denial becomes an error code returned to the program. The paper groups the hooks by object: processes, program loading §12.49, file systems, inodes (the kernel’s record of a file), open files, objects for interprocess communication §19.5.5, network packets and devices, kernel modules, and system operations such as setting the host name.
Opaque security fields. LSM adds a pointer of the C type
void*, which may point to data of any type, to kernel data structures such astask_struct(a process),inode,file,super_block(a mounted file system) andsk_buff(a network packet). The module decides what each pointer leads to, typically the object’s security label, the attributes that its policy uses to decide. Hooks called when an object is allocated and freed let the module create and destroy that data, and further hooks keep it current, for example after a file name has been looked up. LSM provides no locking for these fields; the module must provide it.Registration. At boot every hook leads to a default function. A module registers its table of hook functions, and from then on the kernel calls the module.
Stacking, the use of several modules at once. The authors note that fully general composition of security policies is known to be intractable, so the LSM of 2002 leaves stacking to the modules. The first module loaded has full control and may call a second module and combine the results.
The paper’s example is vfs_mkdir, the kernel function that creates a directory. After the kernel’s own permission checks, a call to the module’s mkdir hook asks whether the process may create this directory in this parent directory; an error stops the operation. After the directory exists, a post_mkdir hook lets the module set the security field of the new directory’s inode. The kernel’s overview records that LSM entered the mainstream kernel in December 2003. Its description of the present arrangement differs from the paper: each hook keeps a list of module functions, called in the order set by the configuration option CONFIG_LSM, so several modules can be active together, which the overview calls a close approximation of general module stacking.
A hook framework raises the question whether its hooks are enough. Call an operation security-sensitive if a policy may need to control it, such as reading a file’s data, sending a signal to a process or loading a kernel module. The hook set mediates completely, in the sense of the principle of complete mediation §1.16, when every execution path that performs a security-sensitive operation passes first through a hook that authorizes that same operation, for the same subject, on the object that is then used. The LSM authors state that they tested LSM kernels by booting and running them and did not test systematically. They cite companion work by Antony Edwards, Trent Jaeger and Xiaolan Zhang at the IBM (International Business Machines) T. J. Watson Research Center on verifying hook placement, including a static analysis §3.1 with CQUAL, a tool that checks type qualifiers, extra labels attached to the types of a C program.
The general method for showing that a hook set is adequate has four steps.
List the security-sensitive operations: the accesses to protected objects that a policy may need to control.
For each operation, find every path that reaches it in the control-flow graph §3.13, the graph whose nodes are program steps and whose edges are the possible transfers of control between them.
Show that a hook authorizing that operation dominates it: every path from the program’s entry to the operation passes through the hook.
Show that the hook checks the right things and that its answer is still valid at the use: the object that is then used, with no second lookup by name in between; the requesting subject; a permission that covers the operation, since a read check does not cover a write; and no other thread able to change the object or its label before the use.
Static analysis, which reasons about the source code without running it, can cover all paths of the model it builds. Tests and runtime tracing cover only the paths that run, but catch places where the model is wrong.
Worked example
This example is invented, although each route it lists exists in Linux. A module must stop process P from reading the contents of the file /secret. Suppose it implements only the hook that runs when a file is opened. Count the routes by which P can read the contents.
P opens
/secretand reads it. The open hook runs: covered.P opens the same file through a hard link §13.10, a second name for the same file. The hook still runs, because LSM checks the inode, not the name: covered. A check on the path string
/secretat the system-call interface would miss this route.Another process that was allowed to open
/secretsends P its open file descriptor §15.21 over a local socket, a communication channel between processes on one machine. P opens nothing: not covered.P opened
/secretbefore the policy changed and keeps reading through the same descriptor. The open check ran under the old policy: not covered.
The open hook alone covers 2 of the 4 routes. LSM’s hook set has the pieces for the other 2: a hook that controls the receipt of open file descriptors over socket communication covers route 3, and file hooks on read and write, which the paper says let a module revalidate permission on use to support dynamic policy changes, cover route 4. With them, 4 of 4 routes are covered.
One more route shows the limit of checks on use. If P maps an open file into its memory with mmap, later reads are ordinary memory loads that no hook sees. The only possible check is when the mapping is made, and withdrawing access afterwards means removing the mapping.
What this account does not establish
The paper does not claim that its hooks mediate every security-sensitive operation. Its authors tested LSM kernels only by booting and running them, and point to companion work for verification. Complete mediation by a hook set has to be shown; the framework does not provide it.
Most hooks are restrictive. Apart from the few permissive capability hooks, a module can tighten the kernel’s discretionary access control but cannot grant what DAC denies, and it is not consulted when the kernel denies.
Placing hooks after name resolution removes races between a check and the kernel’s own lookup, but not every race. A module that reads its own security data without locking can decide on a label while another thread changes it, and kernel code that looks an object up again after the hook can check one object and use another.
The measurements were made in 2002 on Linux 2.5.15, and the interface has changed since. The kernel’s overview, which itself warns that its interfaces are outdated, is the only source here for the present arrangement; this account does not describe the current list of hooks.
Questions answered
What makes a hook set adequate?
A hook set is adequate when it mediates completely: every execution path that performs a security-sensitive operation, meaning an operation that the policy may need to control, first passes through a hook that authorizes exactly that operation, for the subject that requests it, on the object that is then used, and nothing can change the object or the policy’s answer between the check and the use. Four conditions follow.
Every path. Alternative routes to the same effect, such as reading a file through a descriptor received from another process or through a memory mapping, each need a check. A correct check on one convenient path does not govern a path that never calls it.
The right arguments. The hook sees the actual kernel object after the kernel has resolved names and handles, so the object checked is the object used, and it sees enough context to decide.
No gap in time. No window lets another thread, or a policy change, make the earlier decision wrong; where access continues over time, as with an open file, the hook checks again on each use.
Lifecycle hooks. Objects receive their security labels when created and release them when freed, so every check has a label to work with.
Adequacy is shown, not assumed. List the security-sensitive operations; show with static analysis over the control-flow graph that a matching hook precedes each one on every path; and use tests and runtime tracing to catch places where the analysis models the code wrongly. The Linux Security Modules paper (Wright and colleagues, 2002) placed its hooks just before kernel objects are accessed for the reasons in the second condition, and left systematic verification of its hook set to companion work.
Related entries: Probe and hook (§14.26), Reference monitor (§1.17), Complete mediation (§1.16), Authorization (§1.7), Time-of-check to time-of-use (TOCTOU) (§9.26), Static analysis (§3.1), Control-flow graph (CFG) (§3.13), Flask: separating security policy from enforcement mechanisms (§21.12). Further reading: [217, 218].