Chris PeBenito e181fe
# Copyright (C) 2005 Tresys Technology, LLC
Chris PeBenito e181fe
Chris PeBenito 960373
policy_module(init,1.0)
Chris PeBenito 960373
Chris PeBenito bbd6a6
########################################
Chris PeBenito bbd6a6
#
Chris PeBenito bbd6a6
# Declarations
Chris PeBenito bbd6a6
#
Chris PeBenito bbd6a6
Chris PeBenito 343a23
#
Chris PeBenito b4cd15
# init_t is the domain of the init process.
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
type init_t;
Chris PeBenito b4cd15
domain_make_domain(init_t)
Chris PeBenito b4cd15
role system_r types init_t;
Chris PeBenito b4cd15
Chris PeBenito 343a23
#
Chris PeBenito 343a23
# init_exec_t is the type of the init program.
Chris PeBenito 343a23
#
Chris PeBenito b4cd15
type init_exec_t;
Chris PeBenito ff3138
kernel_make_userland_entrypoint(init_t,init_exec_t)
Chris PeBenito b4cd15
domain_make_entrypoint_file(init_t,init_exec_t)
Chris PeBenito b4cd15
Chris PeBenito 343a23
#
Chris PeBenito 343a23
# initctl_t is the type of the named pipe created 
Chris PeBenito 343a23
# by init during initialization.  This pipe is used
Chris PeBenito 343a23
# to communicate with init.
Chris PeBenito 343a23
#
Chris PeBenito b4cd15
type initctl_t;
Chris PeBenito b4cd15
files_make_file(initctl_t)
Chris PeBenito 33bc0d
filesystem_tmpfs_associate(initctl_t)
Chris PeBenito b4cd15
devices_create_dev_entry(init_t,initctl_t,fifo_file)
Chris PeBenito b4cd15
Chris PeBenito 343a23
#
Chris PeBenito 343a23
# init_var_run_t is the type for /var/run/shutdown.pid.
Chris PeBenito 343a23
#
Chris PeBenito b4cd15
type init_var_run_t;
Chris PeBenito d25dd9
files_make_daemon_runtime_file(init_var_run_t)
Chris PeBenito b4cd15
Chris PeBenito 343a23
type initrc_t;
Chris PeBenito 343a23
domain_make_domain(initrc_t)
Chris PeBenito 343a23
role system_r types initrc_t;
Chris PeBenito 343a23
Chris PeBenito 343a23
type initrc_exec_t;
Chris PeBenito 343a23
domain_make_entrypoint_file(initrc_t,initrc_exec_t)
Chris PeBenito 343a23
Chris PeBenito 343a23
type initrc_devpts_t;
Chris PeBenito 219bcf
filesystem_associate(initrc_devpts_t)
Chris PeBenito 219bcf
filesystem_noxattr_associate(initrc_devpts_t)
Chris PeBenito b16c6b
terminal_make_pseudoterminal(initrc_devpts_t)
Chris PeBenito 343a23
Chris PeBenito 343a23
type initrc_var_run_t;
Chris PeBenito d25dd9
files_make_daemon_runtime_file(initrc_var_run_t)
Chris PeBenito 343a23
Chris PeBenito 343a23
type initrc_state_t;
Chris PeBenito 343a23
files_make_file(initrc_state_t)
Chris PeBenito 343a23
Chris PeBenito 343a23
type initrc_tmp_t;
Chris PeBenito 38e24a
files_make_temporary_file(initrc_tmp_t)
Chris PeBenito 343a23
Chris PeBenito 343a23
########################################
Chris PeBenito 343a23
#
Chris PeBenito 343a23
# Init local policy
Chris PeBenito 343a23
#
Chris PeBenito 343a23
Chris PeBenito f05782
# Re-exec itself
Chris PeBenito f05782
allow init_t init_exec_t:file { getattr read execute execute_no_trans };
Chris PeBenito f05782
Chris PeBenito f05782
# For /var/run/shutdown.pid.
Chris PeBenito f05782
allow init_t init_var_run_t:file { create getattr read append write setattr unlink };
Chris PeBenito bbd6a6
files_create_daemon_runtime_data(init_t,init_var_run_t)
Chris PeBenito f05782
Chris PeBenito f05782
# Run init scripts.  this is ok since initrc
Chris PeBenito f05782
# is also in this module
Chris PeBenito f05782
allow init_t initrc_t:process transition;
Chris PeBenito f05782
allow init_t initrc_exec_t:file { getattr read execute };
Chris PeBenito f05782
Chris PeBenito f05782
allow init_t self:fifo_file { read write ioctl };
Chris PeBenito f05782
Chris PeBenito b4cd15
kernel_sigchld_from(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# If you load a new policy that removes active domains, processes can
Chris PeBenito b4cd15
# get stuck if you do not allow unlabeled processes to signal init
Chris PeBenito b4cd15
# If you load an incompatible policy, you should probably reboot,
Chris PeBenito b4cd15
# since you may have compromised system security.
Chris PeBenito b4cd15
kernel_unlabeled_sigchld_from(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
kernel_set_selinux_boolean(init_t)
Chris PeBenito b4cd15
kernel_read_system_state(init_t)
Chris PeBenito b4cd15
kernel_read_hardware_state(init_t)
Chris PeBenito b4cd15
kernel_share_state(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
terminal_use_all_terminals(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
domain_signal_all_domains(init_t)
Chris PeBenito b4cd15
domain_kill_all_domains(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
files_modify_system_runtime_data(init_t)
Chris PeBenito b4cd15
Chris PeBenito f05782
# file descriptors inherited from the rootfs.
Chris PeBenito f05782
files_ignore_modify_rootfs_file(init_t)
Chris PeBenito f05782
files_ignore_modify_rootfs_device(init_t)
Chris PeBenito f05782
Chris PeBenito b4cd15
libraries_use_dynamic_loader(init_t)
Chris PeBenito dd14d0
libraries_use_shared_libraries(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
corecommands_chroot(init_t)
Chris PeBenito b4cd15
corecommands_execute_general_programs(init_t)
Chris PeBenito b4cd15
corecommands_execute_system_programs(init_t)
Chris PeBenito b4cd15
Chris PeBenito 5050e5
logging_send_system_log_message(init_t)
Chris PeBenito 5050e5
Chris PeBenito b4cd15
selinux_read_config(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
miscfiles_read_localization(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
########################################
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# the following seem questionable
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
Chris PeBenito b4cd15
libraries_modify_dynamic_loader_cache(init_t)
Chris PeBenito b4cd15
files_create_runtime_system_config(init_t)
Chris PeBenito b4cd15
authlogin_modify_login_records(init_t)
Chris PeBenito b4cd15
logging_modify_system_logs(init_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# Use capabilities. old rule:
Chris PeBenito 7f89c7
allow init_t self:capability ~sys_module;
Chris PeBenito b4cd15
# is ~sys_module really needed? observed: 
Chris PeBenito b4cd15
# sys_boot
Chris PeBenito b4cd15
# sys_tty_config
Chris PeBenito b4cd15
# kill: now provided by domain_kill_all_domains()
Chris PeBenito b4cd15
# setuid (from /sbin/shutdown)
Chris PeBenito b4cd15
# sys_chroot (from /usr/bin/chroot): now provided by corecommands_chroot()
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# Modify utmp.
Chris PeBenito b4cd15
allow init_t initrc_var_run_t:file { getattr read write setattr };
Chris PeBenito b4cd15
Chris PeBenito bbd6a6
ifdef(`TODO',`
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# for mount points
Chris PeBenito b4cd15
allow init_t file_t:dir search;
Chris PeBenito bbd6a6
') dnl end TODO
Chris PeBenito b4cd15
Chris PeBenito 343a23
########################################
Chris PeBenito f05782
#
Chris PeBenito 343a23
# Init script local policy
Chris PeBenito f05782
#
Chris PeBenito b4cd15
Chris PeBenito b4cd15
allow initrc_t self:process { getpgid setsched setpgid setrlimit getsched };
Chris PeBenito b4cd15
allow initrc_t self:capability ~{ sys_admin sys_module };
Chris PeBenito b4cd15
allow initrc_t self:passwd rootok;
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# Allow IPC with self
Chris PeBenito b4cd15
allow initrc_t self:unix_dgram_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown };
Chris PeBenito b4cd15
allow initrc_t self:unix_stream_socket { create listen accept ioctl read getattr write setattr append bind connect getopt setopt shutdown connectto };
Chris PeBenito b4cd15
allow initrc_t self:fifo_file { read write ioctl };
Chris PeBenito b4cd15
Chris PeBenito b4cd15
allow initrc_t self:netlink_route_socket { create ioctl read getattr write setattr append bind connect getopt setopt shutdown nlmsg_read };
Chris PeBenito b4cd15
Chris PeBenito b4cd15
allow initrc_t initrc_state_t:dir { create read getattr lock setattr ioctl unlink rename search add_name remove_name reparent write rmdir };
Chris PeBenito b4cd15
allow initrc_t initrc_state_t:file { create ioctl read getattr lock write setattr append link unlink rename };
Chris PeBenito b4cd15
allow initrc_t initrc_state_t:lnk_file { create read getattr setattr unlink rename };
Chris PeBenito b4cd15
Chris PeBenito 91a7ab
allow initrc_t self:tcp_socket { connect listen accept create ioctl read getattr write setattr append bind getopt setopt shutdown };
Chris PeBenito 91a7ab
allow initrc_t self:udp_socket { connect create ioctl read getattr write setattr append bind getopt setopt shutdown };
Chris PeBenito 91a7ab
Chris PeBenito d25dd9
files_create_daemon_runtime_data(initrc_t,initrc_var_run_t)
Chris PeBenito d25dd9
Chris PeBenito bbd6a6
allow initrc_t initrc_tmp_t : file { create ioctl read getattr lock write setattr append link unlink rename };
Chris PeBenito bbd6a6
allow initrc_t initrc_tmp_t : dir { create read getattr lock setattr ioctl link unlink rename search add_name remove_name reparent write rmdir };
Chris PeBenito bbd6a6
files_create_private_tmp_data(initrc_t,initrc_tmp_t, { file dir })
Chris PeBenito bbd6a6
Chris PeBenito b4cd15
kernel_read_system_state(initrc_t)
Chris PeBenito b4cd15
kernel_read_software_raid_state(initrc_t)
Chris PeBenito b4cd15
kernel_read_network_state(initrc_t)
Chris PeBenito b4cd15
kernel_read_ring_buffer(initrc_t)
Chris PeBenito b4cd15
kernel_change_ring_buffer_level(initrc_t)
Chris PeBenito b4cd15
kernel_clear_ring_buffer(initrc_t)
Chris PeBenito b4cd15
kernel_get_sysvipc_info(initrc_t)
Chris PeBenito b4cd15
kernel_read_hardware_state(initrc_t)
Chris PeBenito b4cd15
kernel_modify_hardware_config_option(initrc_t)
Chris PeBenito b4cd15
kernel_read_all_sysctl(initrc_t)
Chris PeBenito b4cd15
kernel_modify_all_sysctl(initrc_t)
Chris PeBenito b4cd15
kernel_get_selinux_enforcement_mode(initrc_t)
Chris PeBenito b4cd15
kernel_list_usb_hardware(initrc_t)
Chris PeBenito 07d6e3
# for lsof which is used by alsa shutdown:
Chris PeBenito 07d6e3
kernel_ignore_get_message_interface_attributes(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito daa0e0
bootloader_read_kernel_symbol_table(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito 0e730c
corenetwork_network_tcp_on_all_interfaces(initrc_t)
Chris PeBenito 0e730c
corenetwork_network_raw_on_all_interfaces(initrc_t)
Chris PeBenito 0e730c
corenetwork_network_udp_on_all_interfaces(initrc_t)
Chris PeBenito 0e730c
corenetwork_network_tcp_on_all_nodes(initrc_t)
Chris PeBenito 0e730c
corenetwork_network_raw_on_all_nodes(initrc_t)
Chris PeBenito 0e730c
corenetwork_network_udp_on_all_nodes(initrc_t)
Chris PeBenito 0e730c
corenetwork_network_tcp_on_all_ports(initrc_t)
Chris PeBenito 0e730c
corenetwork_network_udp_on_all_ports(initrc_t)
Chris PeBenito 0e730c
corenetwork_bind_tcp_on_all_nodes(initrc_t)
Chris PeBenito 0e730c
corenetwork_bind_udp_on_all_nodes(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
devices_get_random_data(initrc_t)
Chris PeBenito b4cd15
devices_get_pseudorandom_data(initrc_t)
Chris PeBenito b4cd15
devices_add_entropy(initrc_t)
Chris PeBenito b4cd15
devices_set_pseudorandom_seed(initrc_t)
Chris PeBenito b4cd15
devices_read_framebuffer(initrc_t)
Chris PeBenito b4cd15
devices_read_realtime_clock(initrc_t)
Chris PeBenito b4cd15
devices_read_sound_mixer_levels(initrc_t)
Chris PeBenito b4cd15
devices_write_sound_mixer_levels(initrc_t)
Chris PeBenito 8a0da1
devices_set_all_character_device_attributes(initrc_t)
Chris PeBenito 8a0da1
Chris PeBenito daa0e0
filesystem_register_binary_executable_type(initrc_t)
Chris PeBenito daa0e0
# cjp: not sure why these are here; should use mount policy
Chris PeBenito daa0e0
filesystem_mount_all_filesystems(initrc_t)
Chris PeBenito daa0e0
filesystem_unmount_all_filesystems(initrc_t)
Chris PeBenito daa0e0
filesystem_remount_all_filesystems(initrc_t)
Chris PeBenito daa0e0
filesystem_get_all_filesystems_attributes(initrc_t)
Chris PeBenito daa0e0
Chris PeBenito ba7740
storage_get_fixed_disk_attributes(initrc_t)
Chris PeBenito 8a0da1
storage_set_fixed_disk_attributes(initrc_t)
Chris PeBenito 8a0da1
storage_set_removable_device_attributes(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
terminal_use_all_terminals(initrc_t)
Chris PeBenito ba7740
terminal_reset_physical_terminal_labels(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito daa0e0
corecommands_execute_general_programs(initrc_t)
Chris PeBenito daa0e0
corecommands_execute_system_programs(initrc_t)
Chris PeBenito daa0e0
corecommands_execute_shell(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito d0eddb
domain_kill_all_domains(initrc_t)
Chris PeBenito d0eddb
domain_read_all_domains_process_state(initrc_t)
Chris PeBenito ba7740
domain_use_widely_inheritable_file_descriptors(initrc_t)
Chris PeBenito ba7740
Chris PeBenito 8a0da1
files_get_all_file_attributes(initrc_t)
Chris PeBenito b4cd15
files_remove_all_tmp_data(initrc_t)
Chris PeBenito b4cd15
files_remove_all_lock_files(initrc_t)
Chris PeBenito b4cd15
files_remove_all_daemon_runtime_data(initrc_t)
Chris PeBenito b4cd15
files_read_general_system_config(initrc_t)
Chris PeBenito b4cd15
files_create_runtime_system_config(initrc_t)
Chris PeBenito 033c80
files_manage_system_lock_files(initrc_t)
Chris PeBenito b4cd15
files_execute_system_config_script(initrc_t)
Chris PeBenito 3ce6cb
files_read_general_application_resources(initrc_t)
Chris PeBenito b4cd15
files_manage_pseudorandom_saved_seed(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito daa0e0
libraries_modify_dynamic_loader_cache(initrc_t)
Chris PeBenito daa0e0
libraries_use_dynamic_loader(initrc_t)
Chris PeBenito daa0e0
libraries_use_shared_libraries(initrc_t)
Chris PeBenito daa0e0
libraries_execute_library_scripts(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito 5050e5
logging_send_system_log_message(initrc_t)
Chris PeBenito 5050e5
Chris PeBenito b4cd15
selinux_read_config(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito 91a7ab
sysnetwork_read_network_config(initrc_t)
Chris PeBenito 91a7ab
Chris PeBenito b4cd15
modutils_read_kernel_module_loading_config(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
authlogin_modify_login_records(initrc_t)
Chris PeBenito b4cd15
authlogin_modify_last_login_log(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
miscfiles_read_localization(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
logging_modify_system_logs(initrc_t)
Chris PeBenito b4cd15
logging_read_all_logs(initrc_t)
Chris PeBenito b4cd15
logging_append_all_logs(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito 7bba9d
udev_modify_database(initrc_t)
Chris PeBenito f1578d
Chris PeBenito daa0e0
userdomain_read_all_users_data(initrc_t)
Chris PeBenito daa0e0
# Allow access to the sysadm TTYs. Note that this will give access to the 
Chris PeBenito daa0e0
# TTYs to any process in the initrc_t domain. Therefore, daemons and such
Chris PeBenito daa0e0
# started from init should be placed in their own domain.
Chris PeBenito daa0e0
userdomain_use_admin_terminals(initrc_t)
Chris PeBenito daa0e0
Chris PeBenito daa0e0
tunable_policy(`distro_debian', `
Chris PeBenito daa0e0
filesystem_tmpfs_associate(initrc_var_run_t)
Chris PeBenito daa0e0
')
Chris PeBenito daa0e0
Chris PeBenito 25baab
tunable_policy(`distro_redhat',`
Chris PeBenito b4cd15
kernel_set_selinux_enforcement_mode(initrc_t)
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# Create and read /boot/kernel.h and /boot/System.map.
Chris PeBenito b4cd15
# Redhat systems typically create this file at boot time.
Chris PeBenito b4cd15
bootloader_create_runtime_data(initrc_t)
Chris PeBenito daa0e0
Chris PeBenito daa0e0
filesystem_use_tmpfs_character_devices(initrc_t)
Chris PeBenito daa0e0
Chris PeBenito daa0e0
files_create_boot_flag(initrc_t)
Chris PeBenito daa0e0
Chris PeBenito daa0e0
# readahead asks for these
Chris PeBenito daa0e0
mta_read_mail_aliases(initrc_t)
Chris PeBenito f1578d
') dnl end distro_redhat
Chris PeBenito 3ce6cb
Chris PeBenito 7bba9d
optional_policy(`authlogin.te',`
Chris PeBenito 7bba9d
authlogin_pam_read_runtime_data(initrc_t)
Chris PeBenito 7bba9d
authlogin_pam_remove_runtime_data(initrc_t)
Chris PeBenito 7bba9d
')
Chris PeBenito 7bba9d
Chris PeBenito daa0e0
optional_policy(`hotplug.te',`
Chris PeBenito daa0e0
kernel_read_usb_hardware_state(initrc_t)
Chris PeBenito daa0e0
# init scripts run /etc/hotplug/usb.rc
Chris PeBenito daa0e0
hotplug_read_config(initrc_t)
Chris PeBenito daa0e0
modutils_read_kernel_module_dependencies(initrc_t)
Chris PeBenito daa0e0
')
Chris PeBenito daa0e0
Chris PeBenito b4cd15
ifdef(`TODO',`
Chris PeBenito daa0e0
Chris PeBenito b4cd15
# Mount and unmount file systems.
Chris PeBenito b4cd15
allow initrc_t { file_t default_t }:dir { read search getattr mounton };
Chris PeBenito b4cd15
Chris PeBenito b4cd15
allow initrc_t var_spool_t:file rw_file_perms;
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# Set device ownerships/modes.
Chris PeBenito b4cd15
allow initrc_t xconsole_device_t:fifo_file setattr;
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# for lsof in shutdown scripts
Chris PeBenito c18e82
can_kerberos(initrc_t)
Chris PeBenito ba7740
dontaudit initrc_t krb5_conf_t:file write;
Chris PeBenito ba7740
allow initrc_t krb5_conf_t:file { getattr read };
Chris PeBenito b4cd15
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# Wants to remove udev.tbl
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
allow initrc_t device_t:dir rw_dir_perms;
Chris PeBenito b4cd15
allow initrc_t device_t:lnk_file unlink;
Chris PeBenito b4cd15
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
#  These rules are here to allow init scripts to su
Chris PeBenito b4cd15
#
Chris PeBenito 25baab
optional_policy(`su.te', `
Chris PeBenito b4cd15
su_restricted_domain(initrc,system)
Chris PeBenito b4cd15
role system_r types initrc_su_t;
Chris PeBenito b4cd15
')
Chris PeBenito b4cd15
Chris PeBenito 25baab
tunable_policy(`distro_debian', `
Chris PeBenito b4cd15
allow initrc_t { etc_t device_t }:dir setattr;
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# for storing state under /dev/shm
Chris PeBenito b4cd15
allow initrc_t tmpfs_t:dir setattr;
Chris PeBenito b4cd15
file_type_auto_trans(initrc_t, tmpfs_t, initrc_var_run_t, dir)
Chris PeBenito b4cd15
file_type_auto_trans(initrc_t, tmpfs_t, fixed_disk_device_t, blk_file)
Chris PeBenito 25baab
')dnl end distro_debian
Chris PeBenito b4cd15
Chris PeBenito 25baab
tunable_policy(`distro_redhat', `
Chris PeBenito b4cd15
# Create and read /boot/kernel.h and /boot/System.map.
Chris PeBenito b4cd15
# Redhat systems typically create this file at boot time.
Chris PeBenito b4cd15
allow initrc_t boot_t:lnk_file rw_file_perms;
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# readahead asks for these
Chris PeBenito b4cd15
allow initrc_t var_lib_nfs_t:file { getattr read };
Chris PeBenito b4cd15
')dnl end distro_redhat
Chris PeBenito b4cd15
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# Shutting down xinet causes these
Chris PeBenito b4cd15
#
Chris PeBenito b4cd15
# Rsync
Chris PeBenito b4cd15
dontaudit initrc_t mail_spool_t:lnk_file read;
Chris PeBenito b4cd15
Chris PeBenito b4cd15
# for lsof which is used by alsa shutdown
Chris PeBenito b4cd15
dontaudit initrc_t domain:{ udp_socket tcp_socket fifo_file unix_dgram_socket } getattr;
Chris PeBenito 343a23
') dnl end TODO