Security analysts and system administrators often face a critical challenge: determining whether an application was blocked by a security policy or if the block was legitimate. When Security-Enhanced Linux (SELinux) is in Enforcing mode, it silently prevents unauthorized actions without always providing clear context to the developer. To resolve this, professionals switch SELinux to Permissive mode. This allows the system to log every action that would have been denied, enabling deep analysis of deny logs without disrupting production services. This guide provides a practical, safe workflow for configuring SELinux in Permissive mode, analyzing logs, and hardening systems effectively.
Understanding the Risk of Enforcing Mode vs. Permissive Mode
Before modifying system configurations, it is essential to understand the operational impact. In Enforcing mode, SELinux actively blocks operations that violate its policies. If a legitimate application lacks a specific rule, it crashes or fails silently. While this protects the system, it creates friction during development and incident response.
In Permissive mode, SELinux logs these violations but allows them to proceed. This is crucial for debugging. However, running in Permissive mode on a live production server without a defined policy can introduce security risks, as unauthorized actions may succeed before being logged. Therefore, this procedure assumes a controlled lab environment or a maintenance window where temporary policy relaxation is acceptable.
Prerequisites:
* Access to a RHEL-based system (CentOS, AlmaLinux, Rocky Linux) or Fedora with SELinux enabled.
* Root or sudo privileges.
* A backup of current configuration files (/etc/selinux.conf or /etc/sysconfig/selinux).
Step 1: Verify Current SELinux Status and Version Assumptions
Modern distributions use sestatus to check the current mode. It is vital to confirm the kernel version and architecture, as older kernels may handle context switching differently.
Run the following command to view the status:
sestatus
Expected Output:
SELinux status: enabled
SELinux mode: enforcing
Current policy: strict
If the mode is disabled, you must enable it first using setenforce 1 (though this reverts to Enforcing). For this guide, we assume SELinux is already enabled. Note that on Fedora, the default policy might be “targeted” or “strict,” which affects how logs appear.
Step 2: Switching to Permissive Mode Safely
To begin analysis, change the mode from Enforcing to Permissive. This action takes effect immediately for new processes but does not retroactively unblock past events.
Execute the following command:
setenforce 0
Verification:
Run sestatus again. The output should now read:
SELinux mode: permissive
Security Consideration:
This change lowers the immediate security posture of the host. Do not leave a system in Permissive mode indefinitely. Plan to revert to Enforcing mode once your analysis is complete and new policies have been written or verified. Always document this state change in your incident response ticketing system.
Step 3: Identifying Unauthorized Process Execution in Logs
With SELinux in Permissive mode, the system logs denied actions. The primary tool for this analysis is audit.log, located at /var/log/audit/audit.log on RHEL/CentOS systems. On Debian-based systems with AppArmor or other modules, log paths differ, but SELinux specifically relies on the audit subsystem.
Use the ausearch command to filter for denial records related to unauthorized process execution. This isolates events where a process attempted an action it was not allowed to perform.
ausearch -m AVC -ts today | grep denied
Illustrative Output:
The output will look similar to the following, containing hex-encoded contexts and message IDs:
type=AVC msg=audit(1715623400.123:456): avc: denied { write } for pid=1234 comm="httpd" path="/var/www/html/shell.php" name="shell.php" dev="sda1" ino=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_t:s0 tclass=file permissive=1
Decoding the Log:
* avc: Audit Vector Context.
* { write }: The specific permission denied (read, execute, write, etc.).
* comm="httpd": The process attempting the action.
* scontext vs tcontext: The source security context and target security context. In this example, the web server (httpd_t) tried to write to a file owned by unconfined_t, which is suspicious.
* permissive=1: Confirms this event was logged because we are in Permissive mode.
Step 4: Analyzing and Validating Deny Logs
Raw audit logs are difficult to read. Use the audit2allow utility to generate a human-readable report and suggest policy modules.
ausearch -m AVC -ts today | grep denied > /tmp/denials.log
audit2allow -i < /tmp/denials.log
The tool will output a list of suggested rules, such as:
#============= httpd_t ==============
httpd_can_network_connect_db
httpd_can_script
Analysis Strategy:
1. Filter Noise: Ignore denials from system daemons that are expected to fail (e.g., mail servers rejecting spam). Focus on application-specific denials.
2. Check for Malicious Activity: Look for patterns where a user process attempts to access sensitive areas like /etc/shadow or network sockets it shouldn’t touch.
3. Cross-Reference: Compare the denied actions against known vulnerabilities (CVEs) for that specific software version.
Step 5: Common Errors and Troubleshooting
When working with SELinux logs, several common errors can obscure analysis.
-
Error: “Permission Denied” when reading audit.log.
- Cause: The
rootuser is required to read the audit log directly. If using a non-root shell script, ensure it runs with elevated privileges or uses theauditddaemon permissions correctly. - Fix: Run commands as root or use
sudo.
- Cause: The
-
Error: “No AVC denials found.”
- Cause: SELinux might be disabled entirely, or the audit log is rotated/cleared too frequently.
- Fix: Ensure
auditdservice is running (systemctl status auditd) and that logging is enabled in/etc/audit/auditd.conf.
-
Error: False Positives.
- Cause: A process might be legitimately misconfigured, triggering a denial.
- Fix: Do not blindly apply
audit2allowsuggestions. Always verify the intent of the rule before adding it to the policy. Adding unnecessary rules reduces the security granularity of SELinux.
Step 6: Reverting to Enforcing Mode and Hardening
Once analysis is complete, you must restore the secure configuration. Leaving a system in Permissive mode is a significant vulnerability if not managed strictly.
Reversion Steps:
1. Review all identified denials. Decide which require policy updates and which are anomalies.
2. If necessary, create custom policies using semodule or edit the local policy store.
3. Re-enable enforcing mode:
bash
setenforce 1
4. Verify the change:
bash
sestatus
Expected Output: SELinux mode: enforcing
Industry Application Checklist:
* [ ] Did I document all denied actions before switching back?
* [ ] Have I verified that the suggested policy fixes do not broaden access unnecessarily?
* [ ] Is the system now back in Enforcing mode?
* [ ] Have I cleared temporary analysis files (/tmp/denials.log)?
Student Practice Task: The Web Server Investigation
For IT students and junior engineers, a practical exercise reinforces these concepts. Set up a virtual machine with a web server (Apache or Nginx). Attempt to access a directory that requires authentication but has no credentials provided. Observe the error page. Then, switch SELinux to Permissive and check the logs. You will likely see a denial related to httpd_sys_rw_content_t versus the untrusted context of the login form. This exercise teaches the importance of least privilege without crashing the service.
Conclusion
Configuring SELinux in Permissive mode is a powerful diagnostic technique for incident responders and security engineers. By allowing denied actions to proceed while logging them, you gain visibility into potential unauthorized process executions that would otherwise go unnoticed. However, this power comes with responsibility. Always perform this analysis in isolated environments or during maintenance windows, document your findings rigorously, and revert to Enforcing mode promptly. Proper log analysis combined with strict policy management ensures a robust defense against modern threats while maintaining system stability.
Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.

