Sub topic 9
Finding AVC denials in the audit log
When SELinux blocks an action, it records the refusal as an AVC denial. This chapter shows where those records are, how to read one, and how to search for the ones that matter. It assumes you can use sudo, read journalctl output, and know the security context format (user:role:type:level) and the idea of a domain such as httpd_t from earlier chapters.
What an AVC denial is
SELinux keeps recent access decisions in the Access Vector Cache (AVC). When a process asks for something the policy does not allow, the kernel refuses the request and emits an audit record of type AVC. The application only sees an ordinary error such as "Permission denied", so the audit record is often the only sign that SELinux was involved.
The record travels like this:
On RHEL-family systems auditd normally runs, so the main source is /var/log/audit/audit.log. That file is readable only by root, so use sudo for everything below.
Reading one record
A denial looks like this. It is one line in the log, wrapped here for reading.
type=AVC msg=audit(1764305890.412:2871): avc: denied { read } for pid=2214 comm="httpd" name="index.html" dev="dm-0" ino=1048821 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0| Field | Example | Meaning |
|---|---|---|
| `msg=audit(time:serial)` | `1764305890.412:2871` | Unix timestamp and an event serial number. Other records from the same event share the serial. |
| `denied { ... }` | `{ read }` | The permission that was refused. It can list several, such as `{ read open }`. |
| `pid`, `comm` | `2214`, `httpd` | The process ID and command name of the caller. |
| `name`, `dev`, `ino` | `index.html`, `dm-0`, `1048821` | The target object: file name, device, and inode. |
| `scontext` | `...:httpd_t:s0` | The source context, which is the process that asked. |
| `tcontext` | `...:default_t:s0` | The target context, which is the object it asked for. |
| `tclass` | `file` | The object class: `file`, `dir`, `tcp_socket`, `process`, and so on. |
| `permissive` | `0` | `0` means the access was blocked. `1` means it was allowed and only logged. |
To read a denial, say it as a sentence: "a process in domain httpd_t tried to read a file labeled default_t." Then compare the two types. Apache is allowed to read httpd_sys_content_t, not default_t, so the fix here is a labeling fix, not a policy change.
The shape of tclass tells you the likely category of fix:
file,dir,lnk_filewith a wrongtcontexttype usually means a labeling problem.tcp_socketwithname_bindusually means a port that needs a label.tcp_socketwithname_connectis often fixed by a boolean such ashttpd_can_network_connect.processwithexecmemorexecmodis often a boolean too, or a sign of an unusual application.
Searching with ausearch
Reading the log with grep works, but ausearch understands the record format and joins related records by serial number.
# Denials from the last 10 minutes
sudo ausearch -m avc -ts recent
# Denials since midnight, with numbers translated to names
sudo ausearch -m avc -ts today -i
# Only denials involving the httpd command
sudo ausearch -m avc -c httpd -ts today
# Denials since the last boot
sudo ausearch -m avc -ts bootThe -m avc option limits output to AVC records. -ts sets the start time and accepts recent (the last 10 minutes), today, yesterday, this-week, boot, or an explicit time like -ts 11/28/2026 04:00:00. The -i option interprets raw values, so timestamps become readable dates and numeric IDs become names.
With -i, each event also shows its companion SYSCALL record. That record names the system call (syscall=open), the result (success=no exit=-13), and the executable path (exe=/usr/sbin/httpd). Exit code -13 is EACCES, the same "Permission denied" the application reported.
You can also use the journal:
sudo journalctl _AUDIT_TYPE_NAME=AVC --since "1 hour ago"
sudo grep AVC /var/log/audit/audit.log | tail -n 5A worked example
Suppose you moved a site to /srv/web and Apache returns 403 Forbidden even though the Unix permissions look right. First reproduce the failure, then look for a denial.
curl -sI http://localhost/index.html | head -n 1
sudo ausearch -m avc -ts recent -iA typical result:
type=AVC msg=audit(11/28/2026 04:58:31.412:2871) : avc: denied { read } for pid=2214 comm=httpd name=index.html dev="dm-0" ino=1048821 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:default_t:s0 tclass=file permissive=0The source is httpd_t, the target is default_t, and the class is file. Confirm the label on the file:
ls -Zd /srv/web /srv/web/index.htmlIf both show default_t, the fix is to label the path with semanage fcontext and run restorecon, as in the file labeling chapter. Do not reach for audit2allow here. A label fix keeps the policy as the vendor wrote it.
Why you may see nothing
An empty ausearch result does not always mean SELinux is innocent. Check these causes in order:
- The wrong time window.
-ts recentcovers only 10 minutes. Widen it totodayorboot. - SELinux is disabled. Run
getenforce. If it printsDisabled, no AVC records exist. - The log rotated.
ausearchreads onlyaudit.logby default. Older events are inaudit.log.1and later files. Pass one with-if /var/log/audit/audit.log.1. - A
dontauditrule hides the denial. The policy deliberately suppresses some denials that are common and harmless. A real failure can hide behind one. - The failure is not SELinux. Test with
sudo setenforce 0briefly, or better, use a permissive domain as shown in a later chapter. If the error persists, look at Unix permissions, firewalls, or the application itself.
To expose dontaudit denials, rebuild the policy without those rules, reproduce the problem, and then restore the rules:
sudo semodule -DB # disable dontaudit rules
# reproduce the failure, then search again
sudo ausearch -m avc -ts recent -i
sudo semodule -B # rebuild with dontaudit rules restoredDenials come one at a time
An application usually stops at the first refused operation. If you fix that denial, the program may proceed and hit a second one that was never logged. A new service can therefore need several rounds: reproduce, search, fix, and repeat.
Permissive mode for the single domain avoids that, because the process continues past every would-be denial and all of them are logged with permissive=1. A later chapter covers this.
Also look at the tclass and { permission } pairs across several denials before choosing a fix. Three denials against the same wrong label are one labeling problem, not three policy gaps.
Keeping the log usable
The audit log grows with each denial and is rotated by auditd according to /etc/audit/auditd.conf. The relevant settings are max_log_file (size in MB), num_logs, and max_log_file_action. Raise num_logs on systems where you investigate denials after the fact, since the default retention can be short on a busy host.
When you cannot reproduce a problem, search by date instead of recent:
sudo ausearch -m avc -ts 11/27/2026 00:00:00 -te 11/27/2026 23:59:59 -iThe -te option sets the end time. This narrows a day of events to the window when the user reported the failure.
Exercise
A cron-started backup script runs as a confined service and fails. sudo ausearch -m avc -ts recent prints nothing, but getenforce shows Enforcing and the failure happened two hours ago. What are two things you should try before concluding SELinux is not involved?
Show answer
Widen the time window, for example sudo ausearch -m avc -ts today -i, because recent covers only the last 10 minutes. Then check whether a dontaudit rule is hiding the denial: run sudo semodule -DB, reproduce the failure, search again, and restore the rules with sudo semodule -B. You can also check rotated logs with -if /var/log/audit/audit.log.1.
Exercise
You find this denial: denied { name_connect } for comm="httpd" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:postgresql_port_t:s0 tclass=tcp_socket. State in one sentence what happened, and name the category of fix you would try first.
Show answer
The Apache process in httpd_t tried to open an outbound TCP connection to a port labeled postgresql_port_t, and the policy refused it. Check for a boolean first, such as httpd_can_network_connect_db, enabled with sudo setsebool -P httpd_can_network_connect_db on, before considering a custom module.