Stephen Smalley | 2dd4e51 | 2012-01-04 12:33:27 -0500 | [diff] [blame] | 1 | # init switches to init domain (via init.rc). |
| 2 | type init, domain; |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 3 | permissive_or_unconfined(init) |
Stephen Smalley | 2dd4e51 | 2012-01-04 12:33:27 -0500 | [diff] [blame] | 4 | tmpfs_domain(init) |
Nick Kralevich | 0c9708b | 2013-07-10 14:46:05 -0700 | [diff] [blame] | 5 | |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 6 | # setrlimit |
| 7 | allow init self:capability sys_resource; |
| 8 | |
| 9 | # Remove /dev/.booting, created before initial policy load or restorecon /dev. |
| 10 | allow init tmpfs:file unlink; |
| 11 | |
| 12 | # Access pty created for fsck. |
| 13 | allow init devpts:chr_file { read write open }; |
| 14 | |
| 15 | # Create /dev/fscklogs files. |
| 16 | allow init fscklogs:file create_file_perms; |
| 17 | |
| 18 | # Access /dev/__null__ node created prior to initial policy load. |
| 19 | allow init tmpfs:chr_file write; |
| 20 | |
| 21 | # Access /dev/console. |
| 22 | allow init console_device:chr_file rw_file_perms; |
| 23 | |
| 24 | # Access /dev/tty0. |
| 25 | allow init tty_device:chr_file rw_file_perms; |
| 26 | |
| 27 | # Call mount(2). |
| 28 | allow init self:capability sys_admin; |
| 29 | |
| 30 | # Create and mount on directories in /. |
| 31 | allow init rootfs:dir create_dir_perms; |
| 32 | allow init rootfs:dir mounton; |
| 33 | |
| 34 | # Mount on /dev/usb-ffs/adb. |
| 35 | allow init device:dir mounton; |
| 36 | |
| 37 | # Create symlinks in /. |
| 38 | allow init rootfs:lnk_file create; |
| 39 | |
| 40 | # Mount debugfs on /sys/kernel/debug. |
| 41 | allow init sysfs:dir mounton; |
| 42 | |
| 43 | # Create cgroups mount points in tmpfs and mount cgroups on them. |
| 44 | allow init tmpfs:dir create_dir_perms; |
| 45 | allow init tmpfs:dir mounton; |
| 46 | allow init cgroup:dir create_dir_perms; |
| 47 | allow init cpuctl_device:dir { create mounton }; |
| 48 | |
| 49 | # Create directories under /dev/cpuctl after chowning it to system. |
| 50 | allow init self:capability dac_override; |
| 51 | |
| 52 | # Set system clock. |
| 53 | allow init self:capability sys_time; |
| 54 | |
Stephen Smalley | 5487ca0 | 2014-02-10 16:31:04 -0500 | [diff] [blame] | 55 | allow init self:capability { sys_rawio mknod }; |
| 56 | |
Stephen Smalley | 8a0c25e | 2014-09-23 09:11:30 -0400 | [diff] [blame] | 57 | # Mounting filesystems from block devices. |
| 58 | allow init dev_type:blk_file r_file_perms; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 59 | |
| 60 | # Mounting filesystems. |
Stephen Smalley | 75e2ef9 | 2014-06-16 13:05:38 -0400 | [diff] [blame] | 61 | # Only allow relabelto for types used in context= mount options, |
| 62 | # which should all be assigned the contextmount_type attribute. |
| 63 | # This can be done in device-specific policy via type or typeattribute |
| 64 | # declarations. |
| 65 | allow init fs_type:filesystem ~relabelto; |
| 66 | allow init unlabeled:filesystem ~relabelto; |
| 67 | allow init contextmount_type:filesystem relabelto; |
| 68 | |
| 69 | # Allow read-only access to context= mounted filesystems. |
| 70 | allow init contextmount_type:dir r_dir_perms; |
| 71 | allow init contextmount_type:notdevfile_class_set r_file_perms; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 72 | |
Stephen Smalley | c626a88 | 2014-06-23 09:17:51 -0400 | [diff] [blame] | 73 | # restorecon /adb_keys or any other rootfs files to a more specific type. |
| 74 | allow init rootfs:file relabelfrom; |
| 75 | |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 76 | # mkdir, symlink, write, rm/rmdir, chown/chmod, restorecon/restorecon_recursive from init.rc files. |
| 77 | # chown/chmod require open+read+setattr required for open()+fchown/fchmod(). |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 78 | # system/core/init.rc requires at least cache_file and data_file_type. |
| 79 | # init.<board>.rc files often include device-specific types, so |
| 80 | # we just allow all file types except /system files here. |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 81 | allow init self:capability { chown fowner fsetid }; |
| 82 | allow init {file_type -system_file -exec_type -app_data_file}:dir { create search getattr open read setattr }; |
Stephen Smalley | c457572 | 2014-10-30 16:50:25 -0400 | [diff] [blame] | 83 | 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 }; |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 84 | 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 }; |
| 85 | 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 }; |
| 86 | 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 }; |
Nick Kralevich | 03ce512 | 2014-05-20 11:09:16 -0700 | [diff] [blame] | 87 | allow init {file_type -system_file -exec_type}:dir_file_class_set relabelto; |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 88 | allow init sysfs:{ dir file lnk_file } { getattr relabelfrom }; |
Stephen Smalley | 3291565 | 2014-07-17 14:54:44 -0400 | [diff] [blame] | 89 | allow init sysfs_type:{ dir file lnk_file } relabelto; |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 90 | allow init dev_type:dir create_dir_perms; |
| 91 | allow init dev_type:lnk_file create; |
| 92 | |
| 93 | # chown/chmod on pseudo files. |
| 94 | allow init { fs_type -contextmount_type -sdcard_type -rootfs }:{ dir file } { open read setattr }; |
| 95 | |
| 96 | # chown/chmod on devices. |
Stephen Smalley | 1c16abd | 2014-11-10 12:15:33 -0500 | [diff] [blame^] | 97 | allow init { dev_type -kmem_device }:chr_file { read open setattr }; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 98 | |
Stephen Smalley | 73b0346 | 2014-05-30 09:53:00 -0400 | [diff] [blame] | 99 | # Unlabeled file access for upgrades from 4.2. |
| 100 | allow init unlabeled:dir { create_dir_perms relabelfrom }; |
| 101 | allow init unlabeled:notdevfile_class_set { create_file_perms relabelfrom }; |
| 102 | |
Stephen Smalley | 3235f61 | 2014-05-30 10:25:00 -0400 | [diff] [blame] | 103 | # Create /data/security from init.rc post-fs-data. |
| 104 | allow init security_file:dir { create setattr }; |
| 105 | |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 106 | # Reload policy upon setprop selinux.reload_policy 1. |
Stephen Smalley | 3235f61 | 2014-05-30 10:25:00 -0400 | [diff] [blame] | 107 | r_dir_file(init, security_file) |
Stephen Smalley | fea6e66 | 2013-12-06 08:05:53 -0500 | [diff] [blame] | 108 | allow init kernel:security load_policy; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 109 | |
| 110 | # Any operation that can modify the kernel ring buffer, e.g. clear |
| 111 | # or a read that consumes the messages that were read. |
Nick Kralevich | 685e2f9 | 2014-05-28 13:48:52 -0700 | [diff] [blame] | 112 | allow init kernel:system syslog_mod; |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 113 | allow init self:capability2 syslog; |
| 114 | |
| 115 | # Triggered by chmod 0444 /sys/fs/selinux/policy. |
| 116 | allow init kernel:security read_policy; |
Stephen Smalley | eb1bbf2 | 2014-05-29 14:35:55 -0400 | [diff] [blame] | 117 | |
| 118 | # Set usermodehelpers and /proc security settings. |
Stephen Smalley | 7adb999 | 2013-12-06 09:31:40 -0500 | [diff] [blame] | 119 | allow init usermodehelper:file rw_file_perms; |
| 120 | allow init proc_security:file rw_file_perms; |
Nick Kralevich | fed8a2a | 2014-01-24 20:43:07 -0800 | [diff] [blame] | 121 | |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 122 | # Write to /proc/sys/kernel/panic_on_oops. |
| 123 | allow init proc:file w_file_perms; |
| 124 | |
| 125 | # Write to /proc/sys/net/ping_group_range and other /proc/sys/net files. |
| 126 | allow init proc_net:file w_file_perms; |
| 127 | allow init self:capability net_admin; |
| 128 | |
| 129 | # Write to /proc/sysrq-trigger. |
| 130 | allow init proc_sysrq:file w_file_perms; |
| 131 | |
| 132 | # Reboot. |
| 133 | allow init self:capability sys_boot; |
| 134 | |
| 135 | # Write to sysfs nodes. |
| 136 | allow init sysfs_type:dir r_dir_perms; |
| 137 | allow init sysfs_type:file w_file_perms; |
| 138 | |
Nick Kralevich | fed8a2a | 2014-01-24 20:43:07 -0800 | [diff] [blame] | 139 | # Transitions to seclabel processes in init.rc |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 140 | domain_trans(init, rootfs, adbd) |
| 141 | domain_trans(init, rootfs, healthd) |
| 142 | recovery_only(` |
| 143 | domain_trans(init, rootfs, recovery) |
| 144 | ') |
| 145 | domain_trans(init, shell_exec, shell) |
| 146 | domain_trans(init, rootfs, ueventd) |
| 147 | domain_trans(init, rootfs, watchdogd) |
| 148 | |
| 149 | # Certain domains need LD_PRELOAD passed from init. |
| 150 | # https://android-review.googlesource.com/94851 |
Nick Kralevich | 8a5b28d | 2014-07-16 18:42:36 -0700 | [diff] [blame] | 151 | # For now, allow it to most domains. |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 152 | # TODO: scope this down. |
Nick Kralevich | 8a5b28d | 2014-07-16 18:42:36 -0700 | [diff] [blame] | 153 | allow init { domain -lmkd }:process noatsecure; |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 154 | |
| 155 | # Support "adb shell stop" |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 156 | allow init self:capability kill; |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 157 | allow init domain:process sigkill; |
Nick Kralevich | cd905ec | 2014-05-08 23:28:52 -0700 | [diff] [blame] | 158 | |
| 159 | # Init creates keystore's directory on boot, and walks through |
| 160 | # the directory as part of a recursive restorecon. |
| 161 | allow init keystore_data_file:dir { open create read getattr setattr search }; |
| 162 | allow init keystore_data_file:file { getattr }; |
Stephen Smalley | 356f4be | 2014-05-23 11:26:19 -0400 | [diff] [blame] | 163 | |
Nick Kralevich | ee49c0e | 2014-06-07 10:00:59 -0700 | [diff] [blame] | 164 | # Init creates /data/local/tmp at boot |
| 165 | allow init shell_data_file:dir { open create read getattr setattr search }; |
| 166 | allow init shell_data_file:file { getattr }; |
| 167 | |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 168 | # Set UID and GID for services. |
| 169 | allow init self:capability { setuid setgid }; |
| 170 | |
Stephen Smalley | 356f4be | 2014-05-23 11:26:19 -0400 | [diff] [blame] | 171 | # Use setexeccon(), setfscreatecon(), and setsockcreatecon(). |
| 172 | # setexec is for services with seclabel options. |
| 173 | # setfscreate is for labeling directories and socket files. |
| 174 | # setsockcreate is for labeling local/unix domain sockets. |
| 175 | allow init self:process { setexec setfscreate setsockcreate }; |
Stephen Smalley | ad0d0fc | 2014-05-29 09:22:16 -0400 | [diff] [blame] | 176 | |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 177 | # Perform SELinux access checks on setting properties. |
| 178 | selinux_check_access(init) |
| 179 | |
| 180 | # Ask the kernel for the new context on services to label their sockets. |
| 181 | allow init kernel:security compute_create; |
| 182 | |
| 183 | # Create sockets for the services. |
| 184 | allow init domain:unix_stream_socket { create bind }; |
| 185 | allow init domain:unix_dgram_socket { create bind }; |
| 186 | |
Stephen Smalley | ad0d0fc | 2014-05-29 09:22:16 -0400 | [diff] [blame] | 187 | # Create /data/property and files within it. |
| 188 | allow init property_data_file:dir create_dir_perms; |
| 189 | allow init property_data_file:file create_file_perms; |
Stephen Smalley | bac4ccc | 2014-06-18 10:09:35 -0400 | [diff] [blame] | 190 | |
Stephen Smalley | fee4915 | 2014-06-19 10:27:02 -0400 | [diff] [blame] | 191 | # Set any property. |
| 192 | allow init property_type:property_service set; |
| 193 | |
Nick Kralevich | 0db95cc | 2014-06-20 21:15:56 -0700 | [diff] [blame] | 194 | # Run "ifup lo" to bring up the localhost interface |
| 195 | allow init self:udp_socket { create ioctl }; |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 196 | allow init self:capability net_raw; |
Nick Kralevich | 0db95cc | 2014-06-20 21:15:56 -0700 | [diff] [blame] | 197 | |
Nick Kralevich | a7c04dc | 2014-07-03 22:13:14 -0700 | [diff] [blame] | 198 | # This line seems suspect, as it should not really need to |
| 199 | # set scheduling parameters for a kernel domain task. |
| 200 | allow init kernel:process setsched; |
| 201 | |
Nick Kralevich | beb279c | 2014-10-20 11:52:19 -0700 | [diff] [blame] | 202 | # swapon() needs write access to swap device |
| 203 | # system/core/fs_mgr/fs_mgr.c - fs_mgr_swapon_all |
| 204 | allow init swap_block_device:blk_file rw_file_perms; |
| 205 | |
Stephen Smalley | 0d08d47 | 2014-10-21 10:09:33 -0400 | [diff] [blame] | 206 | # Read from /dev/hw_random if present. |
| 207 | # system/core/init/init.c - mix_hwrng_into_linux_rng_action |
| 208 | allow init hw_random_device:chr_file r_file_perms; |
| 209 | |
| 210 | # Create and access /dev files without a specific type, |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 211 | # e.g. /dev/.coldboot_done, /dev/.booting |
Stephen Smalley | 0d08d47 | 2014-10-21 10:09:33 -0400 | [diff] [blame] | 212 | # TODO: Move these files into their own type unless they are |
| 213 | # only ever accessed by init. |
| 214 | allow init device:file create_file_perms; |
| 215 | auditallow init device:file create_file_perms; |
| 216 | |
| 217 | # Access character devices without a specific type, |
| 218 | # e.g. /dev/keychord. |
| 219 | # TODO: Move these devices into their own type unless they |
| 220 | # are only ever accessed by init. |
| 221 | allow init device:chr_file { rw_file_perms setattr }; |
| 222 | auditallow init device:chr_file { rw_file_perms setattr }; |
| 223 | |
Stephen Smalley | a523aac | 2014-10-24 15:56:15 -0400 | [diff] [blame] | 224 | # keychord configuration |
| 225 | allow init self:capability sys_tty_config; |
| 226 | |
Stephen Smalley | bac4ccc | 2014-06-18 10:09:35 -0400 | [diff] [blame] | 227 | ### |
| 228 | ### neverallow rules |
| 229 | ### |
| 230 | |
| 231 | # The init domain is only entered via setcon from the kernel domain, |
| 232 | # never via an exec-based transition. |
| 233 | neverallow { domain -kernel} init:process dyntransition; |
| 234 | neverallow domain init:process transition; |
| 235 | neverallow init { file_type fs_type }:file entrypoint; |
Stephen Smalley | 018e940 | 2014-09-02 17:05:44 -0400 | [diff] [blame] | 236 | |
| 237 | # Never read/follow symlinks created by shell or untrusted apps. |
| 238 | neverallow init shell_data_file:lnk_file read; |
| 239 | neverallow init app_data_file:lnk_file read; |
Stephen Smalley | 8a0c25e | 2014-09-23 09:11:30 -0400 | [diff] [blame] | 240 | |
| 241 | # init should never execute a program without changing to another domain. |
| 242 | neverallow init { file_type fs_type }:file execute_no_trans; |