Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 455084 - sec-policy/selinux-sudo should allow access to default_type
Summary: sec-policy/selinux-sudo should allow access to default_type
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: SELinux (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: SE Linux Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-02 03:56 UTC by Stan Sander
Modified: 2013-02-09 08:36 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stan Sander 2013-02-02 03:56:48 UTC
Currently sec-policy/selinux-sudo does not allow access to /etc/selinux/strict/contexts/default_type.  This causes sudo -s or sudo -i to fail if the type is not specified with the -t switch.

iax /home/stan $sudo -s
stan's password:  
sudo: unable to get default type for role sysadm_r
sudo: unable to execute /bin/bash: Invalid argument

iax /home/stan $sudo -st sysadm_t
iax /home/stan #

Feb  1 20:21:15 iax kernel: type=1400 audit(1359775275.969:63): avc:  denied  { read } for  pid=3176 comm="sudo" name="default_type" dev="sda3" ino=6311437 scontext=stan:staff_r:staff_sudo_t tcontext=system_u:object_r:default_context_t tclass=file

sesearch shows the necessary permissions are there for the directory, but not the file.  

allow staff_sudo_t default_context_t : dir { getattr search open } ;

This makes me think the lack of file class permissions is an oversight.  Assuming the default type is what I want, I shouldn't have to specify the type on the command line.
Comment 1 Sven Vermeulen (RETIRED) gentoo-dev 2013-02-07 19:52:47 UTC
Hi Stan,

I'm not able to reproduce this here...

"""
swift@hpl ~ $ sudo -s
bash: /root/.bashrc: Permission denied
hpl swift # id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video) context=staff_u:staff_r:staff_t
hpl swift # 
"""

I agree that it is very likely that sudo needs to read the file, but the behavior is important as well. Adding seutil_read_default_contexts(sudodomain) doesn't change anything here.
Comment 2 Stan Sander 2013-02-08 02:07:17 UTC
hmmm.....interesting.  This is on an x86 stable profile so the version is sec-policy/selinux-sudo-2.20120725-r9  Not sure if that makes any difference.  Also interesting that staff_t CAN read the file, but staff_sudo_t can't.  Also staff_t has more perms than the staff_sudo_t, but that's probably not significant.

#sesearch -s staff_t -t default_context_t -ACd
Found 2 semantic av rules:
   allow staff_t default_context_t : file { ioctl read getattr lock open } ; 
   allow staff_t default_context_t : dir { ioctl read getattr lock search open } ; 

sesearch -s staff_sudo_t -t default_context_t -ACd
Found 1 semantic av rules:
   allow staff_sudo_t default_context_t : dir { getattr search open } ; 


After a successful sudo -st sysadm_t here is what I show for id:

#id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),11(floppy),26(tape),27(video) context=stan:sysadm_r:sysadm_t

which differs slightly from yours in that your id still showed that you did not get sysadm_r and sysadm_t even though you are root.  Here are the relevant SELinux user definitions:

root            staff_r sysadm_r system_r
staff_u         staff_r sysadm_r
stan            staff_r sysadm_r system_r

Could I be missing something in my SELinux user definition, or did something not load up correctly in my policy somehow?  I just don't get what could be causing the difference.
Comment 3 Sven Vermeulen (RETIRED) gentoo-dev 2013-02-08 18:53:18 UTC
It might have to do with the sudoers file (do you have any type/role declarations in it?). It is normal that the staff_sudo_t is much less privileged than staff_t: it is a "jumping domain" so that, if staff_t executes sudo_t, then staff_sudo_t is used which then automatically transforms back to staff_t on executing binaries.

Without such a jumping domain, the policies don't know if sudo_t needs to transition back to staff_t or sysadm_t or another domain.
Comment 4 Stan Sander 2013-02-09 01:35:43 UTC
Yes, I do have a sysadm_r declaration for my account, but no type is specified.
Comment 5 Stan Sander 2013-02-09 01:43:50 UTC
Sorry hit submit too quickly.

I added the type=sysadm_t to the configuration and it now functions the way I intended/want.  Seems that in times past it worked OK without the type being declared in the config, but I won't swear to it!!

Anyways, probably fair to mark this as WONTFIX.
Comment 6 Sven Vermeulen (RETIRED) gentoo-dev 2013-02-09 08:36:05 UTC
Yes, and who knows the fix gets in upstream later anyhow. But for now, I'd be hard for me to "defend" the fix.