policy_module(ksmtuned, 1.1.1)

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

## <desc>
## <p>
## Allow ksmtuned to use nfs file systems
## </p>
## </desc>
gen_tunable(ksmtuned_use_nfs, false)

## <desc>
## <p>
## Allow ksmtuned to use cifs/Samba file systems
## </p>
## </desc>
gen_tunable(ksmtuned_use_cifs, false)

type ksmtuned_t;
type ksmtuned_exec_t;
init_daemon_domain(ksmtuned_t, ksmtuned_exec_t)

type ksmtuned_unit_file_t;
systemd_unit_file(ksmtuned_unit_file_t)

type ksmtuned_initrc_exec_t;
init_script_file(ksmtuned_initrc_exec_t)

type ksmtuned_log_t;
logging_log_file(ksmtuned_log_t)

type ksmtuned_var_run_t;
files_pid_file(ksmtuned_var_run_t)

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

allow ksmtuned_t self:capability { sys_ptrace sys_tty_config };
allow ksmtuned_t self:cap_userns { sys_ptrace };
allow ksmtuned_t self:fifo_file rw_fifo_file_perms;

manage_dirs_pattern(ksmtuned_t, ksmtuned_log_t, ksmtuned_log_t)
append_files_pattern(ksmtuned_t, ksmtuned_log_t, ksmtuned_log_t)
create_files_pattern(ksmtuned_t, ksmtuned_log_t, ksmtuned_log_t)
setattr_files_pattern(ksmtuned_t, ksmtuned_log_t, ksmtuned_log_t)
logging_log_filetrans(ksmtuned_t, ksmtuned_log_t, { file dir })

manage_files_pattern(ksmtuned_t, ksmtuned_var_run_t, ksmtuned_var_run_t)
files_pid_filetrans(ksmtuned_t, ksmtuned_var_run_t, file)

kernel_read_system_state(ksmtuned_t)

corecmd_exec_bin(ksmtuned_t)
corecmd_exec_shell(ksmtuned_t)

dev_manage_sysfs(ksmtuned_t)

domain_read_all_domains_state(ksmtuned_t)
domain_dontaudit_read_all_domains_state(ksmtuned_t)

mls_file_read_to_clearance(ksmtuned_t)

term_use_all_terms(ksmtuned_t)

auth_use_nsswitch(ksmtuned_t)

logging_send_syslog_msg(ksmtuned_t)

tunable_policy(`ksmtuned_use_nfs',`
    fs_read_nfs_files(ksmtuned_t)
')

tunable_policy(`ksmtuned_use_cifs',`
    fs_read_cifs_files(ksmtuned_t)
	samba_read_share_files(ksmtuned_t)
')
