avc_netlink_loop - Linux


Overview

avc_netlink_loop is a command-line utility used to loop SELinux AVC messages through the netlink socket. It provides a convenient way to test and debug SELinux policies by simulating policy violations and observing the corresponding messages.

Syntax

avc_netlink_loop [options] <domain> <type> <class> <perm>

Options/Flags

  • -a, –audit: Print audit records instead of netlink AVC messages.
  • -c, –count: Limit the number of messages to print.
  • -d, –domain: Domain name of the subject that is attempting the access.
  • -P, –policy: Policy module to use.
  • -r, –role: Role of the subject that is attempting the access.
  • -s, –source: Source of the AVC message (optional).
  • -t, –type: SELinux type of the object being accessed.
  • -cl, –class: SELinux class of the object being accessed.
  • -p, –perm: SELinux permission being requested.

Examples

Print a single AVC message:

avc_netlink_loop unlabeled_t httpd_t file read

Print 10 AVC messages:

avc_netlink_loop unlabeled_t httpd_t file read -c 10

Print audit records instead of netlink AVC messages:

avc_netlink_loop -a unlabeled_t httpd_t file read

Common Issues

One common issue is that the command may fail to receive any messages if the SELinux policy is incorrectly configured. Ensure that the policy is loaded and that the AVC messages are being logged.

Integration

avc_netlink_loop can be used in conjunction with other utilities like ausearch to analyze SELinux audit logs. For example, the following command can be used to find all AVC messages related to a specific domain:**

avc_netlink_loop -P targeted -d domain -a | ausearch -m avc

Related Commands

  • ausearch: Searches for SELinux audit records.
  • audit2allow: Generates SELinux policy rules from audit logs.
  • semanage: Manages SELinux policies and configurations.