Bug 697812

Summary: sudo -r ... cannot read /etc/selinux/targeted/contexts/default_type
Product: Red Hat Enterprise Linux 6 Reporter: Milos Malik <mmalik>
Component: selinux-policyAssignee: Miroslav Grepl <mgrepl>
Status: CLOSED ERRATA QA Contact: Karel Srot <ksrot>
Severity: medium Docs Contact:
Priority: high    
Version: 6.1CC: dwalsh, ksrot, mgrepl
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.7.19-87.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-05-19 12:27:48 UTC Type: ---
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 2011-04-19 11:01:34 UTC
Description of problem:


Version-Release number of selected component (if applicable):
selinux-policy-minimum-3.7.19-85.el6.noarch
selinux-policy-doc-3.7.19-85.el6.noarch
selinux-policy-targeted-3.7.19-85.el6.noarch
selinux-policy-3.7.19-85.el6.noarch
selinux-policy-mls-3.7.19-85.el6.noarch

How reproducible:
always

Steps to Reproduce:
1) create an staff_u user
2) set a password for the user
3) allow the user to run w via sudo
( echo "USERNAME ALL = (ALL) /usr/bin/w" >> /etc/sudoers )
4) log in as the user (works in both SSH session and X session)
5) run "sudo -r unconfined_r w" (role change from staff_r to unconfined_r is allowed)
$ sudo -r unconfined_r w
[sudo] password for sudotester: 
sudo: unable to get default type for role unconfined_r
sudo: unable to execute /usr/bin/w: Invalid argument

6) run "sudo -r guest_r w" (role change from staff_r to guest_r is not allowed)
$ sudo -r guest_r w
[sudo] password for sudotester: 
sudo: unable to get default type for role guest_r
sudo: unable to execute /usr/bin/w: Invalid argument


Actual results:
----
time->Tue Apr 19 06:55:05 2011
type=SYSCALL msg=audit(1303210505.672:41918): arch=c000003e syscall=137 success=no exit=-13 a0=7fcd0ce368d0 a1=7fff5ac75d40 a2=7fff5ac75cb0 a3=7fff5ac75a10 items=0 ppid=4800 pid=4821 auid=501 uid=0 gid=502 euid=0 suid=0 fsuid=0 egid=502 sgid=502 fsgid=502 tty=pts2 ses=32 comm="sudo" exe="/usr/bin/sudo" subj=staff_u:staff_r:staff_sudo_t:s0 key=(null)
type=AVC msg=audit(1303210505.672:41918): avc:  denied  { getattr } for  pid=4821 comm="sudo" name="/" dev=devpts ino=1 scontext=staff_u:staff_r:staff_sudo_t:s0 tcontext=system_u:object_r:devpts_t:s0 tclass=filesystem
----
time->Tue Apr 19 06:55:05 2011
type=SYSCALL msg=audit(1303210505.752:41922): arch=c000003e syscall=2 success=no exit=-13 a0=7fcd0ce54d80 a1=0 a2=1b6 a3=0 items=0 ppid=4821 pid=4825 auid=501 uid=0 gid=502 euid=0 suid=0 fsuid=0 egid=502 sgid=502 fsgid=502 tty=pts2 ses=32 comm="sudo" exe="/usr/bin/sudo" subj=staff_u:staff_r:staff_sudo_t:s0 key=(null)
type=AVC msg=audit(1303210505.752:41922): avc:  denied  { read } for  pid=4825 comm="sudo" name="default_type" dev=dm-0 ino=132104 scontext=staff_u:staff_r:staff_sudo_t:s0 tcontext=system_u:object_r:default_context_t:s0 tclass=file
----

Expected results:
no AVCs

Comment 2 Miroslav Grepl 2011-04-19 12:25:26 UTC
Did yo try to allow staff_sudo_t to read default_context_t type?

Comment 3 Milos Malik 2011-04-19 12:45:39 UTC
Steps 5 and 6 described in comment#0 lead to 4 AVCs in enforcing mode. "Actual results" section shows the unique ones.

Comment 4 Milos Malik 2011-04-19 13:11:43 UTC
Following module solved my problem. I don't see any AVCs in enforcing mode when running the automated test.

module mypol 1.0;

require {
        type devpts_t;
        type default_context_t;
        type staff_sudo_t;
        class file { read getattr open };
        class filesystem getattr;
}

#============= staff_sudo_t ==============
allow staff_sudo_t default_context_t:file { read getattr open };
allow staff_sudo_t devpts_t:filesystem getattr;

Comment 5 Daniel Walsh 2011-04-19 15:01:01 UTC
Looks good to me.

Comment 6 Miroslav Grepl 2011-04-19 19:27:04 UTC
I will add. It works also for me.

Comment 8 Miroslav Grepl 2011-04-20 14:54:06 UTC
Fixed in selinux-policy-3.7.19-87.el6

Comment 11 errata-xmlrpc 2011-05-19 12:27:48 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0526.html