Learning Objectives
By the end of this chapter, you should be able to:
What Are Linux Security Modules?
An LSM is code compiled directly into the Linux ___ that, utilizing the LSM framework, can ___ _ ___ access to important kernel objects.
The types of objects protected ___…
What Are Linux Security Modules?
The idea behind LSM is to implement mandatory access controls over the variety of requests made to the kernel, but to do so a way that: (3)
Minimizes changes to the kernel
Minimizes overhead on the kernel
Permits flexibility and choice between different implementations, each of which is presented as a self-contained LSM (Linux Security Module).
What Are Linux Security Modules?
The basic idea of LSM is to ___ into/between system calls; insert code whenever an application requests a transition to kernel (system) mode in order to accomplish work that requires enhanced abilities; this code makes sure permissions are valid, malicious intent is protected against, etc. It does this by invoking security-related functional steps ___ a system call is fulfilled by the kernel.
Main LSM Choices
For a long time, the only enhanced security model implemented was ___. When the project was first floated upstream in 2001 to be included directly in the kernel, there were objections about using only one approach to enhanced security.
As a result, the LSM approach was adopted, where alternative modules to ___ could be used as they were developed and was incorporated into the Linux kernel in 2003.
The current LSM implementations are:
Main LSM Choices
Originally, only 1 LSM could be used at a time as they can potentially modify the same parts of the Linux kernel. However, since 2019 it has been possiable to combine (stack) LSMs in certain specified orders.
What are the avaliable current LSM implementations?
Main LSM Choices
LSMs are now considered as either ___ or ___ when configuring their combination.
We will concentrate primarily on SELinux and secondarily on AppArmor in order of usage volume.
SELinux Overview
SELinux was originally developed by the United States ___ and has been integral to ___ disto for a very long time, which has brought it a large usage base.
SELinux Overview
Operationally, SELinux is a set of security rules that are used to determine which processes can access which files, directories, ports, and other items on the system.
It works with 3 conceptual quantities, what are they?
Describe the the 3 conceptual quantities work together?
SELinux Conceptual Quantities:
SELinux Enforcement Modes
SELinux can be run under one of three modes.
What are the 3 modes?
These modes are selected (and explained) in ___ (CentOS and openSUSE) or ___ (Ubuntu).
The ___ utility can display the current mode and policy.
SELinux Modes:
LSM - SELinux utility
What 2 command do you use to set/get LSM mode to be one of the mode it supports? (modes: enforcing, permissive, disabled)
Examples:
$ getenforce
Enforcing
$ sudo setenforce Permissive
$ getenforce
Permissive
LSM - SELinux utility
___ can be used to switch between ___ and ___ modes on the fly while the system is in operation. However, changing in or out of the ___ mode cannot be done this way.
LSM - SELinux utility
While ___ allows you to switch between permissive and enforcing modes, it does not allow you to disable SELinux completely. There are at least 2 different ways to disable SELinux. What are they?
Disabling SELinux
It is important to note that disabling SELinux on systems in which SELinux will be ___ is not recommended. It is preferable to use the ___ mode instead of disabling SELinux, so as to avoid relabeling the entire filesystem, which can be time-consuming.
SELinux Policies
The same configuration file that sets the mode, usually ___ , also sets the SELinux policy. Multiple policies are allowed, but only one can be ___ . Changing the policy may require a reboot of the system and a time-consuming re-labeling of filesystem contents. Each policy has files which must be installed under ___.
What are the 3 most common SELinux policies? describe them.
SELinux Context Utilities
As mentioned earlier, contexts (in terms of SELinux) are labels applied to ___, ___, ___, and ___. Those labels are used to describe ___ ___. There are four SELinux contexts:
SELinux Context Utilities
As mentioned earlier, contexts are labels applied to files, directories, ports, and processes. Those labels are used to describe access rules. There are four SELinux attributes that apply to a context what are they?
Context Utilities
However, we will focus on type context attribute, which is the most ___ utilized context attribute. The label naming convention determines that type context labels should end with ___, as in ___.
Context Utilities
What is the command to see the context of a
Examples:
View file/directory context attributes:
View process context attributes:
LSM Context Utilities
What is the command to change the context attibute of a file/directory, process, port?
Examples:
$ ls -Z
-rw-rw-r–. dog dog unconfined_u:object_r:user_home_t:s0 somefile
$ chcon -t etc_t somefile
$ ls -Z
-rw-rw-r–. dog dog unconfined_u:object_r:etc_t:s0 somefile
$ ls -Z
$ chcon –reference somefile somefile1
$ ls -Z
SELinux and Standard Commands
Many standard command line commands, such as ls and ps, were extended to support SELinux, and corresponding sections were added to their man pages explaining the details. Often the parameter Z is passed to standard command line tools, as in:
Other tools that were extended to support SELinux include ___, ___, and ___.
!!Note that if you have disabled SELinux, no useful information is displayed in the related fields from these utilities.
LSM Context
When viewing the context attributes of this file what are the context attributes displayed?
ls -Z
-rw-rw-r–. jimih jimih unconfined_u:object_r:user_tmp_t:s0 tmpfile
SELinux Context Inheritance
Newly created files inherit the context from their parent directory, but when ___ files, it is the context of the source directory which may be preserved, which can cause problems.
Continuing the previous example, we see the context of tmpfile was not changed by moving the file from /tmp to /home/jimih:
$ cd /tmp/
$ touch tmpfile
$ ls -Z tmpfile
-rw-rw-r–. jimih jimih unconfined_u:object_r:user_tmp_t:s0 tmpfile
$ cd
$ touch homefile
$ ls -Z homefile
-rw-rw-r–. jimih jimih unconfined_u:object_r:user_home_t:s0 homefile
$ mv /tmp/tmpfile.
$ ls -Z
The classical example in which moving files creates a SELinux issue is moving files to the DocumentRoot directory of the httpd server. On SELinux-enabled systems, the web server can only access files with the correct context labels. Creating a file in /tmp, and then moving it to the DocumentRoot directory, will make the file unaccessible to the httpd server until the SELinux context of the file is adjusted.
SELinux Restoring Context
___ resets file contexts, based on parent ___ settings. In the following example, ___ resets the default label recursively for all files at the home directory:
$ ls -Z
$ ___ -Rv /home/jimih
___ reset /home/jimih/tmpfile context \
unconfined_u:object_r:user_tmp_t:s0 >unconfined_u:object_r:user_home_t:s0
$ ls -Z
Note that the context for tmpfile has been reset to the default context for files created at the home directory. The type was changed from user_tmp_t to user_home_t.