Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 1 | # Rules for all domains. |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 2 | |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 3 | # Allow reaping by init. |
| 4 | allow domain init:process sigchld; |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 5 | |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 6 | # Intra-domain accesses. |
| 7 | allow domain self:process { |
| 8 | fork |
| 9 | sigchld |
| 10 | sigkill |
| 11 | sigstop |
| 12 | signull |
| 13 | signal |
| 14 | getsched |
| 15 | setsched |
| 16 | getsession |
| 17 | getpgid |
| 18 | setpgid |
| 19 | getcap |
| 20 | setcap |
| 21 | getattr |
| 22 | setrlimit |
| 23 | }; |
| 24 | allow domain self:fd use; |
| 25 | allow domain proc:dir r_dir_perms; |
| 26 | allow domain proc_net_type:dir search; |
| 27 | r_dir_file(domain, self) |
| 28 | allow domain self:{ fifo_file file } rw_file_perms; |
| 29 | allow domain self:unix_dgram_socket { create_socket_perms sendto }; |
| 30 | allow domain self:unix_stream_socket { create_stream_socket_perms connectto }; |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 31 | |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 32 | # Inherit or receive open files from others. |
| 33 | allow domain init:fd use; |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 34 | |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 35 | # Root fs. |
| 36 | allow domain tmpfs:dir { getattr search }; |
| 37 | allow domain rootfs:dir search; |
| 38 | allow domain rootfs:lnk_file { read getattr }; |
| 39 | |
| 40 | # Device accesses. |
| 41 | allow domain device:dir search; |
| 42 | allow domain dev_type:lnk_file r_file_perms; |
| 43 | allow domain devpts:dir search; |
| 44 | allow domain socket_device:dir r_dir_perms; |
| 45 | allow domain owntty_device:chr_file rw_file_perms; |
| 46 | allow domain null_device:chr_file rw_file_perms; |
| 47 | allow domain zero_device:chr_file rw_file_perms; |
| 48 | |
| 49 | # /dev/binder can be accessed by ... everyone! :) |
| 50 | allow { domain -hwservicemanager } binder_device:chr_file rw_file_perms; |
| 51 | |
| 52 | # Restrict binder ioctls to an allowlist. Additional ioctl commands may be |
| 53 | # added to individual domains, but this sets safe defaults for all processes. |
| 54 | allowxperm domain binder_device:chr_file ioctl { unpriv_binder_ioctls }; |
| 55 | |
| 56 | # /dev/binderfs needs to be accessed by everyone too! |
| 57 | allow domain binderfs:dir { getattr search }; |
| 58 | allow domain binderfs_logs_proc:dir search; |
| 59 | |
| 60 | allow { domain -servicemanager } hwbinder_device:chr_file rw_file_perms; |
| 61 | allow domain ptmx_device:chr_file rw_file_perms; |
| 62 | allow domain random_device:chr_file rw_file_perms; |
| 63 | allow domain proc_random:dir r_dir_perms; |
| 64 | allow domain proc_random:file r_file_perms; |
| 65 | allow domain properties_device:dir { search getattr }; |
| 66 | allow domain properties_serial:file r_file_perms; |
| 67 | allow domain property_info:file r_file_perms; |
| 68 | |
| 69 | allow domain property_contexts_file:file r_file_perms; |
| 70 | |
| 71 | allow domain init:key search; |
| 72 | |
| 73 | # logd access |
| 74 | unix_socket_send(domain, logdw, logd) |
| 75 | |
| 76 | # Directory/link file access for path resolution. |
| 77 | allow domain { |
| 78 | system_file |
| 79 | system_lib_file |
| 80 | system_seccomp_policy_file |
| 81 | system_security_cacerts_file |
| 82 | }:dir r_dir_perms; |
| 83 | allow domain system_file:lnk_file { getattr read }; |
| 84 | |
| 85 | # Global access to /system/etc/security/cacerts/*, /system/etc/seccomp_policy/*, /system/lib[64]/*, |
| 86 | # /(system|product|system_ext)/etc/(group|passwd), linker and its config. |
| 87 | allow domain system_seccomp_policy_file:file r_file_perms; |
| 88 | # cacerts are accessible from public Java API. |
| 89 | allow domain system_security_cacerts_file:file r_file_perms; |
| 90 | allow domain system_group_file:file r_file_perms; |
| 91 | allow domain system_passwd_file:file r_file_perms; |
| 92 | allow domain system_linker_exec:file { execute read open getattr map }; |
| 93 | allow domain system_linker_config_file:file r_file_perms; |
| 94 | allow domain system_lib_file:file { execute read open getattr map }; |
| 95 | # To allow following symlinks at /system/bin/linker, /system/lib/libc.so, etc. |
| 96 | allow domain system_linker_exec:lnk_file { read open getattr }; |
| 97 | allow domain system_lib_file:lnk_file { read open getattr }; |
| 98 | |
| 99 | allow domain system_event_log_tags_file:file r_file_perms; |
| 100 | |
| 101 | allow coredomain system_file:file { execute read open getattr map }; |
| 102 | |
| 103 | # All domains get access to /vendor/etc |
| 104 | allow domain vendor_configs_file:dir r_dir_perms; |
| 105 | allow domain vendor_configs_file:file { read open getattr map }; |
| 106 | |
| 107 | # Allow all domains to be able to follow /system/vendor and/or |
| 108 | # /vendor/odm symlinks. |
| 109 | allow domain vendor_file_type:lnk_file { getattr open read }; |
| 110 | |
| 111 | # This is required to be able to search & read /vendor/lib64 |
| 112 | # in order to lookup vendor libraries. The execute permission |
| 113 | # for coredomains is granted *only* for same process HALs |
| 114 | allow domain vendor_file:dir { getattr search }; |
| 115 | |
| 116 | # Allow reading and executing out of /vendor to all vendor domains |
| 117 | allow { domain -coredomain } vendor_file_type:dir r_dir_perms; |
| 118 | allow { domain -coredomain } vendor_file_type:file { read open getattr execute map }; |
| 119 | allow { domain -coredomain } vendor_file_type:lnk_file { getattr read }; |
| 120 | |
| 121 | # read and stat any sysfs symlinks |
| 122 | allow domain sysfs:lnk_file { getattr read }; |
| 123 | |
| 124 | # Lots of processes access current CPU information |
| 125 | r_dir_file(domain, sysfs_devices_system_cpu) |
| 126 | |
| 127 | # If kernel CONFIG_TRANSPARENT_HUGEPAGE is enabled, libjemalloc5 (statically |
| 128 | # included by libc) reads /sys/kernel/mm/transparent_hugepage/enabled. |
| 129 | allow domain sysfs_transparent_hugepage:dir search; |
| 130 | allow domain sysfs_transparent_hugepage:file r_file_perms; |
| 131 | |
| 132 | allow coredomain system_data_file:dir getattr; |
| 133 | # /data has the label system_data_root_file. Vendor components need the search |
| 134 | # permission on system_data_root_file for path traversal to /data/vendor. |
| 135 | allow domain system_data_root_file:dir { search getattr } ; |
| 136 | allow domain system_data_file:dir search; |
| 137 | # TODO restrict this to non-coredomain |
| 138 | allow domain vendor_data_file:dir { getattr search }; |
| 139 | |
| 140 | # required by the dynamic linker |
| 141 | allow domain proc:lnk_file { getattr read }; |
| 142 | |
| 143 | # /proc/cpuinfo |
| 144 | allow domain proc_cpuinfo:file r_file_perms; |
| 145 | |
| 146 | # profiling needs to read /proc/sys/kernel/perf_event_max_sample_rate |
| 147 | allow domain proc_perf:file r_file_perms; |
| 148 | |
| 149 | # toybox loads libselinux which stats /sys/fs/selinux/ |
| 150 | allow domain selinuxfs:dir search; |
| 151 | allow domain selinuxfs:file getattr; |
| 152 | allow domain sysfs:dir search; |
| 153 | allow domain selinuxfs:filesystem getattr; |
| 154 | |
| 155 | # Almost all processes log tracing information to |
| 156 | # /sys/kernel/debug/tracing/trace_marker |
| 157 | # The reason behind this is documented in b/6513400 |
| 158 | allow domain debugfs:dir search; |
| 159 | allow domain debugfs_tracing:dir search; |
| 160 | allow domain debugfs_tracing_debug:dir search; |
| 161 | allow domain debugfs_trace_marker:file w_file_perms; |
| 162 | |
| 163 | # Linux lockdown mode offers coarse-grained definitions for access controls. |
| 164 | # The "confidentiality" level detects access to tracefs or the perf subsystem. |
| 165 | # This overlaps with more precise declarations in Android's policy. The |
| 166 | # debugfs_trace_marker above is an example in which all processes should have |
| 167 | # some access to tracefs. Therefore, allow all domains to access this level. |
| 168 | # The "integrity" level is however enforced. |
| 169 | allow domain self:lockdown confidentiality; |
| 170 | |
| 171 | # Filesystem access. |
| 172 | allow domain fs_type:filesystem getattr; |
| 173 | allow domain fs_type:dir getattr; |
| 174 | |
| 175 | # Restrict all domains to an allowlist for common socket types. Additional |
| 176 | # ioctl commands may be added to individual domains, but this sets safe |
| 177 | # defaults for all processes. Note that granting this allowlist to domain does |
| 178 | # not grant the ioctl permission on these socket types. That must be granted |
| 179 | # separately. |
| 180 | allowxperm domain domain:{ icmp_socket rawip_socket tcp_socket udp_socket } |
| 181 | ioctl { unpriv_sock_ioctls unpriv_tty_ioctls }; |
| 182 | # default allowlist for unix sockets. |
| 183 | allowxperm domain { domain pdx_channel_socket_type }:{ unix_dgram_socket unix_stream_socket } |
| 184 | ioctl unpriv_unix_sock_ioctls; |
| 185 | |
| 186 | # Restrict PTYs to only allowed ioctls. |
| 187 | # Note that granting this allowlist to domain does |
| 188 | # not grant the wider ioctl permission. That must be granted |
| 189 | # separately. |
| 190 | allowxperm domain devpts:chr_file ioctl unpriv_tty_ioctls; |
| 191 | |
| 192 | # All domains must clearly enumerate what ioctls they use |
| 193 | # on filesystem objects (plain files, directories, symbolic links, |
| 194 | # named pipes, and named sockets). We start off with a safe set. |
| 195 | allowxperm domain { file_type fs_type domain dev_type }:{ dir notdevfile_class_set blk_file } ioctl { FIOCLEX FIONCLEX }; |
| 196 | |
| 197 | # If a domain has ioctl access to tun_device, it must clearly enumerate the |
| 198 | # ioctls used. Safe defaults are listed below. |
| 199 | allowxperm domain tun_device:chr_file ioctl { FIOCLEX FIONCLEX }; |
| 200 | |
| 201 | # Allow a process to make a determination whether a file descriptor |
| 202 | # for a plain file or pipe (fifo_file) is a tty. Note that granting |
| 203 | # this allowlist to domain does not grant the ioctl permission to |
| 204 | # these files. That must be granted separately. |
| 205 | allowxperm domain { file_type fs_type }:file ioctl { TCGETS }; |
| 206 | allowxperm domain domain:fifo_file ioctl { TCGETS }; |
| 207 | |
| 208 | # If a domain has access to perform an ioctl on a block device, allow these |
| 209 | # very common, benign ioctls |
| 210 | allowxperm domain dev_type:blk_file ioctl { BLKGETSIZE64 BLKSSZGET }; |
| 211 | |
| 212 | # read APEX dir and stat any symlink pointing to APEXs. |
| 213 | allow domain apex_mnt_dir:dir { getattr search }; |
| 214 | allow domain apex_mnt_dir:lnk_file r_file_perms; |
| 215 | |
| 216 | allow domain self:global_capability_class_set audit_control; |
| 217 | allow domain self:netlink_audit_socket { create_socket_perms_no_ioctl nlmsg_write }; |
| 218 | |
| 219 | # workaround for supressing property accesses. |
| 220 | # TODO: remove these |
Andrew Scull | 6f3e5fe | 2021-07-02 12:38:21 +0000 | [diff] [blame] | 221 | set_prop(domain, property_type -vmsecret_keymint_prop) |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 222 | # auditallow { domain -init } property_type:property_service set; |
| 223 | # auditallow { domain -init } property_type:file rw_file_perms; |
| 224 | |
| 225 | allow domain linkerconfig_file:dir search; |
| 226 | allow domain linkerconfig_file:file r_file_perms; |
| 227 | |
| 228 | #----------------------------------------- |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 229 | # Path resolution access in cgroups. |
| 230 | allow domain cgroup:dir search; |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 231 | allow { domain } cgroup:dir w_dir_perms; |
| 232 | allow { domain } cgroup:file w_file_perms; |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 233 | |
| 234 | allow domain cgroup_v2:dir search; |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 235 | allow { domain } cgroup_v2:dir w_dir_perms; |
| 236 | allow { domain } cgroup_v2:file w_file_perms; |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 237 | |
| 238 | allow domain cgroup_rc_file:dir search; |
| 239 | allow domain cgroup_rc_file:file r_file_perms; |
| 240 | allow domain task_profiles_file:file r_file_perms; |
| 241 | allow domain task_profiles_api_file:file r_file_perms; |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 242 | |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 243 | #----------------------------------------- |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 244 | # Allow access to fsverity keyring. |
| 245 | allow domain kernel:key search; |
Inseob Kim | ff43be2 | 2021-06-07 16:56:56 +0900 | [diff] [blame] | 246 | |
Inseob Kim | 4eb5660 | 2021-07-09 15:51:12 +0900 | [diff] [blame] | 247 | # Transition to crash_dump when /system/bin/crash_dump* is executed. |
| 248 | # This occurs when the process crashes. |
| 249 | # We do not apply this to the su domain to avoid interfering with |
| 250 | # tests (b/114136122) |
| 251 | domain_auto_trans(domain, crash_dump_exec, crash_dump); |
| 252 | allow domain crash_dump:process sigchld; |