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