


SELinux has three working modes: Disabled, Permissive and Enforcing. In Disable mode, SELinux is turned off and the default DAC access control method is used. In Permissive mode, SELinux is enabled, but security policy rules are not enforced; access is still allowed when security policy rules should deny access. In Enforcing mode, SELinux is started and all security policy rules are enforced.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is SELinux
SELinux, the abbreviation of Security Enhanced Linux, that is, security-enhanced Linux, is Developed jointly by the U.S. National Security Agency (NSA) and other security agencies (such as SCC), it aims to enhance the security of the traditional Linux operating system and solve various permission issues in the Discretionary Access Control (DAC) system in traditional Linux systems ( Such as root permission is too high, etc.).
The SELinux project was open sourced under the GPL license in 2000. SELinux gradually became popular when Red Hat included SELinux in its Linux distribution. Now, SELinux has been widely used by many organizations, and almost all Linux kernel versions 2.6 and above have integrated SELinux functions.
Beginners can understand SELinux in this way. It is a functional module deployed on Linux to enhance system security.
We know that in traditional Linux systems, the default permissions are to control the read, write and execution permissions of the owner, group and other people of the file or directory. This control method is called Discretionary access control (DAC) method; in SELinux, the mandatory access control (MAC) system is used, which is to control whether a process has access rights to files or directories on a specific file system, and The basis for determining whether a process can access a file or directory depends on many policy rules set in SELinux.
- Discretionary Access Control (DAC) is the default access control method of Linux, which determines whether access is possible based on the user's identity and the identity's rwx permissions on files and directories. However, we also found some problems in the actual use of DAC access control: The root permissions are too high, and the rwx permissions are not effective for the root user. Once the root user is stolen or the root user himself misoperates, all the consequences will be to the root user. A deadly threat to Linux systems.
Linux default permissions are too simple. They only have the identity of the owner, the group to which they belong, and other people. The permissions only have read, write, and execute permissions, which is not conducive to permission subdivision and setting.
Unreasonable allocation of permissions will lead to serious consequences, such as setting 777 permissions for sensitive system files or directories, or setting special permissions for sensitive files - SetUID permissions, etc.
- Mandatory Access Control (MAC) uses the default policy rules of SELinux to control the access of specific processes to system file resources. In other words, even if you are a root user, if you use an incorrect process when accessing a file resource, you will not be able to access the file resource.
Note that in SELinux, the default permissions of Linux are still effective. That is to say, for a user to be able to access a file, the user's permissions are required to comply with the rwx permissions, and the user is also required to The process complies with SELinux regulations.However, there are so many processes and so many files in the system. If you manually allocate and specify them, the workload will be too large. Therefore, SELinux provides a lot of default policy rules, which are relatively complete. We will learn how to view and manage these policy rules later. In order to give readers a clear understanding of the role played by SELinux, here is an example. Suppose a vulnerability is discovered in apache, allowing a remote user to access sensitive files of the system (such as /etc/shadow). If SELinux is enabled in our Linux, then, because the apache service process does not have the permission to access /etc/shadow, the remote user's access to the /etc/shadow file through apache will be blocked by SELinux, which protects Linux. The role of the system.
SELinux working modes (Disabled, Permissive and Enforcing)
On the basis of the access control method used by traditional Linux systems, the additional use of SELinux can enhance system security. So, how does SELinux work? Before explaining the working mode of SELinux, let’s first explain a few concepts.1.Subject : It is the process that wants to access file or directory resources. To obtain resources, the basic process is as follows: the user calls a command, the command generates a process, and the process accesses the file or directory resource. In a discretionary access control system (Linux default permissions), the subject controlled by permissions is the user; in a mandatory access control system (SELinux), the subject controlled by policy rules is the process.
2. Object (Object): This concept is relatively clear, it is the file or directory resource that needs to be accessed.
3. Policy: There are a huge number of processes and files in the Linux system, so the number of SELinux rules that limit whether processes can access files is even more cumbersome. If each rule requires the administrator to manually settings, the availability of SELinux will be extremely low. Fortunately, we don't need to manually define the rules. SELinux defines two policies by default. The rules have been written in these two policies. By default, just call the policy and it can be used normally. The two default policies are as follows:
- -targeted: This is the default policy of SELinux. This policy mainly limits network services and has very few restrictions on the local system. This strategy is enough for us.
- -mls: Multi-level security protection strategy, this strategy is more restrictive.
4. Security Context : Each process, file and directory has its own security context. Whether the process can access the file or directory depends on Does this security context match? If the security context of the process matches the security context of the file or directory, the process can access the file or directory. Of course, to determine whether the security context of a process matches the security context of a file or directory, you need to rely on the rules in the policy.
For example, we need to find a partner. Men can be regarded as the subject, and women are the targets. Whether a man can pursue a woman (whether the subject can access the target) mainly depends on whether the two people's personalities are suitable (whether the security context of the subject and the target matches). However, whether the personalities of two people are suitable needs to be judged based on specific conditions such as living habits, behavior, family environment, etc. (Whether the security context matches needs to be determined through the rules in the policy).
We draw a schematic diagram to show the relationship between these concepts, as shown in Figure 1.
Figure 1 Related concepts of SELinux operating mode
Explain this diagram: When the subject wants to access the target, if SELinux is started in the system, the subject's Access requests first need to match the policies defined in SELinux. If the process complies with the rules defined in the policy, access is allowed. At this time, the security context of the process can be matched with the security context of the target; if the comparison fails, access is denied and the access vector cache is passed through AVC (Access Vector Cache). Mainly used to record all access statistics related to SELinux) and generate access denial information. If the security context matches, the target file can be accessed normally. Of course, whether the target file can be truly accessed in the end depends on whether the user who created the process (subject) has reasonable read, write, and execute permissions on the target file.
When we manage SELinux, we generally only>modify the security context of a file or directory so that it matches or does not match the security context of the accessing process to control the process Whether file or directory resources can be accessed; and the specific rules in the policy are rarely modified because there are too many rules and it is too complicated to modify. However, we can manually define whether the rules take effect to control the activation and deactivation of the rules.
Working modes of SELinux
SELinux provides 3 working modes: Disabled, Permissive and Enforcing, and each mode is suitable for Linux systems. Security provides different benefits.
Disable working mode (off mode)
In Disable mode, SELinux is turned off and default DAC access control method is used. This mode is useful for environments that do not require enhanced security.
For example, if a running application is working fine from your perspective, but is generating a large number of SELinux AVC reject messages, it may eventually fill up the log file and render the system unusable. In this case, the most straightforward solution is to disable SELinux, but you can also set the correct security context on the files your application accesses.
It should be noted that before disabling SELinux, you need to consider whether SELinux may be used again on the system. If you decide to set it to Enforcing or Permissive in the future, the system will automatically pass an SELinux file reprocess marking.
The way to turn off SELinux is also very simple. Just edit the configuration file /etc/selinux/config and change SELINUX= in the text to SELINUX=disabled. After restarting the system, SELinux will be disabled.
Permissive working mode (permissive mode)
In Permissive mode, SELinux is enabled, but the security policy rules and was not enforced. When security policy rules should deny access, access is still allowed. However, a message is sent to the log file indicating that access should be denied.
SELinux Permissive mode is mainly used in the following situations:
Review the current SELinux policy rules;
Test new applications to see what effect the SELinux policy rules will have when applied to these programs. ;
Resolve a problem where a specific service or application no longer works properly under SELinux.
In some cases, the audit2allow command can be used to read the SELinux audit log and generate new SELinux rules to selectively allow denied behavior, and this is also a case where SELinux is not disabled. Here's a quick way to get your application working on a Linux system.
Enforcing working mode (enforcing mode)
As can be seen from the name of this mode, in Enforcing mode , SELinux is started and all security policy rules are enforced.
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of What are the three working modes of SELinux?. For more information, please follow other related articles on the PHP Chinese website!

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

在linux中,交叉编译是指在一个平台上生成另一个平台上的可执行代码,即编译源代码的平台和执行源代码编译后程序的平台是两个不同的平台。使用交叉编译的原因:1、目标系统没有能力在其上进行本地编译;2、有能力进行源代码编译的平台与目标平台不同。

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

在linux中,rpc是远程过程调用的意思,是Reomote Procedure Call的缩写,特指一种隐藏了过程调用时实际通信细节的IPC方法;linux中通过RPC可以充分利用非共享内存的多处理器环境,提高系统资源的利用率。

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version
