1# zygote 2typeattribute zygote coredomain; 3typeattribute zygote mlstrustedsubject; 4 5init_daemon_domain(zygote) 6tmpfs_domain(zygote) 7 8read_runtime_log_tags(zygote) 9 10# Override DAC on files and switch uid/gid. 11allow zygote self:global_capability_class_set { dac_override dac_read_search setgid setuid fowner chown }; 12 13# Drop capabilities from bounding set. 14allow zygote self:global_capability_class_set setpcap; 15 16# Switch SELinux context to app domains. 17allow zygote self:process setcurrent; 18allow zygote system_server_startup:process dyntransition; 19allow zygote appdomain:process dyntransition; 20allow zygote webview_zygote:process dyntransition; 21allow zygote app_zygote:process dyntransition; 22 23# Allow zygote to read app /proc/pid dirs (b/10455872). 24allow zygote appdomain:dir { getattr search }; 25allow zygote appdomain:file { r_file_perms }; 26 27userfaultfd_use(zygote) 28 29# Move children into the peer process group. 30allow zygote system_server:process { getpgid setpgid }; 31allow zygote appdomain:process { getpgid setpgid }; 32allow zygote webview_zygote:process { getpgid setpgid }; 33allow zygote app_zygote:process { getpgid setpgid }; 34 35# Read system data. 36allow zygote system_data_file:dir r_dir_perms; 37allow zygote system_data_file:file r_file_perms; 38 39# Get attributes of /mnt/expand, needed by cacheNonBootClasspathClassLoaders. 40allow zygote mnt_expand_file:dir getattr; 41 42# Write to /data/dalvik-cache. 43allow zygote dalvikcache_data_file:dir create_dir_perms; 44allow zygote dalvikcache_data_file:file create_file_perms; 45 46# Create symlinks in /data/dalvik-cache. 47allow zygote dalvikcache_data_file:lnk_file create_file_perms; 48 49# Write to /data/resource-cache. 50allow zygote resourcecache_data_file:dir rw_dir_perms; 51allow zygote resourcecache_data_file:file create_file_perms; 52 53# For updateability, the zygote may fetch the current boot 54# classpath from the dalvik cache. Integrity of the files 55# is ensured by fsverity protection (checked in art_apex_boot_integrity). 56allow zygote dalvikcache_data_file:file execute; 57 58# Allow zygote to find files in APEX data directories. 59allow zygote apex_module_data_file:dir search; 60 61# Allow zygote to find and map files created by on device signing. 62allow zygote apex_art_data_file:dir { getattr search }; 63allow zygote apex_art_data_file:file { r_file_perms execute }; 64 65# Mount tmpfs over various directories containing per-app directories, to hide 66# them for app data isolation. Also traverse these directories (via 67# /data_mirror) to find the allowlisted per-app directories to bind-mount in. 68allow zygote { 69 # /data/user{,_de}, /mnt/expand/$volume/user{,_de} 70 system_userdir_file 71 # /data/data 72 system_data_file 73 # /data/misc/profiles/cur 74 user_profile_root_file 75 # /data/misc/profiles/ref 76 user_profile_data_file 77 # /storage/emulated/$userId/Android/{data,obb} 78 media_rw_data_file 79}:dir { mounton search }; 80 81# Traverse /data_mirror to get to the above directories while their normal paths 82# are hidden, in order to bind-mount allowlisted per-app directories. 83allow zygote mirror_data_file:dir search; 84 85# List /mnt/expand to find all /mnt/expand/$volume/user{,_de} directories that 86# need to be hidden by app data isolation, and traverse /mnt/expand to get to 87# any allowlisted per-app directories within these directories. 88allow zygote mnt_expand_file:dir { open read search }; 89 90# Get the inode number of app CE data directories to find them by inode number 91# when CE storage is locked. Needed for app data isolation. 92allow zygote app_data_file_type:dir getattr; 93 94# Create dirs in the app data isolation tmpfs mounts and bind mount on them. 95allow zygote tmpfs:dir { create_dir_perms mounton }; 96 97# Create the '/data/user/0 => /data/data' symlink in the /data/user tmpfs mount 98# when setting up app data isolation. 99allow zygote tmpfs:lnk_file create; 100 101# Relabel dirs and symlinks in the app and sdk sandbox data isolation tmpfs mounts to their 102# standard labels. Note: it seems that not all dirs are actually relabeled yet, 103# but it works anyway since all domains can search tmpfs:dir. 104allow zygote tmpfs:{ dir lnk_file } relabelfrom; 105allow zygote system_userdir_file:dir relabelto; 106allow zygote system_data_file:{ dir lnk_file } relabelto; 107allow zygote sdk_sandbox_system_data_file:dir { getattr relabelto search }; 108 109# Read if sdcardfs is supported 110allow zygote proc_filesystems:file r_file_perms; 111 112# Allow zygote to create JIT memory. 113allow zygote self:process execmem; 114allow zygote zygote_tmpfs:file execute; 115allow zygote ashmem_libcutils_device:chr_file execute; 116 117# Execute idmap and dex2oat within zygote's own domain. 118# TODO: Should either of these be transitioned to the same domain 119# used by installd or stay in-domain for zygote? 120allow zygote idmap_exec:file rx_file_perms; 121allow zygote dex2oat_exec:file rx_file_perms; 122 123# Allow apps access to /vendor/overlay 124r_dir_file(zygote, vendor_overlay_file) 125 126# Control cgroups. 127allow zygote cgroup:dir create_dir_perms; 128allow zygote cgroup:{ file lnk_file } { r_file_perms setattr }; 129allow zygote cgroup_v2:dir create_dir_perms; 130allow zygote cgroup_v2:{ file lnk_file } { r_file_perms setattr }; 131allow zygote self:global_capability_class_set sys_admin; 132 133# Allow zygote to stat the files that it opens. The zygote must 134# be able to inspect them so that it can reopen them on fork 135# if necessary: b/30963384. 136allow zygote pmsg_device:chr_file getattr; 137allow zygote debugfs_trace_marker:file getattr; 138 139# Get seapp_contexts 140allow zygote seapp_contexts_file:file r_file_perms; 141# Check validity of SELinux context before use. 142selinux_check_context(zygote) 143# Check SELinux permissions. 144selinux_check_access(zygote) 145 146# Native bridge functionality requires that zygote replaces 147# /proc/cpuinfo with /system/lib/<ISA>/cpuinfo using a bind mount 148allow zygote proc_cpuinfo:file mounton; 149 150# Allow remounting rootfs as MS_SLAVE. 151allow zygote rootfs:dir mounton; 152allow zygote tmpfs:filesystem { mount unmount }; 153allow zygote fuse:filesystem { unmount }; 154allow zygote sdcardfs:filesystem { unmount }; 155allow zygote labeledfs:filesystem { unmount }; 156 157# Allow creating user-specific storage source if started before vold. 158allow zygote mnt_user_file:dir { create_dir_perms mounton }; 159allow zygote mnt_user_file:lnk_file create_file_perms; 160allow zygote mnt_user_file:file create_file_perms; 161 162# Allow mounting user-specific storage source if started before vold. 163allow zygote mnt_pass_through_file:dir { create_dir_perms mounton }; 164 165# Allowed to mount user-specific storage into place 166allow zygote storage_file:dir { search mounton }; 167 168# Allow mounting and creating files, dirs on sdcardfs. 169allow zygote { sdcard_type fuse }:dir { create_dir_perms mounton }; 170allow zygote { sdcard_type fuse }:file { create_file_perms }; 171 172# Handle --invoke-with command when launching Zygote with a wrapper command. 173allow zygote zygote_exec:file rx_file_perms; 174 175# Allow zygote to write to statsd. 176unix_socket_send(zygote, statsdw, statsd) 177 178# Root fs. 179r_dir_file(zygote, rootfs) 180 181# System file accesses. 182r_dir_file(zygote, system_file) 183 184# /oem accesses. 185allow zygote oemfs:dir search; 186 187userdebug_or_eng(` 188 # Allow zygote to create and write method traces in /data/misc/trace. 189 allow zygote method_trace_data_file:dir w_dir_perms; 190 allow zygote method_trace_data_file:file { create w_file_perms }; 191') 192 193allow zygote ion_device:chr_file r_file_perms; 194allow zygote tmpfs:dir r_dir_perms; 195 196allow zygote same_process_hal_file:file { execute read open getattr map }; 197 198# Allow zygote to read build properties for attestation feature 199get_prop(zygote, build_attestation_prop) 200 201# Allow the zygote to access storage properties to check if sdcardfs is enabled. 202get_prop(zygote, storage_config_prop); 203 204# Let the zygote access overlays so it can initialize the AssetManager. 205get_prop(zygote, overlay_prop) 206get_prop(zygote, exported_overlay_prop) 207 208# Allow the zygote to access the runtime feature flag properties. 209get_prop(zygote, device_config_runtime_native_prop) 210get_prop(zygote, device_config_runtime_native_boot_prop) 211 212# Allow the zygote to access window manager native boot feature flags 213# to initialize WindowManager static properties. 214get_prop(zygote, device_config_window_manager_native_boot_prop) 215 216# ingore spurious denials 217# fsetid can be checked as a consequence of chmod when using cgroup v2 uid/pid hierarchy. This is 218# done to determine if the file should inherit setgid. In this case, setgid on the file is 219# undesirable, so suppress the denial. 220dontaudit zygote self:global_capability_class_set { sys_resource fsetid }; 221 222# Ignore spurious denials calling access() on fuse. 223# Also ignore read and open as sdcardfs may read and open dir when app tries to access a dir that 224# doesn't exist. 225# TODO(b/151316657): avoid the denials 226dontaudit zygote media_rw_data_file:dir { read open setattr }; 227 228# Allow zygote to use ashmem fds from system_server. 229allow zygote system_server:fd use; 230 231# Send unsolicited message to system_server 232unix_socket_send(zygote, system_unsolzygote, system_server) 233 234# Allow zygote to access media_variant_prop for static initialization 235get_prop(zygote, media_variant_prop) 236 237# Allow zygote to access odsign verification status 238get_prop(zygote, odsign_prop) 239 240# Allow zygote to read ro.control_privapp_permissions and ro.cp_system_other_odex 241get_prop(zygote, packagemanager_config_prop) 242 243# Allow zygote to read qemu.sf.lcd_density 244get_prop(zygote, qemu_sf_lcd_density_prop) 245 246# Allow zygote to read persist.wm.debug.* to toggle experimental window manager features in 247# preloaded classes 248get_prop(zygote, persist_wm_debug_prop) 249 250# Allow zygote to read persist_sysui_builder_extras_prop to toggle experimental features in 251# core preloaded classes 252get_prop(zygote, persist_sysui_builder_extras_prop) 253 254# Allow zygote to read /apex/apex-info-list.xml 255allow zygote apex_info_file:file r_file_perms; 256 257# Allow zygote to canonicalize vendor APEX paths. This is used when zygote is checking the 258# preinstalled path of APEXes that contain runtime resource overlays for the 'android' package. 259allow zygote vendor_apex_file:dir { getattr search }; 260allow zygote vendor_apex_file:file { getattr }; 261 262# Allow zygote to query for compression/features. 263r_dir_file(zygote, sysfs_fs_f2fs) 264 265### 266### neverallow rules 267### 268 269# Ensure that all types assigned to app processes are included 270# in the appdomain attribute, so that all allow and neverallow rules 271# written on appdomain are applied to all app processes. 272# This is achieved by ensuring that it is impossible for zygote to 273# setcon (dyntransition) to any types other than those associated 274# with appdomain plus system_server_startup, webview_zygote and 275# app_zygote. 276neverallow zygote ~{ 277 appdomain 278 system_server_startup 279 webview_zygote 280 app_zygote 281}:process dyntransition; 282 283# Zygote should never execute anything from /data except for 284# /data/dalvik-cache files or files generated during on-device 285# signing under /data/misc/apexdata/com.android.art/. 286neverallow zygote { 287 data_file_type 288 -apex_art_data_file # map PROT_EXEC 289 -dalvikcache_data_file # map PROT_EXEC 290}:file no_x_file_perms; 291 292# Do not allow access to Bluetooth-related system properties and files 293neverallow zygote { 294 bluetooth_a2dp_offload_prop 295 bluetooth_audio_hal_prop 296 bluetooth_prop 297 exported_bluetooth_prop 298}:file create_file_perms; 299 300# Zygote should not be able to access app private data. 301neverallow zygote app_data_file_type:dir ~getattr; 302