Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# Macros for X client programs ($2 etc)
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# Author: Russell Coker <russell@coker.com.au>
Chris PeBenito 0fbfa5
# Based on the work of Stephen Smalley <sds@epoch.ncsc.mil>
Chris PeBenito 0fbfa5
# and Timothy Fraser 
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
define(`xsession_domain', `
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Connect to xserver
Chris PeBenito 0fbfa5
can_unix_connect($1_t, $2_xserver_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# /tmp/.ICE_unix
Chris PeBenito 0fbfa5
allow $1_t $2_xserver_tmp_t:dir search;
Chris PeBenito 0fbfa5
allow $1_t $2_xserver_tmp_t:sock_file rw_file_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Stat /tmp/.X0-lock
Chris PeBenito 0fbfa5
allow $1_t $2_xserver_tmp_t:file getattr;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Signal Xserver
Chris PeBenito 0fbfa5
allow $1_t $2_xserver_t:process signal;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Use file descriptors created by each other.
Chris PeBenito 0fbfa5
allow $1_t $2_xserver_t:fd use;
Chris PeBenito 0fbfa5
allow $2_xserver_t $1_t:fd use;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Xserver read/write parent shm
Chris PeBenito 0fbfa5
allow $2_xserver_t $1_t:shm rw_shm_perms;
Chris PeBenito 0fbfa5
allow $2_xserver_t $1_tmpfs_t:file rw_file_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Parent read xserver shm
Chris PeBenito 0fbfa5
allow $1_t $2_xserver_t:shm r_shm_perms;
Chris PeBenito 0fbfa5
allow $1_t $2_xserver_tmpfs_t:file r_file_perms;
Chris PeBenito 0fbfa5
')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# x_client_domain(domain_prefix)
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# Define a derived domain for an X program when executed by
Chris PeBenito 0fbfa5
# a user domain.  
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# The type declaration for the executable type for this program ($2_exec_t)
Chris PeBenito 0fbfa5
# must be provided separately!
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
# The first parameter is the base name for the domain/role (EG user or sysadm)
Chris PeBenito 0fbfa5
# The second parameter is the program name (EG $2)
Chris PeBenito 0fbfa5
# The third parameter is the attributes for the domain (if any)
Chris PeBenito 0fbfa5
#
Chris PeBenito 0fbfa5
define(`x_client_domain',`
Chris PeBenito 0fbfa5
# Derived domain based on the calling user domain and the program.
Chris PeBenito 0fbfa5
type $1_$2_t, domain, nscd_client_domain $3;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
ifelse(index(`$3', `transitionbool'), -1, `
Chris PeBenito 0fbfa5
domain_auto_trans($1_t, $2_exec_t, $1_$2_t)
Chris PeBenito 0fbfa5
can_exec($1_$2_t, $2_exec_t)
Chris PeBenito 0fbfa5
', `
Chris PeBenito 0fbfa5
# Only do it once
Chris PeBenito 0fbfa5
ifelse($1, user, `
Chris PeBenito 0fbfa5
bool disable_$2 false;
Chris PeBenito 0fbfa5
')
Chris PeBenito 0fbfa5
# Transition from the user domain to the derived domain.
Chris PeBenito 0fbfa5
if (! disable_$2) {
Chris PeBenito 0fbfa5
domain_auto_trans($1_t, $2_exec_t, $1_$2_t)
Chris PeBenito 0fbfa5
can_exec($1_$2_t, $2_exec_t)
Chris PeBenito 0fbfa5
}
Chris PeBenito 0fbfa5
')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# The user role is authorized for this domain.
Chris PeBenito 0fbfa5
role $1_r types $1_$2_t;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# This domain is granted permissions common to most domains (including can_net)
Chris PeBenito 0fbfa5
can_network($1_$2_t)
Chris PeBenito 0fbfa5
can_ypbind($1_$2_t)
Chris PeBenito 0fbfa5
allow $1_$2_t self:process { fork signal_perms getsched };
Chris PeBenito 0fbfa5
allow $1_$2_t self:unix_dgram_socket create_socket_perms;
Chris PeBenito 0fbfa5
allow $1_$2_t self:unix_stream_socket { connectto create_stream_socket_perms };
Chris PeBenito 0fbfa5
allow $1_$2_t self:fifo_file rw_file_perms;
Chris PeBenito 0fbfa5
allow $1_$2_t etc_runtime_t:file { getattr read };
Chris PeBenito 0fbfa5
allow $1_$2_t etc_t:lnk_file read;
Chris PeBenito 0fbfa5
allow $1_$2_t fs_t:filesystem getattr;
Chris PeBenito 0fbfa5
access_terminal($1_$2_t, $1)
Chris PeBenito 0fbfa5
read_locale($1_$2_t)
Chris PeBenito 0fbfa5
r_dir_file($1_$2_t, readable_t)
Chris PeBenito 0fbfa5
allow $1_$2_t proc_t:dir search;
Chris PeBenito 0fbfa5
allow $1_$2_t proc_t:lnk_file read;
Chris PeBenito 0fbfa5
allow $1_$2_t self:dir search;
Chris PeBenito 0fbfa5
allow $1_$2_t self:lnk_file read;
Chris PeBenito 0fbfa5
read_sysctl($1_$2_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
ifdef(`xauth.te',`
Chris PeBenito 0fbfa5
allow $1_$2_t $1_xauth_home_t:file { getattr read };
Chris PeBenito 0fbfa5
')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Allow the user domain to send any signal to the $2 process.
Chris PeBenito 0fbfa5
allow $1_t $1_$2_t:process signal_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Allow the user domain to read the /proc/PID directory for 
Chris PeBenito 0fbfa5
# the $2 process.
Chris PeBenito 0fbfa5
allow $1_t $1_$2_t:dir r_dir_perms;
Chris PeBenito 0fbfa5
allow $1_t $1_$2_t:notdevfile_class_set r_file_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Allow use of /dev/zero by ld.so.
Chris PeBenito 0fbfa5
allow $1_$2_t device_t:dir search;
Chris PeBenito 0fbfa5
allow $1_$2_t zero_device_t:chr_file rw_file_perms;
Chris PeBenito 0fbfa5
allow $1_$2_t zero_device_t:chr_file x_file_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# allow using shared libraries and running programs
Chris PeBenito 0fbfa5
uses_shlib($1_$2_t)
Chris PeBenito 0fbfa5
allow $1_$2_t { bin_t sbin_t }:dir search;
Chris PeBenito 0fbfa5
allow $1_$2_t bin_t:lnk_file read;
Chris PeBenito 0fbfa5
can_exec($1_$2_t, { shell_exec_t bin_t })
Chris PeBenito 0fbfa5
allow $1_$2_t etc_t:file { getattr read };
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Inherit and use descriptors from gnome-pty-helper.
Chris PeBenito 0fbfa5
ifdef(`gnome-pty-helper.te', `allow $1_$2_t $1_gph_t:fd use;')
Chris PeBenito 0fbfa5
allow $1_$2_t privfd:fd use;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# for .xsession-errors
Chris PeBenito 0fbfa5
dontaudit $1_$2_t $1_home_t:file write;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# for X over a ssh tunnel
Chris PeBenito 0fbfa5
ifdef(`ssh.te', `
Chris PeBenito 0fbfa5
can_tcp_connect($1_$2_t, sshd_t)
Chris PeBenito 0fbfa5
')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Read the home directory, e.g. for .Xauthority and to get to config files
Chris PeBenito 0fbfa5
allow $1_$2_t home_root_t:dir { search getattr };
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Use a separate type for tmpfs/shm pseudo files.
Chris PeBenito 0fbfa5
tmpfs_domain($1_$2)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
allow $1_$2_t self:shm create_shm_perms;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# allow X client to read all font files
Chris PeBenito 0fbfa5
r_dir_file($1_$2_t, fonts_t)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# Allow connections to X server.
Chris PeBenito 0fbfa5
ifdef(`xserver.te', `
Chris PeBenito 0fbfa5
allow $1_$2_t tmp_t:dir search;
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
ifdef(`xdm.te', `
Chris PeBenito 0fbfa5
xsession_domain($1_$2, xdm)
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
# for when /tmp/.X11-unix is created by the system
Chris PeBenito 0fbfa5
allow $1_$2_t xdm_t:fifo_file rw_file_perms;
Chris PeBenito 0fbfa5
allow $1_$2_t xdm_tmp_t:dir search;
Chris PeBenito 0fbfa5
allow $1_$2_t xdm_tmp_t:sock_file { read write };
Chris PeBenito 0fbfa5
allow $1_$2_t xdm_t:fd use;
Chris PeBenito 0fbfa5
dontaudit $1_$2_t xdm_t:tcp_socket { read write };
Chris PeBenito 0fbfa5
')
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
ifdef(`startx.te', `
Chris PeBenito 0fbfa5
xsession_domain($1_$2, $1)
Chris PeBenito 0fbfa5
')dnl end startx
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
')dnl end xserver
Chris PeBenito 0fbfa5
Chris PeBenito 0fbfa5
')dnl end x_client macro