SELinux
SELinux ( Security-Enhanced Linux — Linux with enhanced security) is an implementation of a mandatory access control system that can work in parallel with the classic discretionary access control system.
Description
Remaining within the discretionary access control system, an operating system has a fundamental limitation in terms of separating process access to resources — access to resources is based on the user's access rights.
These are the classic rwx rights at three levels — owner, owning group and others.
In SELinux access rights are defined by the system itself using specially defined policies.
Policies work at the level of system calls and are applied by the kernel itself (but they can also be implemented at the application level).
SELinux acts after the classic Linux security model. In other words, SELinux cannot allow what is forbidden through the access rights of users or groups. Policies are described using a special flexible language for describing access rules.
In most cases SELinux rules are «transparent» for applications, and no modification of them is required. Some distributions include ready-made policies in which rights can be determined on the basis of matching the types of a process (subject) and a file (object) — this is the main mechanism of SELinux.
Two other forms of access control — role-based access and multi-level security based access. For example, «for official use», «secret», «top secret», «special importance».
The simplest type of policy to work with and to support is the so-called «targeted» policy, developed within the Fedora project.
The policy describes more than 200 processes that can run in the operating system. Everything that is not described by the «targeted» policy runs in the domain (with the type) unconfined_t. Processes running in this domain are not protected by SELinux.
Thus, all third-party user applications will work without any problems in a system with the «targeted» policy within the classic permissions of the discretionary access control system.
Besides the «targeted» policy, some distributions include a policy with a multi-level security model (with support for the Bell — LaPadula model).
The third policy option is «strict». Here the principle «what is not allowed is forbidden» applies (the principle of least privilege). The policy is based on the Reference Policy from the Tresys company.
SELinux was developed by the US National Security Agency, and then its source code was made available for download.
Original text
From NSA Security-enhanced Linux Team:
«NSA Security-enhanced Linux is a set of patches to the Linux kernel and some utilities to incorporate a strong, flexible mandatory access control (MAC) architecture into the major subsystems of the kernel.
It provides a mechanism to enforce the separation of information based on confidentiality and integrity requirements, which allows threats of tampering and bypassing of application security mechanisms to be addressed and enables the confinement of damage that can be caused by malicious or flawed applications.
It includes a set of sample security policy configuration files designed to meet common, general-purpose security goals.»
SELinux is included in the Linux kernel (since version 2.6).
Also, the functioning of SELinux requires modified versions of some utilities (ps, ls and others) that provide support for the new kernel functions, and support from the file system.
Basic concepts
- Domain — is a certain set of actions that a single process can perform. Mainly these are the actions a process needs to perform a specific task.
- Role — is a collection of several domains.
- Security context — is the set of all attributes that are associated with objects and subjects.
- Security policy — is a set of defined rules that regulates the interaction of roles and domains.
LSM overview
LSM ( Linux Security Modules) are an implementation in the form of loadable kernel modules. First of all, LSM are used to support access control.
By themselves, LSM do not provide the system with any additional security, but are merely a kind of interface for supporting it.
The LSM system provides the implementation of interceptor functions that are stored in the security policy structure covering the main operations whose protection must be ensured. Access control in the system is carried out thanks to the configured policies.
Access control methods
Most operating systems have means and methods of access control, which in turn determine whether a certain object at the operating system level (a user or a program) can gain access to a certain resource. The following access control methods are used:
- Discretionary access control (English: Discretionary Access Control, DAC). This method implements restriction of access to objects on the basis of the groups they belong to. In Linux, this method is based on the standard file access control model. Access rights are defined for the following categories: user (the file owner), group (all users who are members of the group), others (all users who are neither the file owners nor members of the group). Moreover, each of the categories is granted the following rights: write, read and execute permissions.
- Mandatory access control (English: Mandatory Access Control, MAC). Mainly, the essence of this method is to establish certain access rights of a subject to certain objects. In the OS this is implemented as follows: a program has only the capabilities it needs to perform its tasks, and nothing more. This method has an advantage over the previous one; if a vulnerability is found in a program, its access capabilities will be very limited.
- Role-based access control (English: Role-Based Access Control, RBAC). Access rights are implemented in the form of roles issued by the security system. Roles represent certain authority to perform specific actions by a group of subjects on objects in the system. This policy is an improvement on discretionary access control.
Internal architecture of SELinux
At the very beginning of its appearance, SELinux was implemented as a patch. In this case it was not easy to configure the security policy. With the advent of LSM mechanisms, the configuration and management of security became much simpler (the policy and the security enforcement mechanisms were separated), and SELinux was implemented as loadable kernel modules.
Before access to the internal objects of the operating system, the kernel code is modified. This is implemented using special functions (system call interceptors), the so-called «hook» functions (English: hook functions). The interceptor functions are stored in a certain data structure; their purpose is to perform specific security actions based on a predefined policy. The module itself includes six main components: the security server; the access vector cache (English: Access Vector Cache, AVC); network interface tables; the network notification signal code; its own virtual file system (selinuxfs) and the implementation of the interceptor functions.
-
The access vector cache is used to cache computed results (store ready-made access control decisions) obtained from the security server.
This is needed to minimize the performance overhead of the SELinux security mechanisms.
The access vector cache interface for the security server is defined in the header file include/avc_ss.h . -
The network interface table maps network devices to security contexts.
Separate tables are needed because the security field of network devices was excluded from the project.
Network devices are added to the table when they first come into the view of the interceptor functions (are detected by them) and are removed from it when the device is configured or the security policy is reloaded due to reconfiguration.
This is possible thanks to callback functions that register changes in the device configuration and the reloading of security policies.
The code of the network interface table can be found in the file netif.c . -
The network notification event code allows the SELinux module to notify operating system processes when the security policy has been reloaded.
These notifications are used by user space to maintain compatibility with the kernel.
This mechanism is possible thanks to the SELinux library. The network notification event code can be found in the file netlink.c . -
The SELinux pseudo file system exports the API functions of the security server policy into operating system processes.
Initially, the SELinux kernel API functions were divided into three components (process attributes, file attributes, policy API) as part of the changes for the Linux 2.6 kernel version.
SELinux also provides support for the calls policy API. All three components of the new kernel API are encapsulated in the SELinux API library (libselinux).
The code of the pseudo file system can be found in the file selinuxfs.c . -
The implementation of the interceptor functions manages the information security associated with the internal kernel objects and the implementation of SELinux access control for each operation inside the kernel.
The interceptor functions call the security server and the access vector cache to obtain security policy decisions and to apply these decisions for labelling by some criteria and controlling kernel objects.
The code of these interceptor functions is located in the file hooks.c , and the data structures associated with the internal objects are defined in the file include/objsec.h .
Article author: Andrei Olegovich