Difference between revisions of "NB AL"

From SELinux Wiki
Jump to: navigation, search
(New page: = Audit Logs = For SELinux there are two main types of audit event: # SELinux-aware Application Events - These are generated by the SELinux kernel services and SELinux-aware applications ...)
 
(SELinux-aware Application Events)
Line 35: Line 35:
  
 
type=SYSCALL msg=audit(1243855634.660:30): arch=40000003 syscall=4 success=yes exit=3480819 a0=4 a1=b7c74000 a2=351cf3 a3=bfbd9dc8 items=0
 
type=SYSCALL msg=audit(1243855634.660:30): arch=40000003 syscall=4 success=yes exit=3480819 a0=4 a1=b7c74000 a2=351cf3 a3=bfbd9dc8 items=0
ppid=2731 pid=2732 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="load_policy" exe="/usr/sbin/load_policy" subj=unconfined_u:unconfined_r:load_policy_t:s0-s0:c0.c1023 key=(null)
+
ppid=2731 pid=2732 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="load_policy"  
 +
exe="/usr/sbin/load_policy" subj=unconfined_u:unconfined_r:load_policy_t:s0-s0:c0.c1023 key=(null)
  
 
type=USER_ROLE_CHANGE msg=audit(1243855646.618:31): user pid=2731 uid=0 auid=0 ses=1 subj=unconfined_u:unconfined_r:semanage_t:s0-s0:
 
type=USER_ROLE_CHANGE msg=audit(1243855646.618:31): user pid=2731 uid=0 auid=0 ses=1 subj=unconfined_u:unconfined_r:semanage_t:s0-s0:
Line 53: Line 54:
  
 
type=SYSCALL msg=audit(1243856597.296:32): arch=40000003 syscall=4 success=yes exit=1 a0=3 a1=bf95b554 a2=1 a3=bf95b554 items=0 ppid=2643  
 
type=SYSCALL msg=audit(1243856597.296:32): arch=40000003 syscall=4 success=yes exit=1 a0=3 a1=bf95b554 a2=1 a3=bf95b554 items=0 ppid=2643  
pid=2761 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="setenforce" exe="/usr/sbin/setenforce" subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
+
pid=2761 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="setenforce" exe="/usr/sbin/setenforce"  
 +
subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)
 
</pre>
 
</pre>
  

Revision as of 15:06, 16 May 2010

Audit Logs

For SELinux there are two main types of audit event:

  1. SELinux-aware Application Events - These are generated by the SELinux kernel services and SELinux-aware applications for events such as system errors, initialisation, policy load, changing boolean states, setting of enforcing / permissive mode and relabeling.
  2. AVC Audit Events - These are generated by the AVC subsystem as the result of access denials, or where specific events have requested an audit message (i.e. where an auditallow rule has been used in the policy).

The audit and event messages can be stored in one of two places (in F-12 anyway):

  1. The system log located at /var/log/messages that contains the syslog boot and runtime events. The AVC messages logged here are those generated by SELinux before the audit daemon has been loaded, as F-12 uses the audit framework (auditd) as standard. However, some SELinux-aware audit messages are logged here as well[1]. Note that the detailed SELinux kernel boot events are logged in the /var/log/dmesg file.
  2. The audit log located at /var/log/audit/audit.log. Audit events that take place after the audit daemon has been loaded are in this log file as are some SELinux system messages. The AVC audit messages of interest are those starting with type=AVC and are described below.

Note that SE-PostgreSQL does not send its AVC events to the standard audit.log, but to its own log file as discussed in the SELinux PostgreSQL Support section.

SELinux-aware Application Events

For SELinux and SELinux-aware applications (excluding the AVC entries that are discussed in the AVC Audit Events section below) the following are possible type= entries within the audit.log file that have been seen:

# Example audit.log entries for adding a new SELinux user with:
#
# semanage user -a -R staff_r -P STAFF test_u
#
# Note that the audit messages appear in the following sequence:
# 
# 1) That USER_AVC has received a policy reload message. 
# 2) A notice that the policy is changing by MAC_POLICY_LOAD.
# Note that this event is followed by another audit message
# with type=SYSCALL with further information. These two 
# events are tied by having the same serial_number in the 
# msg=audit(time:serial_number) field.
# 3) That semanage carried out a USER_ROLE_CHANGE.

type=USER_AVC msg=audit(1243855640.568:29): user pid=1543 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:
s0-s0:c0.c1023 msg='avc: received policyload notice (seqno=3) : exe="?" (sauid=81, hostname=?, addr=?, terminal=?)'

type=MAC_POLICY_LOAD msg=audit(1243855634.660:30): policy loaded auid=0 ses=1

type=SYSCALL msg=audit(1243855634.660:30): arch=40000003 syscall=4 success=yes exit=3480819 a0=4 a1=b7c74000 a2=351cf3 a3=bfbd9dc8 items=0
ppid=2731 pid=2732 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="load_policy" 
exe="/usr/sbin/load_policy" subj=unconfined_u:unconfined_r:load_policy_t:s0-s0:c0.c1023 key=(null)

type=USER_ROLE_CHANGE msg=audit(1243855646.618:31): user pid=2731 uid=0 auid=0 ses=1 subj=unconfined_u:unconfined_r:semanage_t:s0-s0:
c0.c1023 msg='op=add SELinux user record acct="test_u" old-seuser=? old-role=? old-range=? new-seuser=test_u new-role=staff_r new-range=?
exe=/usr/sbin/semanage (hostname=?, addr=?, terminal=pts/0 res=success)'

# Example audit.log entries for setting enforcing mode by:
#
# setenforce 1
#
# Note that the audit messages appear in the following sequence:
# 
type=MAC_STATUS msg=audit(1243856597.296:32): enforcing=1 old_enforcing=0 auid=0 ses=1

type=USER_AVC msg=audit(1243856597.312:33): user pid=1543 uid=81 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t:
s0-s0:c0.c1023 msg='avc: received setenforce notice (enforcing=1) : exe="?" (sauid=81, hostname=?, addr=?, terminal=?)'

type=SYSCALL msg=audit(1243856597.296:32): arch=40000003 syscall=4 success=yes exit=1 a0=3 a1=bf95b554 a2=1 a3=bf95b554 items=0 ppid=2643 
pid=2761 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="setenforce" exe="/usr/sbin/setenforce" 
subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=(null)

Other entries can appear in the audit.log file, however they are not covered in this Notebook.

It should be noted that entries placed in the /var/log/messages file before the audit daemon is loaded are in a different format, for example:

# This is an example entry of an AVC denial and corresponding 
# SYSCALL from the /var/log/messages file that were captured 
# before the audit daemon was loaded:

May 26 12:34:16 localhost kernel: type=1400 audit(1243337656.638:1358): avc: denied { read } for pid=3033 comm="rsyslogd" path="/proc/kmsg"
dev=proc ino=4026531848 scontext=system_u:system_r:syslogd_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=file

May 26 12:34:16 localhost kernel: type=1300 audit(1243337656.638:1358): arch=40000003 syscall=3 success=yes exit=230 a0=7 a1=11f7e0 
a2=fff a3=11f7e0 items=0 ppid=1 pid=3033 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295
comm="rsyslogd" exe="/sbin/rsyslogd" subj=system_u:system_r:syslogd_t:s0 key=(null)

The more detailed SELinux boot time messages are placed in the /var/log/dmesg file where selected SELinux entries are as follows:

Security Framework initialized
SELinux: Initializing.
SELinux: Starting in permissive mode
...
SELinux: Registering netfilter hooks
....
SELinux: 8192 avtab hash slots, 113530 rules.
SELinux: 8192 avtab hash slots, 113530 rules.
SELinux: 9 users, 11 roles, 2608 types, 122 bools, 1 sens, 1024 cats
SELinux: 73 classes, 113530 rules
SELinux: Completing initialization.
SELinux: Setting up existing superblocks.
SELinux: initialized (dev dm-0, type ext3), uses xattr
SELinux: initialized (dev tmpfs, type tmpfs), uses transition SIDs
SELinux: initialized (dev usbfs, type usbfs), uses genfs_contexts
SELinux: initialized (dev selinuxfs, type selinuxfs), uses genfs_contexts
SELinux: initialized (dev mqueue, type mqueue), uses transition SIDs
....
SELinux: initialized (dev sockfs, type sockfs), uses task SIDs
...
SELinux: initialized (dev rootfs, type rootfs), uses genfs_contexts
SELinux: initialized (dev sysfs, type sysfs), uses genfs_contexts
type=1403 audit(1243839417.933:2): policy loaded auid=4294967295 ses=4294967295
...
...
SELinux: initialized (dev sda1, type ext3), uses xattr
SELinux: initialized (dev tmpfs, type tmpfs), uses transition SIDs
SELinux: Context user_u:unconfined_r:unconfined_t is not valid (left unmapped).
...
...
SELinux: initialized (dev binfmt_misc, type binfmt_misc), uses genfs_contexts

AVC Audit Events

Table 4 shows the general format of AVC audit message within the /var/log/audit/audit.log file. These appear when access has been denied or an audit event has been specifically requested.

Keyword Description
type For SELinux AVC events this can be:

type=AVC - for kernel events

type=USER_AVC - for user-space object manager events

Note that once the AVC event has been logged, another event with type=SYSCALL will follow that contains further information regarding the event.

The AVC event can always be tied to the relevant SYSCALL event as they have the same serial_number in the msg=audit(time:serial_number) field as shown in the following example:

type=AVC msg=audit(1243332701.744:101): avc: denied { getattr } for pid=2714 comm="ls" path="/usr/lib/locale/locale-archive" 
dev=dm-0 ino=353593 scontext=system_u:object_r:unlabeled_t:s0 tcontext=system_u:object_r:locale_t:s0 tclass=file

type=SYSCALL msg=audit(1243332701.744:101): arch=40000003 syscall=197 success=yes exit=0 a0=3 a1=553ac0 a2=552ff4 a3=bfc5eab0 items=0 
ppid=2671 pid=2714 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=1 comm="ls" ''exe="/bin/ls''" subj=system_u:object_r:unlabeled_t:s0 key=(null)


msg This will contain the audit keyword with a reference number (e.g. msg=audit(1243332701.744:101))
avc This will be either denied when access has been denied or granted when the auditallow rule has been executed by the AVC system.

The entries that follow the avc= field depend on what type of event is being audited. Those shown below are generated by the kernel AVC audit function, however the user space AVC audit function will return fields relevant to the application being managed by their Object Manager.

pid If a task, then log the process id (pid) and the name of the executable file (comm).
comm
key If an IPC event then log the identifier.
capability If a Capability event then log the identifier.
path If a File System event then log the relevant information. Note that the name field may not always be present.
name
dev
ino
laddr If a Socket event then log the Source / Destination addresses and ports for IP4 or IP6 sockets (AF_INET).
lport
faddr
fport
path If a File Socket event then log the path (AF_UNIX).
saddr If a Network event then log the Source / Destination addresses and ports with the network interface for IP4 or IP6 networks (AF_INET).



src
daddr
dest
netif
sauid IPSec security association identifiers
hostname
addr
terminal
resid X-Windows resource ID and type.
restype
scontext The security context of the source or subject.
tcontext The security context of the target or object.
tclass The object class of the target or object.

Table 4: AVC Audit Message Description - The keywords in bold are in all AVC audit messages, the others depend on the type of event being audited.

Example audit.log denied and granted events are shown in the following examples:

# This is an example denied message note that there are two 
# type=AVC calls, but only one corresponding type=SYSCALL entry.

type=AVC msg=audit(1242575005.122:101): avc: denied { rename } for pid=2508 comm="canberra-gtk-pl" name="c73a516004b572d8c845c74c49b2511d:runtime.tmp" dev=dm-0 ino=188999 scontext=test_u:staff_r:oddjob_mkhomedir_t:s0 tcontext=test_u:object_r:gnome_home_t:s0 tclass=lnk_file

type=AVC msg=audit(1242575005.122:101): avc: denied { unlink } for pid=2508 comm="canberra-gtk-pl" name="c73a516004b572d8c845c74c49b2511d:runtime" dev=dm-0 ino=188578 scontext=test_u:staff_r:oddjob_mkhomedir_t:s0 tcontext=system_u:object_r:gnome_home_t:s0 tclass=lnk_file

type=SYSCALL msg=audit(1242575005.122:101): arch=40000003 syscall=38 success=yes exit=0 a0=82d2760 a1=82d2850 a2=da6660 a3=82cb550 items=0 ppid=2179 pid=2508 auid=500 uid=500 gid=500 euid=500 suid=500 fsuid=500 egid=500 sgid=500 fsgid=500 tty=(none) ses=1 comm="canberra-gtk-pl" exe="/usr/bin/canberra-gtk-play" subj=test_u:staff_r:oddjob_mkhomedir_t:s0 key=(null)
# These are example X-Windows object manager audit message:

type=USER_AVC msg=audit(1267534171.023:18): user pid=1169 uid=0 auid=4294967295 ses=4294967295 subj=system_u:unconfined_r:unconfined_t msg='avc: denied { getfocus } for request=X11:GetInputFocus comm=X-setest xdevice="Virtual core keyboard" scontext=user_u:unconfined_r:x_select_paste_t tcontext=system_u:unconfined_r:unconfined_t tclass=x_keyboard : exe="/usr/bin/Xorg" sauid=0 hostname=? addr=? terminal=?'

type=USER_AVC msg=audit(1267534395.930:19): user pid=1169 uid=0 auid=4294967295 ses=4294967295 subj=system_u:unconfined_r:unconfined_t msg='avc: denied { read } for request=SELinux:SELinuxGetClientContext comm=X-setest resid=3c00001 restype=<unknown> scontext=user_u:unconfined_r:x_select_paste_t tcontext=user_u:unconfined_r:unconfined_t tclass=x_resource : exe="/usr/bin/Xorg" sauid=0 hostname=? addr=? terminal=?'
# This is an example granted audit message:

type=AVC msg=audit(1239116352.727:311): avc: granted { transition } for pid=7687 comm="bash" path="/usr/move_file/move_file_c" dev=dm-0 ino=402139 scontext=user_u:unconfined_r:unconfined_t tcontext=user_u:unconfined_r:move_file_t tclass=process

type=SYSCALL msg=audit(1239116352.727:311): arch=40000003 syscall=11 success=yes exit=0 a0=8a6ea98 a1=8a56fa8 a2=8a578e8 a3=0 items=0 ppid=2660 pid=7687 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=1 comm="move_file_c" exe="/usr/move_file/move_file_c" subj=user_u:unconfined_r:move_file_t key=(null)




  1. For example if the iptables are loaded and there are SECMARK security contexts present, BUT the contexts are invalid (i.e. not in the policy), then the event is logged in the messages log and nothing will appear in the audit log.