Bug 1296851

Summary: Correct SELinux context for stunnel logging
Product: Red Hat Enterprise Linux 7 Reporter: Milos Malik <mmalik>
Component: selinux-policyAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: lvrabec, mgrepl, mmalik, plautrba, pvrabec, ssekidde, zpytela
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.13.1-71.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1296238 Environment:
Last Closed: 2016-11-04 02:40:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Milos Malik 2016-01-08 09:26:14 UTC
+++ This bug was initially created as a clone of Bug #1296238 +++

Description of problem:
The stunnel program cannot write to a logfile because of selinux context, any attempt ends with an avc denial.

Version-Release number of selected component (if applicable):
selinux-policy-3.13.1-60.el7.noarch
selinux-policy-targeted-3.13.1-60.el7.noarch
stunnel-4.56-4.el7.x86_64

How reproducible:
always

Steps to Reproduce:
1. Set "output = file" in stunnel.conf
2. Run stunnel

Actual results:
type=AVC msg=audit(1450711949.536:39519): avc:  denied  { search } for  pid=28935 comm="stunnel" name="log" dev=dm-0 ino=522773 scontext=system_u:system_r:stunnel_t:s0-s0:c0.c1023 tcontext=system_u:object_r:var_log_t:s0 tclass=dir
type=SYSCALL msg=audit(1450711949.536:39519): arch=c000003e syscall=2 success=no exit=-13 a0=7f802d1ec7e0 a1=441 a2=1a0 a3=4 items=0 ppid=1419 pid=28935 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="stunnel" exe="/usr/bin/stunnel" 
etc.
in /var/log/audit/audit/log

Expected results:
No AVC denials

Additional info:
Logging using syslog works fine. The stunnel(8) manual page describes logging to an output file option as well:

output = file
  append log messages to a file instead of using syslog
  /dev/stdout device can be used to redirect log messages to the standard
  output (for example to log them with daemontools splogger).

so that we can expect that it also works without issues.

According to the stunnel_selinux(8) manual page, currently there is no log-type context associated nor there is a boolean to handle log files correctly.

Following AVCs appeared in permissive mode:
----
type=PATH msg=audit(01/08/2016 09:53:49.083:654) : item=1 name=/var/log/stunnel.log inode=1321 dev=fc:03 mode=file,640 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:var_log_t:s0 nametype=CREATE 
type=PATH msg=audit(01/08/2016 09:53:49.083:654) : item=0 name=/var/log/ inode=495 dev=fc:03 mode=dir,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:var_log_t:s0 nametype=PARENT 
type=CWD msg=audit(01/08/2016 09:53:49.083:654) :  cwd=/root 
type=SYSCALL msg=audit(01/08/2016 09:53:49.083:654) : arch=x86_64 syscall=open success=yes exit=8 a0=0x7f75914b3b60 a1=O_WRONLY|O_CREAT|O_APPEND a2=0640 a3=0x4 items=2 ppid=8195 pid=5050 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=pts0 ses=9 comm=stunnel exe=/usr/bin/stunnel subj=system_u:system_r:stunnel_t:s0 key=(null) 
type=AVC msg=audit(01/08/2016 09:53:49.083:654) : avc:  denied  { append open } for  pid=5050 comm=stunnel name=stunnel.log dev=vda3 ino=1321 scontext=system_u:system_r:stunnel_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file 
type=AVC msg=audit(01/08/2016 09:53:49.083:654) : avc:  denied  { create } for  pid=5050 comm=stunnel name=stunnel.log scontext=system_u:system_r:stunnel_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file 
type=AVC msg=audit(01/08/2016 09:53:49.083:654) : avc:  denied  { add_name } for  pid=5050 comm=stunnel name=stunnel.log scontext=system_u:system_r:stunnel_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=dir 
type=AVC msg=audit(01/08/2016 09:53:49.083:654) : avc:  denied  { write } for  pid=5050 comm=stunnel name=log dev=vda3 ino=495 scontext=system_u:system_r:stunnel_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=dir 
type=AVC msg=audit(01/08/2016 09:53:49.083:654) : avc:  denied  { search } for  pid=5050 comm=stunnel name=log dev=vda3 ino=495 scontext=system_u:system_r:stunnel_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=dir 
----

Comment 4 errata-xmlrpc 2016-11-04 02:40:03 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-2283.html