policy_module(uml, 2.3.0)

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

attribute_role uml_roles;

type uml_t;
type uml_exec_t; # customizable
typealias uml_t alias { user_uml_t staff_uml_t sysadm_uml_t };
typealias uml_t alias { auditadm_uml_t secadm_uml_t };
userdom_user_application_domain(uml_t, uml_exec_t)
role uml_roles types uml_t;

type uml_ro_t; # customizable
typealias uml_ro_t alias { user_uml_ro_t staff_uml_ro_t sysadm_uml_ro_t };
typealias uml_ro_t alias { auditadm_uml_ro_t secadm_uml_ro_t };
userdom_user_home_content(uml_ro_t)

type uml_rw_t;
typealias uml_rw_t alias { user_uml_rw_t staff_uml_rw_t sysadm_uml_rw_t };
typealias uml_rw_t alias { auditadm_uml_rw_t secadm_uml_rw_t };
userdom_user_home_content(uml_rw_t)

type uml_tmp_t;
typealias uml_tmp_t alias { user_uml_tmp_t staff_uml_tmp_t sysadm_uml_tmp_t };
typealias uml_tmp_t alias { auditadm_uml_tmp_t secadm_uml_tmp_t };
userdom_user_tmp_file(uml_tmp_t)

type uml_tmpfs_t;
typealias uml_tmpfs_t alias { user_uml_tmpfs_t staff_uml_tmpfs_t sysadm_uml_tmpfs_t };
typealias uml_tmpfs_t alias { auditadm_uml_tmpfs_t secadm_uml_tmpfs_t };
userdom_user_tmpfs_file(uml_tmpfs_t)

type uml_devpts_t;
typealias uml_devpts_t alias { user_uml_devpts_t staff_uml_devpts_t sysadm_uml_devpts_t };
typealias uml_devpts_t alias { auditadm_uml_devpts_t secadm_uml_devpts_t };
term_pty(uml_devpts_t)
ubac_constrained(uml_devpts_t)

type uml_switch_t;
type uml_switch_exec_t;
init_daemon_domain(uml_switch_t, uml_switch_exec_t)

type uml_switch_var_run_t;
files_pid_file(uml_switch_var_run_t)

########################################
#
# Local policy
#

allow uml_t self:process signal_perms;
allow uml_t self:fifo_file rw_fifo_file_perms;
allow uml_t self:unix_stream_socket create_stream_socket_perms;
allow uml_t self:tcp_socket { accept listen };
allow uml_t self:tun_socket create;
allow uml_t self:unix_dgram_socket { create_socket_perms sendto };

allow uml_t uml_devpts_t:chr_file { rw_file_perms setattr_chr_file_perms };
term_create_pty(uml_t, uml_devpts_t)

manage_dirs_pattern(uml_t, uml_tmp_t, uml_tmp_t)
manage_files_pattern(uml_t, uml_tmp_t, uml_tmp_t)
files_tmp_filetrans(uml_t, uml_tmp_t, { file dir })

manage_files_pattern(uml_t, uml_tmpfs_t, uml_tmpfs_t)
manage_lnk_files_pattern(uml_t, uml_tmpfs_t, uml_tmpfs_t)
manage_fifo_files_pattern(uml_t, uml_tmpfs_t, uml_tmpfs_t)
manage_sock_files_pattern(uml_t, uml_tmpfs_t, uml_tmpfs_t)
fs_tmpfs_filetrans(uml_t, uml_tmpfs_t, { file lnk_file sock_file fifo_file })

allow uml_t uml_ro_t:dir list_dir_perms;
allow uml_t uml_ro_t:file read_file_perms;
allow uml_t uml_ro_t:lnk_file read_lnk_file_perms;

manage_dirs_pattern(uml_t, uml_rw_t, uml_rw_t)
manage_files_pattern(uml_t, uml_rw_t, uml_rw_t)
manage_lnk_files_pattern(uml_t, uml_rw_t, uml_rw_t)
manage_fifo_files_pattern(uml_t, uml_rw_t, uml_rw_t)
manage_sock_files_pattern(uml_t, uml_rw_t, uml_rw_t)
userdom_user_home_dir_filetrans(uml_t, uml_rw_t, dir, ".uml")

can_exec(uml_t, { uml_exec_t uml_tmp_t uml_tmpfs_t })

kernel_read_system_state(uml_t)
kernel_write_proc_files(uml_t)

corecmd_exec_bin(uml_t)

corenet_all_recvfrom_netlabel(uml_t)
corenet_tcp_sendrecv_generic_if(uml_t)
corenet_tcp_sendrecv_generic_node(uml_t)
corenet_tcp_sendrecv_all_ports(uml_t)

corenet_sendrecv_all_client_packets(uml_t)
corenet_tcp_connect_all_ports(uml_t)

corenet_rw_tun_tap_dev(uml_t)

domain_use_interactive_fds(uml_t)

files_dontaudit_read_etc_runtime_files(uml_t)

fs_getattr_all_fs(uml_t)
fs_search_auto_mountpoints(uml_t)

auth_use_nsswitch(uml_t)

init_read_utmp(uml_t)
init_dontaudit_write_utmp(uml_t)

libs_exec_lib_files(uml_t)

# Inherit and use descriptors from newrole.
seutil_use_newrole_fds(uml_t)

# Use the network.
sysnet_read_config(uml_t)

userdom_use_inherited_user_terminals(uml_t)
userdom_attach_admin_tun_iface(uml_t)

tunable_policy(`use_nfs_home_dirs',`
	fs_manage_nfs_dirs(uml_t)
	fs_manage_nfs_files(uml_t)
	fs_manage_nfs_named_pipes(uml_t)
	fs_manage_nfs_symlinks(uml_t)
')

tunable_policy(`use_samba_home_dirs',`
	fs_manage_cifs_dirs(uml_t)
	fs_manage_cifs_files(uml_t)
	fs_manage_cifs_named_pipes(uml_t)
	fs_manage_cifs_symlinks(uml_t)
')

optional_policy(`
	virt_attach_tun_iface(uml_t)
')

########################################
#
# Switch local policy
#

dontaudit uml_switch_t self:capability sys_tty_config;
allow uml_switch_t self:process signal_perms;
allow uml_switch_t self:unix_stream_socket { accept listen };

manage_files_pattern(uml_switch_t, uml_switch_var_run_t, uml_switch_var_run_t)
manage_sock_files_pattern(uml_switch_t, uml_switch_var_run_t, uml_switch_var_run_t)
files_pid_filetrans(uml_switch_t, uml_switch_var_run_t, file)

kernel_read_kernel_sysctls(uml_switch_t)
kernel_list_proc(uml_switch_t)
kernel_read_proc_symlinks(uml_switch_t)

dev_read_sysfs(uml_switch_t)

domain_use_interactive_fds(uml_switch_t)

fs_getattr_all_fs(uml_switch_t)
fs_search_auto_mountpoints(uml_switch_t)

term_dontaudit_use_console(uml_switch_t)

init_use_fds(uml_switch_t)
init_use_script_ptys(uml_switch_t)

logging_send_syslog_msg(uml_switch_t)

userdom_dontaudit_use_unpriv_user_fds(uml_switch_t)
userdom_dontaudit_search_user_home_dirs(uml_switch_t)

optional_policy(`
	seutil_sigchld_newrole(uml_switch_t)
')

optional_policy(`
	udev_read_db(uml_switch_t)
')
