2012-01-04 18:33:27 +01:00
|
|
|
# init switches to init domain (via init.rc).
|
2014-12-05 06:40:22 +01:00
|
|
|
type init, domain, mlstrustedsubject;
|
2012-01-04 18:33:27 +01:00
|
|
|
tmpfs_domain(init)
|
2013-07-10 23:46:05 +02:00
|
|
|
|
2014-10-24 21:56:15 +02:00
|
|
|
# setrlimit
|
|
|
|
allow init self:capability sys_resource;
|
|
|
|
|
|
|
|
# Remove /dev/.booting, created before initial policy load or restorecon /dev.
|
|
|
|
allow init tmpfs:file unlink;
|
|
|
|
|
|
|
|
# Access pty created for fsck.
|
|
|
|
allow init devpts:chr_file { read write open };
|
|
|
|
|
|
|
|
# Create /dev/fscklogs files.
|
|
|
|
allow init fscklogs:file create_file_perms;
|
|
|
|
|
|
|
|
# Access /dev/__null__ node created prior to initial policy load.
|
|
|
|
allow init tmpfs:chr_file write;
|
|
|
|
|
|
|
|
# Access /dev/console.
|
|
|
|
allow init console_device:chr_file rw_file_perms;
|
|
|
|
|
|
|
|
# Access /dev/tty0.
|
|
|
|
allow init tty_device:chr_file rw_file_perms;
|
|
|
|
|
|
|
|
# Call mount(2).
|
|
|
|
allow init self:capability sys_admin;
|
|
|
|
|
|
|
|
# Create and mount on directories in /.
|
|
|
|
allow init rootfs:dir create_dir_perms;
|
|
|
|
allow init rootfs:dir mounton;
|
|
|
|
|
|
|
|
# Mount on /dev/usb-ffs/adb.
|
|
|
|
allow init device:dir mounton;
|
|
|
|
|
2014-12-24 02:08:58 +01:00
|
|
|
# Create and remove symlinks in /.
|
|
|
|
allow init rootfs:lnk_file { create unlink };
|
2014-10-24 21:56:15 +02:00
|
|
|
|
|
|
|
# Mount debugfs on /sys/kernel/debug.
|
|
|
|
allow init sysfs:dir mounton;
|
|
|
|
|
|
|
|
# Create cgroups mount points in tmpfs and mount cgroups on them.
|
|
|
|
allow init tmpfs:dir create_dir_perms;
|
|
|
|
allow init tmpfs:dir mounton;
|
|
|
|
allow init cgroup:dir create_dir_perms;
|
|
|
|
allow init cpuctl_device:dir { create mounton };
|
|
|
|
|
2015-02-27 23:54:40 +01:00
|
|
|
# Use tmpfs as /data, used for booting when /data is encrypted
|
|
|
|
allow init tmpfs:dir relabelfrom;
|
|
|
|
|
2014-10-24 21:56:15 +02:00
|
|
|
# Create directories under /dev/cpuctl after chowning it to system.
|
|
|
|
allow init self:capability dac_override;
|
|
|
|
|
|
|
|
# Set system clock.
|
|
|
|
allow init self:capability sys_time;
|
|
|
|
|
2014-02-10 22:31:04 +01:00
|
|
|
allow init self:capability { sys_rawio mknod };
|
|
|
|
|
2014-09-23 15:11:30 +02:00
|
|
|
# Mounting filesystems from block devices.
|
|
|
|
allow init dev_type:blk_file r_file_perms;
|
2014-05-29 20:35:55 +02:00
|
|
|
|
|
|
|
# Mounting filesystems.
|
2014-06-16 19:05:38 +02:00
|
|
|
# Only allow relabelto for types used in context= mount options,
|
|
|
|
# which should all be assigned the contextmount_type attribute.
|
|
|
|
# This can be done in device-specific policy via type or typeattribute
|
|
|
|
# declarations.
|
|
|
|
allow init fs_type:filesystem ~relabelto;
|
|
|
|
allow init unlabeled:filesystem ~relabelto;
|
|
|
|
allow init contextmount_type:filesystem relabelto;
|
|
|
|
|
|
|
|
# Allow read-only access to context= mounted filesystems.
|
|
|
|
allow init contextmount_type:dir r_dir_perms;
|
|
|
|
allow init contextmount_type:notdevfile_class_set r_file_perms;
|
2014-05-29 20:35:55 +02:00
|
|
|
|
2014-06-23 15:17:51 +02:00
|
|
|
# restorecon /adb_keys or any other rootfs files to a more specific type.
|
|
|
|
allow init rootfs:file relabelfrom;
|
|
|
|
|
2014-10-24 21:56:15 +02:00
|
|
|
# mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files.
|
|
|
|
# chown/chmod require open+read+setattr required for open()+fchown/fchmod().
|
2014-05-29 20:35:55 +02:00
|
|
|
# system/core/init.rc requires at least cache_file and data_file_type.
|
|
|
|
# init.<board>.rc files often include device-specific types, so
|
|
|
|
# we just allow all file types except /system files here.
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init self:capability { chown fowner fsetid };
|
|
|
|
allow init {file_type -system_file -exec_type -app_data_file}:dir { create search getattr open read setattr };
|
2014-10-30 21:50:25 +01:00
|
|
|
allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:dir { write add_name remove_name rmdir relabelfrom };
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:file { create getattr open read write setattr relabelfrom unlink };
|
|
|
|
allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:{ sock_file fifo_file } { create getattr open read setattr relabelfrom unlink };
|
|
|
|
allow init {file_type -system_file -exec_type -keystore_data_file -security_file -app_data_file -shell_data_file}:lnk_file { create getattr setattr relabelfrom unlink };
|
2014-05-20 20:09:16 +02:00
|
|
|
allow init {file_type -system_file -exec_type}:dir_file_class_set relabelto;
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init sysfs:{ dir file lnk_file } { getattr relabelfrom };
|
2014-07-17 20:54:44 +02:00
|
|
|
allow init sysfs_type:{ dir file lnk_file } relabelto;
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init dev_type:dir create_dir_perms;
|
|
|
|
allow init dev_type:lnk_file create;
|
|
|
|
|
|
|
|
# chown/chmod on pseudo files.
|
2015-02-06 22:29:25 +01:00
|
|
|
allow init { fs_type -contextmount_type -sdcard_type -rootfs }:file { open read setattr };
|
|
|
|
allow init { fs_type -contextmount_type -sdcard_type -rootfs }:dir { open read setattr search };
|
2014-10-24 21:56:15 +02:00
|
|
|
|
|
|
|
# chown/chmod on devices.
|
2014-11-10 18:15:33 +01:00
|
|
|
allow init { dev_type -kmem_device }:chr_file { read open setattr };
|
2014-05-29 20:35:55 +02:00
|
|
|
|
2014-05-30 15:53:00 +02:00
|
|
|
# Unlabeled file access for upgrades from 4.2.
|
|
|
|
allow init unlabeled:dir { create_dir_perms relabelfrom };
|
|
|
|
allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom };
|
|
|
|
|
2014-05-30 16:25:00 +02:00
|
|
|
# Create /data/security from init.rc post-fs-data.
|
|
|
|
allow init security_file:dir { create setattr };
|
|
|
|
|
2014-05-29 20:35:55 +02:00
|
|
|
# Reload policy upon setprop selinux.reload_policy 1.
|
2014-05-30 16:25:00 +02:00
|
|
|
r_dir_file(init, security_file)
|
2013-12-06 14:05:53 +01:00
|
|
|
allow init kernel:security load_policy;
|
2014-05-29 20:35:55 +02:00
|
|
|
|
|
|
|
# Any operation that can modify the kernel ring buffer, e.g. clear
|
|
|
|
# or a read that consumes the messages that were read.
|
2014-05-28 22:48:52 +02:00
|
|
|
allow init kernel:system syslog_mod;
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init self:capability2 syslog;
|
|
|
|
|
2014-05-29 20:35:55 +02:00
|
|
|
# Set usermodehelpers and /proc security settings.
|
2013-12-06 15:31:40 +01:00
|
|
|
allow init usermodehelper:file rw_file_perms;
|
|
|
|
allow init proc_security:file rw_file_perms;
|
2014-01-25 05:43:07 +01:00
|
|
|
|
2014-10-24 21:56:15 +02:00
|
|
|
# Write to /proc/sys/kernel/panic_on_oops.
|
|
|
|
allow init proc:file w_file_perms;
|
|
|
|
|
|
|
|
# Write to /proc/sys/net/ping_group_range and other /proc/sys/net files.
|
2015-02-25 22:28:40 +01:00
|
|
|
allow init proc_net:file w_file_perms;
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init self:capability net_admin;
|
|
|
|
|
|
|
|
# Write to /proc/sysrq-trigger.
|
|
|
|
allow init proc_sysrq:file w_file_perms;
|
|
|
|
|
|
|
|
# Reboot.
|
|
|
|
allow init self:capability sys_boot;
|
|
|
|
|
|
|
|
# Write to sysfs nodes.
|
|
|
|
allow init sysfs_type:dir r_dir_perms;
|
|
|
|
allow init sysfs_type:file w_file_perms;
|
|
|
|
|
2014-01-25 05:43:07 +01:00
|
|
|
# Transitions to seclabel processes in init.rc
|
2014-07-04 07:13:14 +02:00
|
|
|
domain_trans(init, rootfs, adbd)
|
|
|
|
domain_trans(init, rootfs, healthd)
|
2015-02-18 14:59:38 +01:00
|
|
|
domain_trans(init, rootfs, slideshow)
|
2014-07-04 07:13:14 +02:00
|
|
|
recovery_only(`
|
|
|
|
domain_trans(init, rootfs, recovery)
|
|
|
|
')
|
|
|
|
domain_trans(init, shell_exec, shell)
|
|
|
|
domain_trans(init, rootfs, ueventd)
|
|
|
|
domain_trans(init, rootfs, watchdogd)
|
|
|
|
|
|
|
|
# Support "adb shell stop"
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init self:capability kill;
|
2014-07-04 07:13:14 +02:00
|
|
|
allow init domain:process sigkill;
|
2014-05-09 08:28:52 +02:00
|
|
|
|
|
|
|
# Init creates keystore's directory on boot, and walks through
|
|
|
|
# the directory as part of a recursive restorecon.
|
|
|
|
allow init keystore_data_file:dir { open create read getattr setattr search };
|
|
|
|
allow init keystore_data_file:file { getattr };
|
2014-05-23 17:26:19 +02:00
|
|
|
|
2014-06-07 19:00:59 +02:00
|
|
|
# Init creates /data/local/tmp at boot
|
|
|
|
allow init shell_data_file:dir { open create read getattr setattr search };
|
|
|
|
allow init shell_data_file:file { getattr };
|
|
|
|
|
2014-10-24 21:56:15 +02:00
|
|
|
# Set UID and GID for services.
|
|
|
|
allow init self:capability { setuid setgid };
|
|
|
|
|
2014-12-05 06:40:22 +01:00
|
|
|
# For bootchart to read the /proc/$pid/cmdline file of each process,
|
|
|
|
# we need to have following line to allow init to have access
|
|
|
|
# to different domains.
|
|
|
|
r_dir_file(init, domain)
|
|
|
|
|
2014-05-23 17:26:19 +02:00
|
|
|
# Use setexeccon(), setfscreatecon(), and setsockcreatecon().
|
|
|
|
# setexec is for services with seclabel options.
|
|
|
|
# setfscreate is for labeling directories and socket files.
|
|
|
|
# setsockcreate is for labeling local/unix domain sockets.
|
|
|
|
allow init self:process { setexec setfscreate setsockcreate };
|
2014-05-29 15:22:16 +02:00
|
|
|
|
2014-10-24 21:56:15 +02:00
|
|
|
# Perform SELinux access checks on setting properties.
|
|
|
|
selinux_check_access(init)
|
|
|
|
|
|
|
|
# Ask the kernel for the new context on services to label their sockets.
|
|
|
|
allow init kernel:security compute_create;
|
|
|
|
|
|
|
|
# Create sockets for the services.
|
|
|
|
allow init domain:unix_stream_socket { create bind };
|
|
|
|
allow init domain:unix_dgram_socket { create bind };
|
|
|
|
|
2014-05-29 15:22:16 +02:00
|
|
|
# Create /data/property and files within it.
|
|
|
|
allow init property_data_file:dir create_dir_perms;
|
|
|
|
allow init property_data_file:file create_file_perms;
|
2014-06-18 16:09:35 +02:00
|
|
|
|
2014-06-19 16:27:02 +02:00
|
|
|
# Set any property.
|
|
|
|
allow init property_type:property_service set;
|
|
|
|
|
2014-06-21 06:15:56 +02:00
|
|
|
# Run "ifup lo" to bring up the localhost interface
|
|
|
|
allow init self:udp_socket { create ioctl };
|
2014-10-24 21:56:15 +02:00
|
|
|
allow init self:capability net_raw;
|
2014-06-21 06:15:56 +02:00
|
|
|
|
2014-07-04 07:13:14 +02:00
|
|
|
# This line seems suspect, as it should not really need to
|
|
|
|
# set scheduling parameters for a kernel domain task.
|
|
|
|
allow init kernel:process setsched;
|
|
|
|
|
2014-10-20 20:52:19 +02:00
|
|
|
# swapon() needs write access to swap device
|
|
|
|
# system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all
|
|
|
|
allow init swap_block_device:blk_file rw_file_perms;
|
|
|
|
|
2014-10-21 16:09:33 +02:00
|
|
|
# Read from /dev/hw_random if present.
|
|
|
|
# system/core/init/init.c - mix_hwrng_into_linux_rng_action
|
|
|
|
allow init hw_random_device:chr_file r_file_perms;
|
|
|
|
|
|
|
|
# Create and access /dev files without a specific type,
|
2014-10-24 21:56:15 +02:00
|
|
|
# e.g. /dev/.coldboot_done, /dev/.booting
|
2014-10-21 16:09:33 +02:00
|
|
|
# TODO: Move these files into their own type unless they are
|
|
|
|
# only ever accessed by init.
|
|
|
|
allow init device:file create_file_perms;
|
|
|
|
|
|
|
|
# Access character devices without a specific type,
|
|
|
|
# e.g. /dev/keychord.
|
|
|
|
# TODO: Move these devices into their own type unless they
|
|
|
|
# are only ever accessed by init.
|
|
|
|
allow init device:chr_file { rw_file_perms setattr };
|
|
|
|
|
2014-10-24 21:56:15 +02:00
|
|
|
# keychord configuration
|
|
|
|
allow init self:capability sys_tty_config;
|
|
|
|
|
2015-03-05 01:55:29 +01:00
|
|
|
# Access device mapper for setting up dm-verity
|
|
|
|
allow init dm_device:chr_file rw_file_perms;
|
|
|
|
allow init dm_device:blk_file rw_file_perms;
|
|
|
|
|
|
|
|
# Access metadata block device for storing dm-verity state
|
|
|
|
allow init metadata_block_device:blk_file rw_file_perms;
|
|
|
|
|
|
|
|
# Read /sys/fs/pstore/console-ramoops to detect restarts caused
|
|
|
|
# by dm-verity detecting corrupted blocks
|
|
|
|
allow init pstorefs:dir search;
|
|
|
|
allow init pstorefs:file r_file_perms;
|
|
|
|
|
2015-03-11 23:44:14 +01:00
|
|
|
# linux keyring configuration
|
|
|
|
allow init init:key { write search setattr };
|
|
|
|
|
|
|
|
# Allow init to link temp fs to unencrypted data on userdata
|
|
|
|
allow init tmpfs:lnk_file { create read getattr relabelfrom };
|
|
|
|
|
|
|
|
# Allow init to manipulate /data/unencrypted
|
|
|
|
allow init unencrypted_data_file:{ file lnk_file } create_file_perms;
|
|
|
|
allow init unencrypted_data_file:dir create_dir_perms;
|
|
|
|
|
|
|
|
unix_socket_connect(init, vold, vold)
|
|
|
|
|
2014-06-18 16:09:35 +02:00
|
|
|
###
|
|
|
|
### neverallow rules
|
|
|
|
###
|
|
|
|
|
|
|
|
# The init domain is only entered via setcon from the kernel domain,
|
|
|
|
# never via an exec-based transition.
|
|
|
|
neverallow { domain -kernel} init:process dyntransition;
|
|
|
|
neverallow domain init:process transition;
|
|
|
|
neverallow init { file_type fs_type }:file entrypoint;
|
2014-09-02 23:05:44 +02:00
|
|
|
|
|
|
|
# Never read/follow symlinks created by shell or untrusted apps.
|
|
|
|
neverallow init shell_data_file:lnk_file read;
|
|
|
|
neverallow init app_data_file:lnk_file read;
|
2014-09-23 15:11:30 +02:00
|
|
|
|
|
|
|
# init should never execute a program without changing to another domain.
|
|
|
|
neverallow init { file_type fs_type }:file execute_no_trans;
|