Inferensys

Glossary

Linux Security Modules (LSM)

Linux Security Modules (LSM) is a framework in the Linux kernel that allows security models like SELinux and AppArmor to be implemented as loadable modules to enforce mandatory access control (MAC) policies.
Governance lead reviewing model governance framework on laptop, policy documents visible, executive office setup.
SECURE ENCLAVE EXECUTION

What is Linux Security Modules (LSM)?

A technical definition of the Linux kernel framework for implementing mandatory access control (MAC) security policies.

Linux Security Modules (LSM) is a framework in the Linux kernel that provides a set of hooks to support the implementation of mandatory access control (MAC) security models as loadable kernel modules. It allows security policies like SELinux, AppArmor, and Smack to be integrated into the kernel to enforce fine-grained, system-wide rules on object access and process operations, extending beyond traditional discretionary access control (DAC). The framework acts as a mediator, enabling these modules to authorize or deny security-sensitive operations.

In the context of secure enclave execution for AI agents, LSM is a critical sandboxing mechanism. It can confine tool-calling processes by restricting their filesystem access, network capabilities, and system calls, enforcing the principle of least privilege. This isolation mitigates risks if an agent is compromised, preventing lateral movement. While distinct from hardware-based Trusted Execution Environments (TEEs) like Intel SGX, LSM operates at the OS level to provide a robust, configurable layer of mandatory security policy enforcement for containerized and native workloads.

LINUX SECURITY MODULES

Core Architectural Features of LSM

The Linux Security Modules (LSM) framework provides a standardized, modular architecture for implementing mandatory access control (MAC) security policies directly within the Linux kernel.

01

Hook-Based Architecture

LSM implements security by inserting hooks at critical points in the kernel where a user-space object (file, task, socket) is about to be accessed. Before the kernel proceeds with the operation, it calls the LSM framework, which passes the request to the loaded security module (e.g., SELinux, AppArmor) for a policy decision.

  • Example Hooks: file_open, inode_permission, task_kill, socket_bind.
  • The module evaluates the request against its internal policy and returns an allow or deny decision.
  • This design centralizes security logic without scattering checks throughout the kernel source code.
02

Module Stacking (Since Linux 5.1)

Historically, only one LSM could be active at boot time. Modern kernels support LSM stacking, allowing multiple security modules to be loaded simultaneously. Hooks are processed in a defined order, with each module getting a chance to make a decision.

  • Key Use Case: Combining a comprehensive MAC system like SELinux with a simpler, path-based module like AppArmor for specific applications.
  • The final decision is a logical AND; all modules must allow the action for it to proceed.
  • This enables defense-in-depth by layering distinct security models.
03

Blob Management

LSM modules often need to store security state (labels, contexts) associated with kernel objects like tasks, inodes, and files. The framework provides opaque security blobs—pointers to module-specific data structures—attached to these kernel objects.

  • The kernel allocates and manages the pointer storage, but the module manages the actual data.
  • Example: SELinux stores a security context (e.g., user_u:role_r:type_t) in the inode's security blob.
  • This mechanism isolates module data, preventing interference between stacked modules.
04

Capabilities Integration

LSM hooks integrate with and extend the traditional Linux Capabilities model. While capabilities are a form of discretionary access control (DAC) granting privileges to processes, LSM modules can make finer-grained decisions.

  • A hook can override a capability check. For instance, a process might have the CAP_NET_BIND_SERVICE capability, but SELinux policy could still deny a specific socket_bind operation.
  • This allows policies to enforce rules that are more specific than broad privilege flags.
05

Network Security Hooks

Beyond files and processes, LSM provides hooks for regulating network operations. This allows security modules to implement policies for sockets, packets, and network interfaces.

  • Socket Hooks: Control creation (socket_create), binding (socket_bind), and connecting (socket_connect) based on security context.
  • Packet Hooks: Authorize transmission/reception of individual packets (socket_sendmsg, socket_recvmsg).
  • Netfilter Integration: Modules like SELinux can label packets via secmark for consistent policy enforcement across the network stack.
06

Userspace Object Labeling

A core function of LSM modules is to assign and manage security labels on all system objects. These persistent labels are the basis for access decisions.

  • Filesystem Labeling: Labels are stored in extended attributes (e.g., security.selinux) on supported filesystems.
  • Dynamic Translation: Modules provide rules to assign initial labels to new objects (e.g., a process inherits its parent's label, a new file gets its creating process's label).
  • Tools: Userspace utilities (e.g., chcon, aa-status) allow administrators to query and modify these labels according to policy.
KERNEL SECURITY

How the LSM Framework Works

The Linux Security Modules (LSM) framework is a kernel-level architecture that provides hooks for implementing mandatory access control (MAC) security policies.

The Linux Security Modules (LSM) framework is a lightweight, general-purpose hook-based architecture integrated into the Linux kernel. It places security decision points at critical kernel operations—such as file access, task creation, and socket binding—allowing a loaded security module to intercept these calls and enforce policy. This design enables mandatory access control (MAC) systems like SELinux and AppArmor to be implemented as kernel modules without requiring extensive kernel patches, providing a standardized interface for security extensions.

When a system call triggers a protected operation, the kernel executes the relevant LSM hook, which calls the currently active security module's callback function. The module evaluates the request against its internal policy—checking labels, contexts, or rules—and returns a decision to allow or deny the action. Only one MAC module can be active at a time, ensuring deterministic policy enforcement. The framework's core provides only the hook infrastructure; all security logic and policy management are delegated to the loadable module, separating mechanism from policy.

LINUX SECURITY MODULES (LSM)

Frequently Asked Questions

Linux Security Modules (LSM) is a kernel framework that enables mandatory access control (MAC) for the Linux operating system. These FAQs address its core mechanisms, use cases, and relationship to secure enclave execution for AI agents.

Linux Security Modules (LSM) is a framework in the Linux kernel that provides hooks for implementing mandatory access control (MAC) security models. It works by inserting security hooks at critical points in the kernel—such as file operations, task creation, and network socket actions—allowing a loaded security module to make authorization decisions before an operation proceeds. Unlike traditional Discretionary Access Control (DAC), which relies on user/group ownership, LSM enables system-wide policies that enforce rules regardless of user discretion. The framework itself is policy-agnostic; the enforcement logic is defined by the loaded module, such as SELinux, AppArmor, or Smack. When a system call triggers a hooked operation, the kernel queries the active LSM, which can allow or deny the action based on its security policy.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.