Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Macros for su domains.
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Authors:  Stephen Smalley <sds@epoch.ncsc.mil> and Timothy Fraser
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# su_domain(domain_prefix)
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Define a derived domain for the su program when executed
Chris PeBenito ab58ad
# by a user domain.
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# The type declaration for the executable type for this program is
Chris PeBenito ab58ad
# provided separately in domains/program/su.te. 
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
Chris PeBenito ab58ad
undefine(`su_restricted_domain')
Chris PeBenito ab58ad
undefine(`su_mini_domain')
Chris PeBenito ab58ad
undefine(`su_domain')
Chris PeBenito ab58ad
ifdef(`su.te', `
Chris PeBenito ab58ad
Chris PeBenito ab58ad
define(`su_restricted_domain', `
Chris PeBenito ab58ad
# Derived domain based on the calling user domain and the program.
Chris PeBenito ab58ad
type $1_su_t, domain, privlog, privrole, privuser, privowner, privfd, nscd_client_domain;
Chris PeBenito ab58ad
ifdef(`support_polyinstantiation', `
Chris PeBenito ab58ad
typeattribute $1_su_t mlsfileread;
Chris PeBenito ab58ad
typeattribute $1_su_t mlsfilewrite;
Chris PeBenito ab58ad
typeattribute $1_su_t mlsfileupgrade;
Chris PeBenito ab58ad
typeattribute $1_su_t mlsfiledowngrade;
Chris PeBenito ab58ad
typeattribute $1_su_t mlsprocsetsl;
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# for SSP
Chris PeBenito ab58ad
allow $1_su_t urandom_device_t:chr_file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Transition from the user domain to this domain.
Chris PeBenito ab58ad
domain_auto_trans($1_t, su_exec_t, $1_su_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_su_t sbin_t:dir search;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
uses_shlib($1_su_t)
Chris PeBenito ab58ad
allow $1_su_t etc_t:file { getattr read };
Chris PeBenito ab58ad
read_locale($1_su_t)
Chris PeBenito ab58ad
read_sysctl($1_su_t)
Chris PeBenito ab58ad
allow $1_su_t self:unix_dgram_socket { connect create write };
Chris PeBenito ab58ad
allow $1_su_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito ab58ad
allow $1_su_t self:fifo_file rw_file_perms;
Chris PeBenito ab58ad
allow $1_su_t proc_t:dir search;
Chris PeBenito ab58ad
allow $1_su_t proc_t:lnk_file read;
Chris PeBenito ab58ad
r_dir_file($1_su_t, self)
Chris PeBenito ab58ad
allow $1_su_t proc_t:file read;
Chris PeBenito ab58ad
allow $1_su_t self:process { setsched setrlimit };
Chris PeBenito ab58ad
allow $1_su_t device_t:dir search;
Chris PeBenito ab58ad
allow $1_su_t self:process { fork sigchld };
Chris PeBenito ab58ad
nsswitch_domain($1_su_t)
Chris PeBenito ab58ad
r_dir_file($1_su_t, selinux_config_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
dontaudit $1_su_t shadow_t:file { getattr read };
Chris PeBenito ab58ad
dontaudit $1_su_t home_root_t:dir search;
Chris PeBenito ab58ad
dontaudit $1_su_t init_t:fd use;
Chris PeBenito ab58ad
allow $1_su_t var_lib_t:dir search;
Chris PeBenito ab58ad
allow $1_t $1_su_t:process signal;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`crond.te', `
Chris PeBenito ab58ad
allow $1_su_t crond_t:fifo_file read;
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Use capabilities.
Chris PeBenito ab58ad
allow $1_su_t self:capability { setuid setgid net_bind_service chown dac_override fowner sys_nice sys_resource audit_control audit_write };
Chris PeBenito ab58ad
dontaudit $1_su_t self:capability sys_tty_config;
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Caused by su - init scripts
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
dontaudit $1_su_t initrc_devpts_t:chr_file { getattr ioctl };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# By default, revert to the calling domain when a shell is executed.
Chris PeBenito ab58ad
domain_auto_trans($1_su_t, shell_exec_t, $1_t)
Chris PeBenito ab58ad
allow $1_su_t bin_t:dir search;
Chris PeBenito ab58ad
allow $1_su_t bin_t:lnk_file read;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# But also allow transitions to unprivileged user domains.
Chris PeBenito ab58ad
domain_trans($1_su_t, shell_exec_t, unpriv_userdomain)
Chris PeBenito ab58ad
can_setexec($1_su_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Get security decisions
Chris PeBenito ab58ad
can_getsecurity($1_su_t)
Chris PeBenito ab58ad
r_dir_file($1_su_t, default_context_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_su_t privfd:fd use;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Write to utmp.
Chris PeBenito ab58ad
allow $1_su_t { var_t var_run_t }:dir search;
Chris PeBenito ab58ad
allow $1_su_t initrc_var_run_t:file rw_file_perms;
Chris PeBenito ab58ad
can_kerberos($1_su_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`chkpwd.te', `
Chris PeBenito ab58ad
domain_auto_trans($1_su_t, chkpwd_exec_t, $2_chkpwd_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_su_t self:netlink_audit_socket { nlmsg_relay create_netlink_socket_perms };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
') dnl end su_restricted_domain
Chris PeBenito ab58ad
Chris PeBenito ab58ad
define(`su_mini_domain', `
Chris PeBenito ab58ad
su_restricted_domain($1,$1)
Chris PeBenito ab58ad
if(!secure_mode)
Chris PeBenito ab58ad
{
Chris PeBenito ab58ad
	# if we are not in secure mode then we can transition to sysadm_t
Chris PeBenito ab58ad
	domain_trans($1_su_t, shell_exec_t, sysadm_t)
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Relabel ttys and ptys.
Chris PeBenito ab58ad
allow $1_su_t device_t:dir { getattr read search };
Chris PeBenito ab58ad
allow $1_su_t { ttyfile ptyfile }:chr_file { relabelfrom relabelto };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Close and re-open ttys and ptys to get the fd into the correct domain.
Chris PeBenito ab58ad
allow $1_su_t { ttyfile ptyfile }:chr_file { read write };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
')dnl end su_mini_domain
Chris PeBenito ab58ad
Chris PeBenito ab58ad
define(`su_domain', `
Chris PeBenito ab58ad
su_mini_domain($1)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Inherit and use descriptors from gnome-pty-helper.
Chris PeBenito ab58ad
ifdef(`gnome-pty-helper.te', `allow $1_su_t $1_gph_t:fd use;')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# The user role is authorized for this domain.
Chris PeBenito ab58ad
role $1_r types $1_su_t;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Write to the user domain tty.
Chris PeBenito ab58ad
access_terminal($1_su_t, $1)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_su_t { home_root_t $1_home_dir_t }:dir search;
Chris PeBenito ab58ad
allow $1_su_t $1_home_t:file create_file_perms;
Chris PeBenito ab58ad
ifdef(`user_canbe_sysadm', `
Chris PeBenito ab58ad
allow $1_su_t home_dir_type:dir { search write };
Chris PeBenito ab58ad
', `
Chris PeBenito ab58ad
dontaudit $1_su_t home_dir_type:dir { search write };
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_su_t autofs_t:dir { search getattr };
Chris PeBenito ab58ad
if (use_nfs_home_dirs) {
Chris PeBenito ab58ad
allow $1_su_t nfs_t:dir search;
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
if (use_samba_home_dirs) {
Chris PeBenito ab58ad
allow $1_su_t cifs_t:dir search;
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`support_polyinstantiation', `
Chris PeBenito ab58ad
# Su can polyinstantiate
Chris PeBenito ab58ad
polyinstantiater($1_su_t)
Chris PeBenito ab58ad
# Su has to unmount polyinstantiated directories (like home)
Chris PeBenito ab58ad
# that should not be polyinstantiated under the new user
Chris PeBenito ab58ad
allow $1_su_t fs_t:filesystem unmount;
Chris PeBenito ab58ad
# Su needs additional permission to mount over a previous mount
Chris PeBenito ab58ad
allow $1_su_t polymember:dir mounton;
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Modify .Xauthority file (via xauth program).
Chris PeBenito ab58ad
ifdef(`xauth.te', `
Chris PeBenito ab58ad
file_type_auto_trans($1_su_t, staff_home_dir_t, staff_xauth_home_t, file)
Chris PeBenito ab58ad
file_type_auto_trans($1_su_t, user_home_dir_t, user_xauth_home_t, file)
Chris PeBenito ab58ad
file_type_auto_trans($1_su_t, sysadm_home_dir_t, sysadm_xauth_home_t, file)
Chris PeBenito ab58ad
domain_auto_trans($1_su_t, xauth_exec_t, $1_xauth_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`cyrus.te', `
Chris PeBenito ab58ad
allow $1_su_t cyrus_var_lib_t:dir search;
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
ifdef(`ssh.te', `
Chris PeBenito ab58ad
# Access sshd cookie files.
Chris PeBenito ab58ad
allow $1_su_t sshd_tmp_t:dir rw_dir_perms;
Chris PeBenito ab58ad
allow $1_su_t sshd_tmp_t:file rw_file_perms;
Chris PeBenito ab58ad
file_type_auto_trans($1_su_t, sshd_tmp_t, $1_tmp_t)
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_su_t var_lib_t:dir search;
Chris PeBenito ab58ad
dontaudit $1_su_t init_t:fd use;
Chris PeBenito ab58ad
')dnl end su_domain
Chris PeBenito ab58ad
Chris PeBenito ab58ad
', `
Chris PeBenito ab58ad
Chris PeBenito ab58ad
define(`su_domain',`')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad