policy_module(xen)

########################################
#
# Declarations
#

## <desc>
##	<p>
##	Determine whether xen can
##	use fusefs file systems.
##	</p>
## </desc>
gen_tunable(xen_use_fusefs, false)

## <desc>
##	<p>
##	Determine whether xen can
##	use nfs file systems.
##	</p>
## </desc>
gen_tunable(xen_use_nfs, false)

## <desc>
##	<p>
##	Determine whether xen can
##	use samba file systems.
##	</p>
## </desc>
gen_tunable(xen_use_samba, false)

type blktap_t;
type blktap_exec_t;
domain_type(blktap_t)
domain_entry_file(blktap_t, blktap_exec_t)
role system_r types blktap_t;

type blktap_runtime_t alias blktap_var_run_t;
files_runtime_file(blktap_runtime_t)

type evtchnd_t;
type evtchnd_exec_t;
init_daemon_domain(evtchnd_t, evtchnd_exec_t)

type evtchnd_var_log_t;
logging_log_file(evtchnd_var_log_t)

type evtchnd_runtime_t alias evtchnd_var_run_t;
files_runtime_file(evtchnd_runtime_t)

type xen_devpts_t;
term_pty(xen_devpts_t)
files_type(xen_devpts_t)

type xen_image_t; # customizable
files_type(xen_image_t)
dev_node(xen_image_t)

optional_policy(`
	virt_image(xen_image_t)
')

type xen_lock_t;
files_lock_file(xen_lock_t)

type xen_log_t;
typealias xen_log_t alias xend_var_log_t;
logging_log_file(xen_log_t)

type xen_runtime_t;
typealias xen_runtime_t alias xend_runtime_t;
files_runtime_file(xen_runtime_t)
files_mountpoint(xen_runtime_t)

type xen_state_t;
typealias xen_state_t alias xend_var_lib_t;
files_type(xen_state_t)
files_mountpoint(xen_state_t)

type xenctl_t;
files_type(xenctl_t)

type xenstored_t;
type xenstored_exec_t;
init_daemon_domain(xenstored_t, xenstored_exec_t)

type xenstored_tmp_t;
files_tmp_file(xenstored_tmp_t)

type xenstored_var_lib_t;
files_type(xenstored_var_lib_t)
files_mountpoint(xenstored_var_lib_t)

type xenstored_var_log_t;
logging_log_file(xenstored_var_log_t)

type xenstored_runtime_t alias xenstored_var_run_t;
files_runtime_file(xenstored_runtime_t)
init_daemon_runtime_file(xenstored_runtime_t, dir, "xenstored")

type xenconsoled_t;
type xenconsoled_exec_t;
init_daemon_domain(xenconsoled_t, xenconsoled_exec_t)

type xenconsoled_runtime_t alias xenconsoled_var_run_t;
files_runtime_file(xenconsoled_runtime_t)

type xm_t;
type xm_exec_t;
init_system_domain(xm_t, xm_exec_t)

########################################
#
# blktap local policy
#

allow blktap_t self:fifo_file rw_inherited_fifo_file_perms;

dev_read_sysfs(blktap_t)
dev_rw_xen(blktap_t)

files_read_etc_files(blktap_t)

logging_send_syslog_msg(blktap_t)

miscfiles_read_localization(blktap_t)

xen_stream_connect_xenstore(blktap_t)

#######################################
#
# evtchnd local policy
#

manage_dirs_pattern(evtchnd_t, evtchnd_var_log_t, evtchnd_var_log_t)
append_files_pattern(evtchnd_t, evtchnd_var_log_t, evtchnd_var_log_t)
create_files_pattern(evtchnd_t, evtchnd_var_log_t, evtchnd_var_log_t)
setattr_files_pattern(evtchnd_t, evtchnd_var_log_t, evtchnd_var_log_t)
logging_log_filetrans(evtchnd_t, evtchnd_var_log_t, { file dir })

manage_dirs_pattern(evtchnd_t, evtchnd_runtime_t, evtchnd_runtime_t)
manage_files_pattern(evtchnd_t, evtchnd_runtime_t, evtchnd_runtime_t)
manage_sock_files_pattern(evtchnd_t, evtchnd_runtime_t, evtchnd_runtime_t)
files_runtime_filetrans(evtchnd_t, evtchnd_runtime_t, { file sock_file dir })

########################################
#
# Xen console local policy
#

allow xenconsoled_t self:capability { dac_override fsetid ipc_lock };
allow xenconsoled_t self:process setrlimit;
allow xenconsoled_t self:unix_stream_socket create_stream_socket_perms;
allow xenconsoled_t self:fifo_file rw_fifo_file_perms;

allow xenconsoled_t xen_devpts_t:chr_file { rw_term_perms setattr_chr_file_perms };

manage_dirs_pattern(xenconsoled_t, xen_log_t, xen_log_t)
append_files_pattern(xenconsoled_t, xen_log_t, xen_log_t)
create_files_pattern(xenconsoled_t, xen_log_t, xen_log_t)
setattr_files_pattern(xenconsoled_t, xen_log_t, xen_log_t)

manage_files_pattern(xenconsoled_t, xenconsoled_runtime_t, xenconsoled_runtime_t)
manage_sock_files_pattern(xenconsoled_t, xenconsoled_runtime_t, xenconsoled_runtime_t)
files_runtime_filetrans(xenconsoled_t, xenconsoled_runtime_t, { file sock_file })

kernel_read_kernel_sysctls(xenconsoled_t)
kernel_write_xen_state(xenconsoled_t)
kernel_read_xen_state(xenconsoled_t)

dev_rw_xen(xenconsoled_t)
dev_filetrans_xen(xenconsoled_t)
dev_rw_sysfs(xenconsoled_t)

domain_dontaudit_ptrace_all_domains(xenconsoled_t)

files_read_etc_files(xenconsoled_t)
files_read_usr_files(xenconsoled_t)

fs_list_tmpfs(xenconsoled_t)
fs_manage_xenfs_dirs(xenconsoled_t)
fs_manage_xenfs_files(xenconsoled_t)

term_create_pty(xenconsoled_t, xen_devpts_t)
term_use_generic_ptys(xenconsoled_t)
term_use_console(xenconsoled_t)

init_use_fds(xenconsoled_t)
init_use_script_ptys(xenconsoled_t)

logging_search_logs(xenconsoled_t)

miscfiles_read_localization(xenconsoled_t)

xen_stream_connect_xenstore(xenconsoled_t)

########################################
#
# Xen store local policy
#

allow xenstored_t self:capability { dac_override ipc_lock sys_resource };
allow xenstored_t self:unix_stream_socket { accept listen };

manage_files_pattern(xenstored_t, xenstored_tmp_t, xenstored_tmp_t)
manage_dirs_pattern(xenstored_t, xenstored_tmp_t, xenstored_tmp_t)
files_tmp_filetrans(xenstored_t, xenstored_tmp_t, { file dir })

manage_dirs_pattern(xenstored_t, xenstored_runtime_t, xenstored_runtime_t)
manage_files_pattern(xenstored_t, xenstored_runtime_t, xenstored_runtime_t)
manage_sock_files_pattern(xenstored_t, xenstored_runtime_t, xenstored_runtime_t)
files_runtime_filetrans(xenstored_t, xenstored_runtime_t, { file sock_file dir })

manage_dirs_pattern(xenstored_t, xenstored_var_log_t, xenstored_var_log_t)
append_files_pattern(xenstored_t, xenstored_var_log_t, xenstored_var_log_t)
create_files_pattern(xenstored_t, xenstored_var_log_t, xenstored_var_log_t)
setattr_files_pattern(xenstored_t, xenstored_var_log_t, xenstored_var_log_t)
manage_sock_files_pattern(xenstored_t, xenstored_var_log_t, xenstored_var_log_t)
logging_log_filetrans(xenstored_t, xenstored_var_log_t, { sock_file file dir })

manage_dirs_pattern(xenstored_t, xenstored_var_lib_t, xenstored_var_lib_t)
manage_files_pattern(xenstored_t, xenstored_var_lib_t, xenstored_var_lib_t)
manage_sock_files_pattern(xenstored_t, xenstored_var_lib_t, xenstored_var_lib_t)
files_var_lib_filetrans(xenstored_t, xenstored_var_lib_t, { file dir sock_file })

stream_connect_pattern(xenstored_t, evtchnd_runtime_t, evtchnd_runtime_t, evtchnd_t)

kernel_write_xen_state(xenstored_t)
kernel_read_xen_state(xenstored_t)

corecmd_search_bin(xenstored_t)

dev_filetrans_xen(xenstored_t)
dev_rw_xen(xenstored_t)
dev_read_sysfs(xenstored_t)

files_read_etc_files(xenstored_t)
files_read_usr_files(xenstored_t)

fs_search_xenfs(xenstored_t)
fs_manage_xenfs_files(xenstored_t)
fs_mmap_xenfs_files(xenstored_t)

term_use_generic_ptys(xenstored_t)

init_use_fds(xenstored_t)
init_use_script_ptys(xenstored_t)

logging_send_syslog_msg(xenstored_t)

miscfiles_read_localization(xenstored_t)

xen_append_log(xenstored_t)

########################################
#
# xm local policy
#

allow xm_t self:capability { dac_override ipc_lock net_admin setpcap sys_nice sys_tty_config };
allow xm_t self:process { getcap getsched setcap setsched sigkill signal };
allow xm_t self:fifo_file rw_fifo_file_perms;
allow xm_t self:unix_stream_socket { accept connectto listen };
allow xm_t self:tcp_socket { accept listen };

allow xm_t xen_runtime_t:dir rw_dir_perms;

allow xm_t xen_lock_t:file manage_file_perms;
files_lock_filetrans(xm_t, xen_lock_t, file)

manage_files_pattern(xm_t, xen_log_t, xen_log_t)

manage_files_pattern(xm_t, xen_state_t, xen_state_t)
manage_fifo_files_pattern(xm_t, xen_state_t, xen_state_t)
manage_sock_files_pattern(xm_t, xen_state_t, xen_state_t)

manage_files_pattern(xm_t, xen_image_t, xen_image_t)
manage_blk_files_pattern(xm_t, xen_image_t, xen_image_t)
manage_lnk_files_pattern(xm_t, xen_image_t, xen_image_t)

read_files_pattern(xm_t, xenstored_runtime_t, xenstored_runtime_t)

xen_manage_image_dirs(xm_t)
xen_append_log(xm_t)
xen_stream_connect_xenstore(xm_t)

can_exec(xm_t, xm_exec_t)

kernel_request_load_module(xm_t)
kernel_read_system_state(xm_t)
kernel_read_network_state(xm_t)
kernel_read_kernel_sysctls(xm_t)
kernel_read_sysctl(xm_t)
kernel_read_xen_state(xm_t)
kernel_write_xen_state(xm_t)

corecmd_exec_bin(xm_t)
corecmd_exec_shell(xm_t)

corenet_all_recvfrom_netlabel(xm_t)
corenet_tcp_sendrecv_generic_if(xm_t)
corenet_tcp_sendrecv_generic_node(xm_t)

corenet_sendrecv_soundd_client_packets(xm_t)
corenet_tcp_connect_soundd_port(xm_t)

dev_read_rand(xm_t)
dev_read_urand(xm_t)
dev_read_sysfs(xm_t)

domain_use_interactive_fds(xm_t)

files_read_etc_runtime_files(xm_t)
files_read_etc_files(xm_t)
files_read_kernel_img(xm_t)
files_read_usr_files(xm_t)
files_search_runtime(xm_t)
files_search_var_lib(xm_t)
files_list_mnt(xm_t)
files_list_tmp(xm_t)

fs_getattr_all_fs(xm_t)
fs_manage_xenfs_dirs(xm_t)
fs_manage_xenfs_files(xm_t)
fs_search_auto_mountpoints(xm_t)

storage_raw_read_fixed_disk(xm_t)

term_use_all_terms(xm_t)

init_stream_connect_script(xm_t)
init_rw_script_stream_sockets(xm_t)
init_use_fds(xm_t)

logging_send_syslog_msg(xm_t)

miscfiles_read_localization(xm_t)

sysnet_dns_name_resolve(xm_t)
sysnet_domtrans_ifconfig(xm_t)

# for vif-bridge to write to /run/xen-hotplug/iptables
# maybe we need a different label for /run/xen-hotplug
udev_manage_runtime_files(xm_t)

userdom_dontaudit_search_user_home_content(xm_t)

tunable_policy(`xen_use_fusefs',`
	fs_manage_fusefs_dirs(xm_t)
	fs_manage_fusefs_files(xm_t)
	fs_read_fusefs_symlinks(xm_t)
')

tunable_policy(`xen_use_nfs',`
	fs_manage_nfs_dirs(xm_t)
	fs_manage_nfs_files(xm_t)
	fs_read_nfs_symlinks(xm_t)
')

tunable_policy(`xen_use_samba',`
	fs_manage_cifs_dirs(xm_t)
	fs_manage_cifs_files(xm_t)
	fs_read_cifs_symlinks(xm_t)
')

optional_policy(`
	qemu_domtrans(xm_t)
	qemu_signal(xm_t)
	qemu_stream_connect(xm_t)
	qemu_delete_runtime_sock_files(xm_t)
')

optional_policy(`
	iptables_domtrans(xm_t)
')

optional_policy(`
	cron_system_entry(xm_t, xm_exec_t)
')

optional_policy(`
	dbus_system_bus_client(xm_t)
')

optional_policy(`
	rpm_exec(xm_t)
')

optional_policy(`
	vhostmd_rw_tmpfs_files(xm_t)
	vhostmd_stream_connect(xm_t)
	vhostmd_dontaudit_rw_stream_connect(xm_t)
')

optional_policy(`
	virt_domtrans(xm_t)
	virt_manage_images(xm_t)
	virt_manage_config(xm_t)
	virt_stream_connect(xm_t)
')

optional_policy(`
	ssh_basic_client_template(xm, xm_t, system_r)

	kernel_read_xen_state(xm_ssh_t)
	kernel_write_xen_state(xm_ssh_t)

	files_search_tmp(xm_ssh_t)

	fs_manage_xenfs_dirs(xm_ssh_t)
	fs_manage_xenfs_files(xm_ssh_t)
')
