How Linux Capabilities and the LSM Framework Work: Fine-Grained Privilege, Hook Points, and Why Root Is No Longer All-or-Nothing

A process that needs to bind a low-numbered TCP port, or to change the system clock, does not need the power to rewrite arbitrary files, kill arbitrary processes, or load kernel modules. Traditional Unix privilege treats effective UID 0 as a single switch: either the process is root and almost every check is bypassed, or it is not. Compromising a set-UID-root binary therefore hands the attacker the entire switch.

Linux capabilities split that switch into independent bits. The Linux Security Module (LSM) framework then places hooks at kernel decision points so that additional policy (SELinux, AppArmor, etc.) can further restrict or label operations even when a capability is present. This article explains both mechanisms: the capability sets that travel with a thread, how they transform on execve, file capabilities as a replacement for set-UID-root, and the hook architecture that LSMs register against.

It is not a second tour of privilege rings, of namespace isolation, or of specific speculative-execution attacks. Those describe the CPU mode transition, name filtering, and side-channel leakage. Capabilities describe which privileged operations the kernel will still permit after the transition. Related reading: How System Calls Work, How Linux Namespaces and cgroups Work.

The contract

Each thread carries several capability sets, each a bitmask. The kernel consults the effective set when it decides whether a privileged operation is allowed. The permitted set is the upper bound of what the thread may place into its effective set. The inheritable set participates in calculating the sets of a newly exec'd program. The bounding set (per-thread since 2.6.25) limits what file capabilities can grant. The ambient set (since 4.3) preserves selected capabilities across an exec of a non-privileged binary, provided the capability is also permitted and inheritable.

A capability is not an object capability. The process still names resources through global namespaces (files, PIDs, network endpoints). Capabilities only answer the narrower question: may this thread perform this privileged action? LSMs answer a broader question by attaching labels or path-based rules and consulting them at the same decision points.

Capability sets and the execve transition

On execve the kernel computes the new sets from the old process sets, the file capability sets stored on the executable, the file's effective flag, and the bounding set. Roughly:

  • New permitted = (old inheritable & file inheritable) | (file permitted & bounding)
  • New effective = new permitted if the file effective flag is set, otherwise empty (unless ambient contributes)
  • Ambient is cleared if the file is privileged; otherwise it is preserved subject to the invariant that ambient ⊆ permitted ∩ inheritable

Dropping a capability from the permitted set is permanent for that thread lineage unless a later set-UID-root exec re-grants it. The bounding set can be irreversibly reduced with prctl, giving a lasting ceiling even for programs that carry file capabilities. Ambient capabilities let an unprivileged parent hand a narrow privilege to a non-privileged child without making the child set-UID or attaching file capabilities that any user could invoke.

File capabilities replace set-UID-root

An executable can carry permitted, inheritable, and effective capability sets in its extended attributes. When the kernel execs it, those sets are combined with the caller's sets as above. A binary that only needs CAP_NET_BIND_SERVICE can receive exactly that bit; a compromise yields only the ability to bind low ports, not the rest of root. setcap and getcap manage the attributes. The bounding set and LSM policy still apply, so the grant is not absolute.

Where the LSM framework sits

The LSM framework (present since 2.6) inserts hooks throughout the kernel: file open, inode permission, socket create/connect, task credentials, capability checks, and many others. A security module registers a list of hook functions. When the kernel reaches a hook point it calls every registered module; access is allowed only if every module returns success. Capabilities themselves are implemented as the first LSM (always present). Major modules (SELinux, AppArmor, Smack, TOMOYO) implement full mandatory access control and are mutually exclusive; minor modules (Yama, Lockdown, etc.) can stack.

Hooks run after ordinary discretionary checks in many paths, giving LSMs a veto. Each module may store its own security blob on kernel objects (task, inode, file, socket). SELinux uses type enforcement and role-based rules on labels; AppArmor uses path-based profiles. Both consult the same hook points. The active list is visible in /sys/kernel/security/lsm; the capability module is always first.

Misconceptions

A process with every capability is not identical to traditional root in every respect: some historical checks still look at UID 0, and LSM policy can still deny. Capabilities do not isolate namespaces; a process with CAP_SYS_ADMIN inside a user namespace is still limited by the namespace boundaries. Ambient capabilities are not a free pass: they must already be permitted and inheritable, and they disappear on a privileged exec. LSM stacking does not mean every module is equally powerful; major modules remain exclusive.

Takeaways

Linux capabilities turn the single root switch into a set of independent bits carried by each thread and by executable files. The permitted/effective/inheritable/bounding/ambient sets, together with the execve calculation, let a program receive only the privileges it needs. The LSM framework places additional hooks at the same decision points so that label- or path-based policy can further constrain operations. Together they replace the all-or-nothing model without requiring a second kernel or a hypervisor. Container runtimes routinely drop most capabilities and apply an LSM profile for exactly this reason.

Related: namespaces filter names; capabilities filter privileged operations; LSM hooks add policy on top of both.

Next Post Previous Post