Bug 1296238

Summary: Correct selinux context for stunnel logging
Product: Red Hat Enterprise Linux 6 Reporter: Zdenek Pytela <zpytela>
Component: selinux-policyAssignee: Miroslav Grepl <mgrepl>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.7CC: dwalsh, lvrabec, mgrepl, mmalik, plautrba, pvrabec, redhat-bugzilla, robert.scheck, ssekidde
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.7.19-288.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1296851 1297325 (view as bug list) Environment:
Last Closed: 2016-05-10 20:04:20 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:
Embargoed:
Bug Depends On:    
Bug Blocks: 1297325, 1333033    

Description Zdenek Pytela 2016-01-06 16:40:43 UTC
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):
stunnel-4.29-3.el6_6.1.x86_64
selinux-policy-3.7.19-279.el6_7.8.noarch


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.

Comment 2 Miroslav Grepl 2016-01-07 09:44:47 UTC
Ok we can provide a new type - stunnel_log_t for these cases.

Comment 3 Milos Malik 2016-01-08 08:55:24 UTC
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 Milos Malik 2016-01-08 08:56:52 UTC
selinux-policy in RHEL-7 does not define any type for stunnel log files either.

Comment 12 errata-xmlrpc 2016-05-10 20:04:20 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-0763.html