1*e4a36f41SAndroid Build Coastguard Worker# Transition to crash_dump when /system/bin/crash_dump* is executed. 2*e4a36f41SAndroid Build Coastguard Worker# This occurs when the process crashes. 3*e4a36f41SAndroid Build Coastguard Worker# We do not apply this to the su domain to avoid interfering with 4*e4a36f41SAndroid Build Coastguard Worker# tests (b/114136122) 5*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans({ domain userdebug_or_eng(`-su') }, crash_dump_exec, crash_dump); 6*e4a36f41SAndroid Build Coastguard Workerallow domain crash_dump:process sigchld; 7*e4a36f41SAndroid Build Coastguard Worker 8*e4a36f41SAndroid Build Coastguard Worker# Allow every process to check the heapprofd.enable properties to determine 9*e4a36f41SAndroid Build Coastguard Worker# whether to load the heap profiling library. This does not necessarily enable 10*e4a36f41SAndroid Build Coastguard Worker# heap profiling, as initialization will fail if it does not have the 11*e4a36f41SAndroid Build Coastguard Worker# necessary SELinux permissions. 12*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, heapprofd_prop); 13*e4a36f41SAndroid Build Coastguard Worker# Allow heap profiling on debug builds. 14*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`can_profile_heap({ 15*e4a36f41SAndroid Build Coastguard Worker domain 16*e4a36f41SAndroid Build Coastguard Worker -bpfloader 17*e4a36f41SAndroid Build Coastguard Worker -init 18*e4a36f41SAndroid Build Coastguard Worker -kernel 19*e4a36f41SAndroid Build Coastguard Worker -keystore 20*e4a36f41SAndroid Build Coastguard Worker -llkd 21*e4a36f41SAndroid Build Coastguard Worker -logd 22*e4a36f41SAndroid Build Coastguard Worker -logpersist 23*e4a36f41SAndroid Build Coastguard Worker -recovery 24*e4a36f41SAndroid Build Coastguard Worker -recovery_persist 25*e4a36f41SAndroid Build Coastguard Worker -recovery_refresh 26*e4a36f41SAndroid Build Coastguard Worker -ueventd 27*e4a36f41SAndroid Build Coastguard Worker -vendor_init 28*e4a36f41SAndroid Build Coastguard Worker -vold 29*e4a36f41SAndroid Build Coastguard Worker})') 30*e4a36f41SAndroid Build Coastguard Worker 31*e4a36f41SAndroid Build Coastguard Worker# As above, allow perf profiling most processes on debug builds. 32*e4a36f41SAndroid Build Coastguard Worker# zygote is excluded as system-wide profiling could end up with it 33*e4a36f41SAndroid Build Coastguard Worker# (unexpectedly) holding an open fd across a fork. 34*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`can_profile_perf({ 35*e4a36f41SAndroid Build Coastguard Worker domain 36*e4a36f41SAndroid Build Coastguard Worker -bpfloader 37*e4a36f41SAndroid Build Coastguard Worker -init 38*e4a36f41SAndroid Build Coastguard Worker -kernel 39*e4a36f41SAndroid Build Coastguard Worker -keystore 40*e4a36f41SAndroid Build Coastguard Worker -llkd 41*e4a36f41SAndroid Build Coastguard Worker -logd 42*e4a36f41SAndroid Build Coastguard Worker -logpersist 43*e4a36f41SAndroid Build Coastguard Worker -recovery 44*e4a36f41SAndroid Build Coastguard Worker -recovery_persist 45*e4a36f41SAndroid Build Coastguard Worker -recovery_refresh 46*e4a36f41SAndroid Build Coastguard Worker -ueventd 47*e4a36f41SAndroid Build Coastguard Worker -vendor_init 48*e4a36f41SAndroid Build Coastguard Worker -vold 49*e4a36f41SAndroid Build Coastguard Worker -zygote 50*e4a36f41SAndroid Build Coastguard Worker})') 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Worker# Everyone can access the IncFS list of features. 53*e4a36f41SAndroid Build Coastguard Workerr_dir_file(domain, sysfs_fs_incfs_features); 54*e4a36f41SAndroid Build Coastguard Worker 55*e4a36f41SAndroid Build Coastguard Worker# Path resolution access in cgroups. 56*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup:dir search; 57*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup:dir w_dir_perms; 58*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup:file w_file_perms; 59*e4a36f41SAndroid Build Coastguard Worker 60*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup_v2:dir search; 61*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup_v2:dir w_dir_perms; 62*e4a36f41SAndroid Build Coastguard Workerallow { domain -appdomain -rs } cgroup_v2:file w_file_perms; 63*e4a36f41SAndroid Build Coastguard Worker 64*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup_rc_file:dir search; 65*e4a36f41SAndroid Build Coastguard Workerallow domain cgroup_rc_file:file r_file_perms; 66*e4a36f41SAndroid Build Coastguard Workerallow domain task_profiles_file:file r_file_perms; 67*e4a36f41SAndroid Build Coastguard Workerallow domain task_profiles_api_file:file r_file_perms; 68*e4a36f41SAndroid Build Coastguard Workerallow domain vendor_task_profiles_file:file r_file_perms; 69*e4a36f41SAndroid Build Coastguard Worker 70*e4a36f41SAndroid Build Coastguard Worker# Allow all domains to read sys.use_memfd to determine 71*e4a36f41SAndroid Build Coastguard Worker# if memfd support can be used if device supports it 72*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, use_memfd_prop); 73*e4a36f41SAndroid Build Coastguard Worker 74*e4a36f41SAndroid Build Coastguard Worker# Read access to sdkextensions props 75*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, module_sdkextensions_prop) 76*e4a36f41SAndroid Build Coastguard Worker 77*e4a36f41SAndroid Build Coastguard Worker# Read access to bq configuration values 78*e4a36f41SAndroid Build Coastguard Workerget_prop(domain, bq_config_prop); 79*e4a36f41SAndroid Build Coastguard Worker 80*e4a36f41SAndroid Build Coastguard Worker# For now, everyone can access core property files 81*e4a36f41SAndroid Build Coastguard Worker# Device specific properties are not granted by default 82*e4a36f41SAndroid Build Coastguard Workernot_compatible_property(` 83*e4a36f41SAndroid Build Coastguard Worker # DO NOT ADD ANY PROPERTIES HERE 84*e4a36f41SAndroid Build Coastguard Worker get_prop(domain, core_property_type) 85*e4a36f41SAndroid Build Coastguard Worker get_prop(domain, exported3_system_prop) 86*e4a36f41SAndroid Build Coastguard Worker get_prop(domain, vendor_default_prop) 87*e4a36f41SAndroid Build Coastguard Worker') 88*e4a36f41SAndroid Build Coastguard Workercompatible_property_only(` 89*e4a36f41SAndroid Build Coastguard Worker # DO NOT ADD ANY PROPERTIES HERE 90*e4a36f41SAndroid Build Coastguard Worker get_prop({coredomain appdomain shell}, core_property_type) 91*e4a36f41SAndroid Build Coastguard Worker get_prop({coredomain appdomain shell}, exported3_system_prop) 92*e4a36f41SAndroid Build Coastguard Worker get_prop({coredomain appdomain shell}, exported_camera_prop) 93*e4a36f41SAndroid Build Coastguard Worker get_prop({coredomain shell}, userspace_reboot_exported_prop) 94*e4a36f41SAndroid Build Coastguard Worker get_prop({coredomain shell}, userspace_reboot_log_prop) 95*e4a36f41SAndroid Build Coastguard Worker get_prop({coredomain shell}, userspace_reboot_test_prop) 96*e4a36f41SAndroid Build Coastguard Worker get_prop({domain -coredomain -appdomain}, vendor_default_prop) 97*e4a36f41SAndroid Build Coastguard Worker') 98*e4a36f41SAndroid Build Coastguard Worker 99*e4a36f41SAndroid Build Coastguard Worker# Allow access to fsverity keyring. 100*e4a36f41SAndroid Build Coastguard Workerallow domain kernel:key search; 101*e4a36f41SAndroid Build Coastguard Worker# Allow access to keys in the fsverity keyring that were installed at boot. 102*e4a36f41SAndroid Build Coastguard Workerallow domain fsverity_init:key search; 103*e4a36f41SAndroid Build Coastguard Worker# For testing purposes, allow access to keys installed with su. 104*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(` 105*e4a36f41SAndroid Build Coastguard Worker allow domain su:key search; 106*e4a36f41SAndroid Build Coastguard Worker') 107*e4a36f41SAndroid Build Coastguard Worker 108*e4a36f41SAndroid Build Coastguard Worker# Allow access to linkerconfig file 109*e4a36f41SAndroid Build Coastguard Workerallow domain linkerconfig_file:dir search; 110*e4a36f41SAndroid Build Coastguard Workerallow domain linkerconfig_file:file r_file_perms; 111*e4a36f41SAndroid Build Coastguard Worker 112*e4a36f41SAndroid Build Coastguard Worker# Allow all processes to check for the existence of the boringssl_self_test_marker files. 113*e4a36f41SAndroid Build Coastguard Workerallow domain boringssl_self_test_marker:dir search; 114*e4a36f41SAndroid Build Coastguard Worker 115*e4a36f41SAndroid Build Coastguard Worker# Limit ability to ptrace or read sensitive /proc/pid files of processes 116*e4a36f41SAndroid Build Coastguard Worker# with other UIDs to these allowlisted domains. 117*e4a36f41SAndroid Build Coastguard Workerneverallow { 118*e4a36f41SAndroid Build Coastguard Worker domain 119*e4a36f41SAndroid Build Coastguard Worker -vold 120*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-llkd') 121*e4a36f41SAndroid Build Coastguard Worker -dumpstate 122*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-incidentd') 123*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-profcollectd') 124*e4a36f41SAndroid Build Coastguard Worker -storaged 125*e4a36f41SAndroid Build Coastguard Worker -system_server 126*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set sys_ptrace; 127*e4a36f41SAndroid Build Coastguard Worker 128*e4a36f41SAndroid Build Coastguard Worker# Limit ability to generate hardware unique device ID attestations to priv_apps 129*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -priv_app -gmscore_app } *:keystore_key gen_unique_id; 130*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -priv_app -gmscore_app } *:keystore2_key gen_unique_id; 131*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server } *:keystore2_key use_dev_id; 132*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server } keystore:keystore2 { clear_ns lock reset unlock }; 133*e4a36f41SAndroid Build Coastguard Worker 134*e4a36f41SAndroid Build Coastguard Workerneverallow { 135*e4a36f41SAndroid Build Coastguard Worker domain 136*e4a36f41SAndroid Build Coastguard Worker -init 137*e4a36f41SAndroid Build Coastguard Worker -vendor_init 138*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-domain') 139*e4a36f41SAndroid Build Coastguard Worker} debugfs_tracing_debug:file no_rw_file_perms; 140*e4a36f41SAndroid Build Coastguard Worker 141*e4a36f41SAndroid Build Coastguard Worker# System_server owns dropbox data, and init creates/restorecons the directory 142*e4a36f41SAndroid Build Coastguard Worker# Disallow direct access by other processes. 143*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } dropbox_data_file:dir *; 144*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } dropbox_data_file:file ~{ getattr read }; 145*e4a36f41SAndroid Build Coastguard Worker 146*e4a36f41SAndroid Build Coastguard Worker### 147*e4a36f41SAndroid Build Coastguard Worker# Services should respect app sandboxes 148*e4a36f41SAndroid Build Coastguard Workerneverallow { 149*e4a36f41SAndroid Build Coastguard Worker domain 150*e4a36f41SAndroid Build Coastguard Worker -appdomain 151*e4a36f41SAndroid Build Coastguard Worker -installd # creation of sandbox 152*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir_file_class_set { create unlink }; 153*e4a36f41SAndroid Build Coastguard Worker 154*e4a36f41SAndroid Build Coastguard Worker# Only the following processes should be directly accessing private app 155*e4a36f41SAndroid Build Coastguard Worker# directories. 156*e4a36f41SAndroid Build Coastguard Workerneverallow { 157*e4a36f41SAndroid Build Coastguard Worker domain 158*e4a36f41SAndroid Build Coastguard Worker -adbd 159*e4a36f41SAndroid Build Coastguard Worker -appdomain 160*e4a36f41SAndroid Build Coastguard Worker -app_zygote 161*e4a36f41SAndroid Build Coastguard Worker -dexoptanalyzer 162*e4a36f41SAndroid Build Coastguard Worker -installd 163*e4a36f41SAndroid Build Coastguard Worker -iorap_inode2filename 164*e4a36f41SAndroid Build Coastguard Worker -iorap_prefetcherd 165*e4a36f41SAndroid Build Coastguard Worker -profman 166*e4a36f41SAndroid Build Coastguard Worker -rs # spawned by appdomain, so carryover the exception above 167*e4a36f41SAndroid Build Coastguard Worker -runas 168*e4a36f41SAndroid Build Coastguard Worker -system_server 169*e4a36f41SAndroid Build Coastguard Worker -viewcompiler 170*e4a36f41SAndroid Build Coastguard Worker -zygote 171*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir *; 172*e4a36f41SAndroid Build Coastguard Worker 173*e4a36f41SAndroid Build Coastguard Worker# Only apps should be modifying app data. installd is exempted for 174*e4a36f41SAndroid Build Coastguard Worker# restorecon and package install/uninstall. 175*e4a36f41SAndroid Build Coastguard Workerneverallow { 176*e4a36f41SAndroid Build Coastguard Worker domain 177*e4a36f41SAndroid Build Coastguard Worker -appdomain 178*e4a36f41SAndroid Build Coastguard Worker -installd 179*e4a36f41SAndroid Build Coastguard Worker -rs # spawned by appdomain, so carryover the exception above 180*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir ~r_dir_perms; 181*e4a36f41SAndroid Build Coastguard Worker 182*e4a36f41SAndroid Build Coastguard Workerneverallow { 183*e4a36f41SAndroid Build Coastguard Worker domain 184*e4a36f41SAndroid Build Coastguard Worker -appdomain 185*e4a36f41SAndroid Build Coastguard Worker -app_zygote 186*e4a36f41SAndroid Build Coastguard Worker -installd 187*e4a36f41SAndroid Build Coastguard Worker -iorap_prefetcherd 188*e4a36f41SAndroid Build Coastguard Worker -rs # spawned by appdomain, so carryover the exception above 189*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:file_class_set open; 190*e4a36f41SAndroid Build Coastguard Worker 191*e4a36f41SAndroid Build Coastguard Workerneverallow { 192*e4a36f41SAndroid Build Coastguard Worker domain 193*e4a36f41SAndroid Build Coastguard Worker -appdomain 194*e4a36f41SAndroid Build Coastguard Worker -installd # creation of sandbox 195*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir_file_class_set { create unlink }; 196*e4a36f41SAndroid Build Coastguard Worker 197*e4a36f41SAndroid Build Coastguard Workerneverallow { 198*e4a36f41SAndroid Build Coastguard Worker domain 199*e4a36f41SAndroid Build Coastguard Worker -installd 200*e4a36f41SAndroid Build Coastguard Worker} { privapp_data_file app_data_file }:dir_file_class_set { relabelfrom relabelto }; 201*e4a36f41SAndroid Build Coastguard Worker 202*e4a36f41SAndroid Build Coastguard Worker# The staging directory contains APEX and APK files. It is important to ensure 203*e4a36f41SAndroid Build Coastguard Worker# that these files cannot be accessed by other domains to ensure that the files 204*e4a36f41SAndroid Build Coastguard Worker# do not change between system_server staging the files and apexd processing 205*e4a36f41SAndroid Build Coastguard Worker# the files. 206*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server -apexd -installd -iorap_inode2filename -priv_app } staging_data_file:dir *; 207*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_app -system_server -apexd -adbd -kernel -installd -iorap_inode2filename -priv_app } staging_data_file:file *; 208*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server -installd} staging_data_file:dir no_w_dir_perms; 209*e4a36f41SAndroid Build Coastguard Worker# apexd needs the link and unlink permissions, so list every `no_w_file_perms` 210*e4a36f41SAndroid Build Coastguard Worker# except for `link` and `unlink`. 211*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } staging_data_file:file 212*e4a36f41SAndroid Build Coastguard Worker { append create relabelfrom rename setattr write no_x_file_perms }; 213*e4a36f41SAndroid Build Coastguard Worker 214*e4a36f41SAndroid Build Coastguard Workerneverallow { 215*e4a36f41SAndroid Build Coastguard Worker domain 216*e4a36f41SAndroid Build Coastguard Worker -appdomain # for oemfs 217*e4a36f41SAndroid Build Coastguard Worker -bootanim # for oemfs 218*e4a36f41SAndroid Build Coastguard Worker -recovery # for /tmp/update_binary in tmpfs 219*e4a36f41SAndroid Build Coastguard Worker} { fs_type -rootfs }:file execute; 220*e4a36f41SAndroid Build Coastguard Worker 221*e4a36f41SAndroid Build Coastguard Worker# 222*e4a36f41SAndroid Build Coastguard Worker# Assert that, to the extent possible, we're not loading executable content from 223*e4a36f41SAndroid Build Coastguard Worker# outside the rootfs or /system partition except for a few allowlisted domains. 224*e4a36f41SAndroid Build Coastguard Worker# Executable files loaded from /data is a persistence vector 225*e4a36f41SAndroid Build Coastguard Worker# we want to avoid. See 226*e4a36f41SAndroid Build Coastguard Worker# https://bugs.chromium.org/p/project-zero/issues/detail?id=955 for example. 227*e4a36f41SAndroid Build Coastguard Worker# 228*e4a36f41SAndroid Build Coastguard Workerneverallow { 229*e4a36f41SAndroid Build Coastguard Worker domain 230*e4a36f41SAndroid Build Coastguard Worker -appdomain 231*e4a36f41SAndroid Build Coastguard Worker with_asan(`-asan_extract') 232*e4a36f41SAndroid Build Coastguard Worker -iorap_prefetcherd 233*e4a36f41SAndroid Build Coastguard Worker -shell 234*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-su') 235*e4a36f41SAndroid Build Coastguard Worker -system_server_startup # for memfd backed executable regions 236*e4a36f41SAndroid Build Coastguard Worker -app_zygote 237*e4a36f41SAndroid Build Coastguard Worker -webview_zygote 238*e4a36f41SAndroid Build Coastguard Worker -zygote 239*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-mediaextractor') 240*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-mediaswcodec') 241*e4a36f41SAndroid Build Coastguard Worker} { 242*e4a36f41SAndroid Build Coastguard Worker file_type 243*e4a36f41SAndroid Build Coastguard Worker -system_file_type 244*e4a36f41SAndroid Build Coastguard Worker -system_lib_file 245*e4a36f41SAndroid Build Coastguard Worker -system_linker_exec 246*e4a36f41SAndroid Build Coastguard Worker -vendor_file_type 247*e4a36f41SAndroid Build Coastguard Worker -exec_type 248*e4a36f41SAndroid Build Coastguard Worker -postinstall_file 249*e4a36f41SAndroid Build Coastguard Worker}:file execute; 250*e4a36f41SAndroid Build Coastguard Worker 251*e4a36f41SAndroid Build Coastguard Worker# Only init is allowed to write cgroup.rc file 252*e4a36f41SAndroid Build Coastguard Workerneverallow { 253*e4a36f41SAndroid Build Coastguard Worker domain 254*e4a36f41SAndroid Build Coastguard Worker -init 255*e4a36f41SAndroid Build Coastguard Worker -vendor_init 256*e4a36f41SAndroid Build Coastguard Worker} cgroup_rc_file:file no_w_file_perms; 257*e4a36f41SAndroid Build Coastguard Worker 258*e4a36f41SAndroid Build Coastguard Worker# Only authorized processes should be writing to files in /data/dalvik-cache 259*e4a36f41SAndroid Build Coastguard Workerneverallow { 260*e4a36f41SAndroid Build Coastguard Worker domain 261*e4a36f41SAndroid Build Coastguard Worker -init # TODO: limit init to relabelfrom for files 262*e4a36f41SAndroid Build Coastguard Worker -zygote 263*e4a36f41SAndroid Build Coastguard Worker -installd 264*e4a36f41SAndroid Build Coastguard Worker -postinstall_dexopt 265*e4a36f41SAndroid Build Coastguard Worker -cppreopts 266*e4a36f41SAndroid Build Coastguard Worker -dex2oat 267*e4a36f41SAndroid Build Coastguard Worker -otapreopt_slot 268*e4a36f41SAndroid Build Coastguard Worker} dalvikcache_data_file:file no_w_file_perms; 269*e4a36f41SAndroid Build Coastguard Worker 270*e4a36f41SAndroid Build Coastguard Workerneverallow { 271*e4a36f41SAndroid Build Coastguard Worker domain 272*e4a36f41SAndroid Build Coastguard Worker -init 273*e4a36f41SAndroid Build Coastguard Worker -installd 274*e4a36f41SAndroid Build Coastguard Worker -postinstall_dexopt 275*e4a36f41SAndroid Build Coastguard Worker -cppreopts 276*e4a36f41SAndroid Build Coastguard Worker -dex2oat 277*e4a36f41SAndroid Build Coastguard Worker -zygote 278*e4a36f41SAndroid Build Coastguard Worker -otapreopt_slot 279*e4a36f41SAndroid Build Coastguard Worker} dalvikcache_data_file:dir no_w_dir_perms; 280*e4a36f41SAndroid Build Coastguard Worker 281*e4a36f41SAndroid Build Coastguard Worker# Only authorized processes should be writing to /data/misc/apexdata/com.android.art as it 282*e4a36f41SAndroid Build Coastguard Worker# contains boot class path and system server AOT artifacts following an ART APEX Mainline update. 283*e4a36f41SAndroid Build Coastguard Workerneverallow { 284*e4a36f41SAndroid Build Coastguard Worker domain 285*e4a36f41SAndroid Build Coastguard Worker # art processes 286*e4a36f41SAndroid Build Coastguard Worker -odrefresh 287*e4a36f41SAndroid Build Coastguard Worker -odsign 288*e4a36f41SAndroid Build Coastguard Worker # others 289*e4a36f41SAndroid Build Coastguard Worker -apexd 290*e4a36f41SAndroid Build Coastguard Worker -init 291*e4a36f41SAndroid Build Coastguard Worker -vold_prepare_subdirs 292*e4a36f41SAndroid Build Coastguard Worker} apex_art_data_file:file no_w_file_perms; 293*e4a36f41SAndroid Build Coastguard Worker 294*e4a36f41SAndroid Build Coastguard Workerneverallow { 295*e4a36f41SAndroid Build Coastguard Worker domain 296*e4a36f41SAndroid Build Coastguard Worker # art processes 297*e4a36f41SAndroid Build Coastguard Worker -odrefresh 298*e4a36f41SAndroid Build Coastguard Worker -odsign 299*e4a36f41SAndroid Build Coastguard Worker # others 300*e4a36f41SAndroid Build Coastguard Worker -apexd 301*e4a36f41SAndroid Build Coastguard Worker -init 302*e4a36f41SAndroid Build Coastguard Worker -vold_prepare_subdirs 303*e4a36f41SAndroid Build Coastguard Worker} apex_art_data_file:dir no_w_dir_perms; 304*e4a36f41SAndroid Build Coastguard Worker 305*e4a36f41SAndroid Build Coastguard Worker# Protect most domains from executing arbitrary content from /data. 306*e4a36f41SAndroid Build Coastguard Workerneverallow { 307*e4a36f41SAndroid Build Coastguard Worker domain 308*e4a36f41SAndroid Build Coastguard Worker -appdomain 309*e4a36f41SAndroid Build Coastguard Worker} { 310*e4a36f41SAndroid Build Coastguard Worker data_file_type 311*e4a36f41SAndroid Build Coastguard Worker -apex_art_data_file 312*e4a36f41SAndroid Build Coastguard Worker -dalvikcache_data_file 313*e4a36f41SAndroid Build Coastguard Worker -system_data_file # shared libs in apks 314*e4a36f41SAndroid Build Coastguard Worker -apk_data_file 315*e4a36f41SAndroid Build Coastguard Worker}:file no_x_file_perms; 316*e4a36f41SAndroid Build Coastguard Worker 317*e4a36f41SAndroid Build Coastguard Worker# Minimize dac_override and dac_read_search. 318*e4a36f41SAndroid Build Coastguard Worker# Instead of granting them it is usually better to add the domain to 319*e4a36f41SAndroid Build Coastguard Worker# a Unix group or change the permissions of a file. 320*e4a36f41SAndroid Build Coastguard Workerdefine(`dac_override_allowed', `{ 321*e4a36f41SAndroid Build Coastguard Worker apexd 322*e4a36f41SAndroid Build Coastguard Worker dnsmasq 323*e4a36f41SAndroid Build Coastguard Worker dumpstate 324*e4a36f41SAndroid Build Coastguard Worker init 325*e4a36f41SAndroid Build Coastguard Worker installd 326*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`llkd') 327*e4a36f41SAndroid Build Coastguard Worker lmkd 328*e4a36f41SAndroid Build Coastguard Worker migrate_legacy_obb_data 329*e4a36f41SAndroid Build Coastguard Worker netd 330*e4a36f41SAndroid Build Coastguard Worker postinstall_dexopt 331*e4a36f41SAndroid Build Coastguard Worker recovery 332*e4a36f41SAndroid Build Coastguard Worker rss_hwm_reset 333*e4a36f41SAndroid Build Coastguard Worker sdcardd 334*e4a36f41SAndroid Build Coastguard Worker tee 335*e4a36f41SAndroid Build Coastguard Worker ueventd 336*e4a36f41SAndroid Build Coastguard Worker uncrypt 337*e4a36f41SAndroid Build Coastguard Worker vendor_init 338*e4a36f41SAndroid Build Coastguard Worker vold 339*e4a36f41SAndroid Build Coastguard Worker vold_prepare_subdirs 340*e4a36f41SAndroid Build Coastguard Worker zygote 341*e4a36f41SAndroid Build Coastguard Worker}') 342*e4a36f41SAndroid Build Coastguard Workerneverallow ~dac_override_allowed self:global_capability_class_set dac_override; 343*e4a36f41SAndroid Build Coastguard Worker# Since the kernel checks dac_read_search before dac_override, domains that 344*e4a36f41SAndroid Build Coastguard Worker# have dac_override should also have dac_read_search to eliminate spurious 345*e4a36f41SAndroid Build Coastguard Worker# denials. Some domains have dac_read_search without having dac_override, so 346*e4a36f41SAndroid Build Coastguard Worker# this list should be a superset of the one above. 347*e4a36f41SAndroid Build Coastguard Workerneverallow ~{ 348*e4a36f41SAndroid Build Coastguard Worker dac_override_allowed 349*e4a36f41SAndroid Build Coastguard Worker iorap_inode2filename 350*e4a36f41SAndroid Build Coastguard Worker iorap_prefetcherd 351*e4a36f41SAndroid Build Coastguard Worker traced_perf 352*e4a36f41SAndroid Build Coastguard Worker traced_probes 353*e4a36f41SAndroid Build Coastguard Worker heapprofd 354*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set dac_read_search; 355*e4a36f41SAndroid Build Coastguard Worker 356*e4a36f41SAndroid Build Coastguard Worker# Limit what domains can mount filesystems or change their mount flags. 357*e4a36f41SAndroid Build Coastguard Worker# sdcard_type / vfat is exempt as a larger set of domains need 358*e4a36f41SAndroid Build Coastguard Worker# this capability, including device-specific domains. 359*e4a36f41SAndroid Build Coastguard Workerneverallow { 360*e4a36f41SAndroid Build Coastguard Worker domain 361*e4a36f41SAndroid Build Coastguard Worker -apexd 362*e4a36f41SAndroid Build Coastguard Worker recovery_only(`-fastbootd') 363*e4a36f41SAndroid Build Coastguard Worker -init 364*e4a36f41SAndroid Build Coastguard Worker -kernel 365*e4a36f41SAndroid Build Coastguard Worker -otapreopt_chroot 366*e4a36f41SAndroid Build Coastguard Worker -recovery 367*e4a36f41SAndroid Build Coastguard Worker -update_engine 368*e4a36f41SAndroid Build Coastguard Worker -vold 369*e4a36f41SAndroid Build Coastguard Worker -zygote 370*e4a36f41SAndroid Build Coastguard Worker} { fs_type 371*e4a36f41SAndroid Build Coastguard Worker -sdcard_type 372*e4a36f41SAndroid Build Coastguard Worker}:filesystem { mount remount relabelfrom relabelto }; 373*e4a36f41SAndroid Build Coastguard Worker 374*e4a36f41SAndroid Build Coastguard Workerenforce_debugfs_restriction(` 375*e4a36f41SAndroid Build Coastguard Worker neverallow { 376*e4a36f41SAndroid Build Coastguard Worker domain userdebug_or_eng(`-init') 377*e4a36f41SAndroid Build Coastguard Worker } { debugfs_type -debugfs_tracing_debug }:filesystem { mount remount relabelfrom relabelto }; 378*e4a36f41SAndroid Build Coastguard Worker') 379*e4a36f41SAndroid Build Coastguard Worker 380*e4a36f41SAndroid Build Coastguard Worker# Limit raw I/O to these allowlisted domains. Do not apply to debug builds. 381*e4a36f41SAndroid Build Coastguard Workerneverallow { 382*e4a36f41SAndroid Build Coastguard Worker domain 383*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-domain') 384*e4a36f41SAndroid Build Coastguard Worker -kernel 385*e4a36f41SAndroid Build Coastguard Worker -gsid 386*e4a36f41SAndroid Build Coastguard Worker -init 387*e4a36f41SAndroid Build Coastguard Worker -recovery 388*e4a36f41SAndroid Build Coastguard Worker -ueventd 389*e4a36f41SAndroid Build Coastguard Worker -healthd 390*e4a36f41SAndroid Build Coastguard Worker -uncrypt 391*e4a36f41SAndroid Build Coastguard Worker -tee 392*e4a36f41SAndroid Build Coastguard Worker -hal_bootctl_server 393*e4a36f41SAndroid Build Coastguard Worker -fastbootd 394*e4a36f41SAndroid Build Coastguard Worker} self:global_capability_class_set sys_rawio; 395*e4a36f41SAndroid Build Coastguard Worker 396*e4a36f41SAndroid Build Coastguard Worker# Limit directory operations that doesn't need to do app data isolation. 397*e4a36f41SAndroid Build Coastguard Workerneverallow { 398*e4a36f41SAndroid Build Coastguard Worker domain 399*e4a36f41SAndroid Build Coastguard Worker -init 400*e4a36f41SAndroid Build Coastguard Worker -installd 401*e4a36f41SAndroid Build Coastguard Worker -zygote 402*e4a36f41SAndroid Build Coastguard Worker} mirror_data_file:dir *; 403*e4a36f41SAndroid Build Coastguard Worker 404*e4a36f41SAndroid Build Coastguard Worker# This property is being removed. Remove remaining access. 405*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server -vendor_init } net_dns_prop:property_service set; 406*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -dumpstate -init -system_server -vendor_init } net_dns_prop:file read; 407*e4a36f41SAndroid Build Coastguard Worker 408*e4a36f41SAndroid Build Coastguard Worker# Only core domains are allowed to access package_manager properties 409*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server } pm_prop:property_service set; 410*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -coredomain } pm_prop:file no_rw_file_perms; 411*e4a36f41SAndroid Build Coastguard Worker 412*e4a36f41SAndroid Build Coastguard Worker# Do not allow reading the last boot timestamp from system properties 413*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -system_server -dumpstate } firstboot_prop:file r_file_perms; 414*e4a36f41SAndroid Build Coastguard Worker 415*e4a36f41SAndroid Build Coastguard Worker# Kprobes should only be used by adb root 416*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -vendor_init } debugfs_kprobes:file *; 417*e4a36f41SAndroid Build Coastguard Worker 418*e4a36f41SAndroid Build Coastguard Worker# On TREBLE devices, most coredomains should not access vendor_files. 419*e4a36f41SAndroid Build Coastguard Worker# TODO(b/71553434): Remove exceptions here. 420*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(` 421*e4a36f41SAndroid Build Coastguard Worker neverallow { 422*e4a36f41SAndroid Build Coastguard Worker coredomain 423*e4a36f41SAndroid Build Coastguard Worker -appdomain 424*e4a36f41SAndroid Build Coastguard Worker -bootanim 425*e4a36f41SAndroid Build Coastguard Worker -crash_dump 426*e4a36f41SAndroid Build Coastguard Worker -heapprofd 427*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-profcollectd') 428*e4a36f41SAndroid Build Coastguard Worker -init 429*e4a36f41SAndroid Build Coastguard Worker -iorap_inode2filename 430*e4a36f41SAndroid Build Coastguard Worker -iorap_prefetcherd 431*e4a36f41SAndroid Build Coastguard Worker -kernel 432*e4a36f41SAndroid Build Coastguard Worker -traced_perf 433*e4a36f41SAndroid Build Coastguard Worker -ueventd 434*e4a36f41SAndroid Build Coastguard Worker } vendor_file:file { no_w_file_perms no_x_file_perms open }; 435*e4a36f41SAndroid Build Coastguard Worker') 436*e4a36f41SAndroid Build Coastguard Worker 437*e4a36f41SAndroid Build Coastguard Worker# Vendor domains are not permitted to initiate communications to core domain sockets 438*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(` 439*e4a36f41SAndroid Build Coastguard Worker neverallow_establish_socket_comms({ 440*e4a36f41SAndroid Build Coastguard Worker domain 441*e4a36f41SAndroid Build Coastguard Worker -coredomain 442*e4a36f41SAndroid Build Coastguard Worker -appdomain 443*e4a36f41SAndroid Build Coastguard Worker -socket_between_core_and_vendor_violators 444*e4a36f41SAndroid Build Coastguard Worker }, { 445*e4a36f41SAndroid Build Coastguard Worker coredomain 446*e4a36f41SAndroid Build Coastguard Worker -logd # Logging by writing to logd Unix domain socket is public API 447*e4a36f41SAndroid Build Coastguard Worker -netd # netdomain needs this 448*e4a36f41SAndroid Build Coastguard Worker -mdnsd # netdomain needs this 449*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-su') # communications with su are permitted only on userdebug or eng builds 450*e4a36f41SAndroid Build Coastguard Worker -init 451*e4a36f41SAndroid Build Coastguard Worker -tombstoned # linker to tombstoned 452*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-heapprofd') 453*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-traced_perf') 454*e4a36f41SAndroid Build Coastguard Worker }); 455*e4a36f41SAndroid Build Coastguard Worker') 456*e4a36f41SAndroid Build Coastguard Worker 457*e4a36f41SAndroid Build Coastguard Workerfull_treble_only(` 458*e4a36f41SAndroid Build Coastguard Worker # Do not allow system components access to /vendor files except for the 459*e4a36f41SAndroid Build Coastguard Worker # ones allowed here. 460*e4a36f41SAndroid Build Coastguard Worker neverallow { 461*e4a36f41SAndroid Build Coastguard Worker coredomain 462*e4a36f41SAndroid Build Coastguard Worker # TODO(b/37168747): clean up fwk access to /vendor 463*e4a36f41SAndroid Build Coastguard Worker -crash_dump 464*e4a36f41SAndroid Build Coastguard Worker -init # starts vendor executables 465*e4a36f41SAndroid Build Coastguard Worker -iorap_inode2filename 466*e4a36f41SAndroid Build Coastguard Worker -iorap_prefetcherd 467*e4a36f41SAndroid Build Coastguard Worker -kernel # loads /vendor/firmware 468*e4a36f41SAndroid Build Coastguard Worker -heapprofd 469*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-profcollectd') 470*e4a36f41SAndroid Build Coastguard Worker -shell 471*e4a36f41SAndroid Build Coastguard Worker -system_executes_vendor_violators 472*e4a36f41SAndroid Build Coastguard Worker -traced_perf # library/binary access for symbolization 473*e4a36f41SAndroid Build Coastguard Worker -ueventd # reads /vendor/ueventd.rc 474*e4a36f41SAndroid Build Coastguard Worker -vold # loads incremental fs driver 475*e4a36f41SAndroid Build Coastguard Worker } { 476*e4a36f41SAndroid Build Coastguard Worker vendor_file_type 477*e4a36f41SAndroid Build Coastguard Worker -same_process_hal_file 478*e4a36f41SAndroid Build Coastguard Worker -vendor_app_file 479*e4a36f41SAndroid Build Coastguard Worker -vendor_apex_file 480*e4a36f41SAndroid Build Coastguard Worker -vendor_configs_file 481*e4a36f41SAndroid Build Coastguard Worker -vendor_service_contexts_file 482*e4a36f41SAndroid Build Coastguard Worker -vendor_framework_file 483*e4a36f41SAndroid Build Coastguard Worker -vendor_idc_file 484*e4a36f41SAndroid Build Coastguard Worker -vendor_keychars_file 485*e4a36f41SAndroid Build Coastguard Worker -vendor_keylayout_file 486*e4a36f41SAndroid Build Coastguard Worker -vendor_overlay_file 487*e4a36f41SAndroid Build Coastguard Worker -vendor_public_framework_file 488*e4a36f41SAndroid Build Coastguard Worker -vendor_public_lib_file 489*e4a36f41SAndroid Build Coastguard Worker -vendor_task_profiles_file 490*e4a36f41SAndroid Build Coastguard Worker -vndk_sp_file 491*e4a36f41SAndroid Build Coastguard Worker }:file *; 492*e4a36f41SAndroid Build Coastguard Worker') 493*e4a36f41SAndroid Build Coastguard Worker 494*e4a36f41SAndroid Build Coastguard Worker# mlsvendorcompat is only for compatibility support for older vendor 495*e4a36f41SAndroid Build Coastguard Worker# images, and should not be granted to any domain in current policy. 496*e4a36f41SAndroid Build Coastguard Worker# (Every domain is allowed self:fork, so this will trigger if the 497*e4a36f41SAndroid Build Coastguard Worker# intsersection of domain & mlsvendorcompat is not empty.) 498*e4a36f41SAndroid Build Coastguard Workerneverallow domain mlsvendorcompat:process fork; 499*e4a36f41SAndroid Build Coastguard Worker 500*e4a36f41SAndroid Build Coastguard Worker# Only init and otapreopt_chroot should be mounting filesystems on locations 501*e4a36f41SAndroid Build Coastguard Worker# labeled system or vendor (/product and /vendor respectively). 502*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init -otapreopt_chroot } { system_file_type vendor_file_type }:dir_file_class_set mounton; 503*e4a36f41SAndroid Build Coastguard Worker 504*e4a36f41SAndroid Build Coastguard Worker# Only allow init and vendor_init to read/write mm_events properties 505*e4a36f41SAndroid Build Coastguard Worker# NOTE: dumpstate is allowed to read any system property 506*e4a36f41SAndroid Build Coastguard Workerneverallow { 507*e4a36f41SAndroid Build Coastguard Worker domain 508*e4a36f41SAndroid Build Coastguard Worker -init 509*e4a36f41SAndroid Build Coastguard Worker -vendor_init 510*e4a36f41SAndroid Build Coastguard Worker -dumpstate 511*e4a36f41SAndroid Build Coastguard Worker} mm_events_config_prop:file no_rw_file_perms; 512*e4a36f41SAndroid Build Coastguard Worker 513*e4a36f41SAndroid Build Coastguard Worker# Allow the tracing daemon and callstack sampler to use kallsyms to symbolize 514*e4a36f41SAndroid Build Coastguard Worker# kernel traces. Addresses are not disclosed, they are repalced with symbol 515*e4a36f41SAndroid Build Coastguard Worker# names (if available). Traces don't disclose KASLR. 516*e4a36f41SAndroid Build Coastguard Workerneverallow { 517*e4a36f41SAndroid Build Coastguard Worker domain 518*e4a36f41SAndroid Build Coastguard Worker -init 519*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-profcollectd') 520*e4a36f41SAndroid Build Coastguard Worker -vendor_init 521*e4a36f41SAndroid Build Coastguard Worker -traced_probes 522*e4a36f41SAndroid Build Coastguard Worker -traced_perf 523*e4a36f41SAndroid Build Coastguard Worker} proc_kallsyms:file { open read }; 524*e4a36f41SAndroid Build Coastguard Worker 525*e4a36f41SAndroid Build Coastguard Worker# debugfs_kcov type is not included in this neverallow statement since the KCOV 526*e4a36f41SAndroid Build Coastguard Worker# tool uses it for kernel fuzzing. 527*e4a36f41SAndroid Build Coastguard Worker# vendor_modprobe is also exempted since the kernel modules it loads may create 528*e4a36f41SAndroid Build Coastguard Worker# debugfs files in its context. 529*e4a36f41SAndroid Build Coastguard Workerenforce_debugfs_restriction(` 530*e4a36f41SAndroid Build Coastguard Worker neverallow { 531*e4a36f41SAndroid Build Coastguard Worker domain 532*e4a36f41SAndroid Build Coastguard Worker -vendor_modprobe 533*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(` 534*e4a36f41SAndroid Build Coastguard Worker -init 535*e4a36f41SAndroid Build Coastguard Worker -hal_dumpstate 536*e4a36f41SAndroid Build Coastguard Worker ') 537*e4a36f41SAndroid Build Coastguard Worker } { debugfs_type 538*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-debugfs_kcov') 539*e4a36f41SAndroid Build Coastguard Worker -tracefs_type 540*e4a36f41SAndroid Build Coastguard Worker }:file no_rw_file_perms; 541*e4a36f41SAndroid Build Coastguard Worker') 542