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 # /dev/__properties__ 80 properties_device 81}:dir { mounton search }; 82 83# Traverse /data_mirror to get to the above directories while their normal paths 84# are hidden, in order to bind-mount allowlisted per-app directories. 85allow zygote mirror_data_file:dir search; 86 87# List /mnt/expand to find all /mnt/expand/$volume/user{,_de} directories that 88# need to be hidden by app data isolation, and traverse /mnt/expand to get to 89# any allowlisted per-app directories within these directories. 90allow zygote mnt_expand_file:dir { open read search }; 91 92# Get the inode number of app CE data directories to find them by inode number 93# when CE storage is locked. Needed for app data isolation. 94allow zygote app_data_file_type:dir getattr; 95 96# Create dirs in the app data isolation tmpfs mounts and bind mount on them. 97allow zygote tmpfs:dir { create_dir_perms mounton }; 98 99# Create the '/data/user/0 => /data/data' symlink in the /data/user tmpfs mount 100# when setting up app data isolation. 101allow zygote tmpfs:lnk_file create; 102 103# Relabel dirs and symlinks in the app and sdk sandbox data isolation tmpfs mounts to their 104# standard labels. Note: it seems that not all dirs are actually relabeled yet, 105# but it works anyway since all domains can search tmpfs:dir. 106allow zygote tmpfs:{ dir lnk_file } relabelfrom; 107allow zygote system_userdir_file:dir relabelto; 108allow zygote system_data_file:{ dir lnk_file } relabelto; 109allow zygote sdk_sandbox_system_data_file:dir { getattr relabelto search }; 110 111# Read if sdcardfs is supported 112allow zygote proc_filesystems:file r_file_perms; 113 114# Allow zygote to create JIT memory. 115allow zygote self:process execmem; 116allow zygote zygote_tmpfs:file execute; 117allow zygote ashmem_libcutils_device:chr_file execute; 118 119# Execute idmap and dex2oat within zygote's own domain. 120# TODO: Should either of these be transitioned to the same domain 121# used by installd or stay in-domain for zygote? 122allow zygote idmap_exec:file rx_file_perms; 123allow zygote dex2oat_exec:file rx_file_perms; 124 125# Allow apps access to /vendor/overlay 126r_dir_file(zygote, vendor_overlay_file) 127 128# Control cgroups. 129allow zygote cgroup:dir create_dir_perms; 130allow zygote cgroup:{ file lnk_file } { r_file_perms setattr }; 131allow zygote cgroup_v2:dir create_dir_perms; 132allow zygote cgroup_v2:{ file lnk_file } { r_file_perms setattr }; 133allow zygote self:global_capability_class_set sys_admin; 134 135# Allow zygote to stat the files that it opens. The zygote must 136# be able to inspect them so that it can reopen them on fork 137# if necessary: b/30963384. 138allow zygote pmsg_device:chr_file getattr; 139allow zygote debugfs_trace_marker:file getattr; 140 141# Get seapp_contexts 142allow zygote seapp_contexts_file:file r_file_perms; 143# Check validity of SELinux context before use. 144selinux_check_context(zygote) 145# Check SELinux permissions. 146selinux_check_access(zygote) 147 148# Native bridge functionality requires that zygote replaces 149# /proc/cpuinfo with /system/lib/<ISA>/cpuinfo using a bind mount 150allow zygote proc_cpuinfo:file mounton; 151 152# Allow remounting rootfs as MS_SLAVE. 153allow zygote rootfs:dir mounton; 154allow zygote tmpfs:filesystem { mount unmount }; 155allow zygote fuse:filesystem { unmount }; 156allow zygote sdcardfs:filesystem { unmount }; 157allow zygote labeledfs:filesystem { unmount }; 158 159# Allow creating user-specific storage source if started before vold. 160allow zygote mnt_user_file:dir { create_dir_perms mounton }; 161allow zygote mnt_user_file:lnk_file create_file_perms; 162allow zygote mnt_user_file:file create_file_perms; 163 164# Allow mounting user-specific storage source if started before vold. 165allow zygote mnt_pass_through_file:dir { create_dir_perms mounton }; 166 167# Allowed to mount user-specific storage into place 168allow zygote storage_file:dir { search mounton }; 169 170# Allow mounting and creating files, dirs on sdcardfs. 171allow zygote { sdcard_type fuse }:dir { create_dir_perms mounton }; 172allow zygote { sdcard_type fuse }:file { create_file_perms }; 173 174# Handle --invoke-with command when launching Zygote with a wrapper command. 175allow zygote zygote_exec:file rx_file_perms; 176 177# Allow zygote to write to statsd. 178unix_socket_send(zygote, statsdw, statsd) 179 180# Root fs. 181r_dir_file(zygote, rootfs) 182 183# System file accesses. 184r_dir_file(zygote, system_file) 185 186# /oem accesses. 187allow zygote oemfs:dir search; 188 189userdebug_or_eng(` 190 # Allow zygote to create and write method traces in /data/misc/trace. 191 allow zygote method_trace_data_file:dir w_dir_perms; 192 allow zygote method_trace_data_file:file { create w_file_perms }; 193') 194 195allow zygote ion_device:chr_file r_file_perms; 196allow zygote tmpfs:dir r_dir_perms; 197 198allow zygote same_process_hal_file:file { execute read open getattr map }; 199 200# Allow zygote to read build properties for attestation feature 201get_prop(zygote, build_attestation_prop) 202 203# Allow the zygote to access storage properties to check if sdcardfs is enabled. 204get_prop(zygote, storage_config_prop); 205 206# Let the zygote access overlays so it can initialize the AssetManager. 207get_prop(zygote, overlay_prop) 208get_prop(zygote, exported_overlay_prop) 209 210# Allow the zygote to access the runtime feature flag properties. 211get_prop(zygote, device_config_runtime_native_prop) 212get_prop(zygote, device_config_runtime_native_boot_prop) 213 214# Allow the zygote to access window manager native boot feature flags 215# to initialize WindowManager static properties. 216get_prop(zygote, device_config_window_manager_native_boot_prop) 217 218# ingore spurious denials 219# fsetid can be checked as a consequence of chmod when using cgroup v2 uid/pid hierarchy. This is 220# done to determine if the file should inherit setgid. In this case, setgid on the file is 221# undesirable, so suppress the denial. 222dontaudit zygote self:global_capability_class_set { sys_resource fsetid }; 223 224# Ignore spurious denials calling access() on fuse. 225# Also ignore read and open as sdcardfs may read and open dir when app tries to access a dir that 226# doesn't exist. 227# TODO(b/151316657): avoid the denials 228dontaudit zygote media_rw_data_file:dir { read open setattr }; 229 230# Allow zygote to use ashmem fds from system_server. 231allow zygote system_server:fd use; 232 233# Send unsolicited message to system_server 234unix_socket_send(zygote, system_unsolzygote, system_server) 235 236# Allow zygote to access media_variant_prop for static initialization 237get_prop(zygote, media_variant_prop) 238 239# Allow zygote to access odsign verification status 240get_prop(zygote, odsign_prop) 241 242# Allow zygote to read ro.control_privapp_permissions and ro.cp_system_other_odex 243get_prop(zygote, packagemanager_config_prop) 244 245# Allow zygote to read qemu.sf.lcd_density 246get_prop(zygote, qemu_sf_lcd_density_prop) 247 248# Allow zygote to read persist.wm.debug.* to toggle experimental window manager features in 249# preloaded classes 250get_prop(zygote, persist_wm_debug_prop) 251 252# Allow zygote to read persist_sysui_builder_extras_prop 253# and persist_sysui_ranking_update_prop 254# to toggle experimental features in core preloaded classes 255get_prop(zygote, persist_sysui_builder_extras_prop) 256get_prop(zygote, persist_sysui_ranking_update_prop) 257 258# Allow zygote to read /apex/apex-info-list.xml 259allow zygote apex_info_file:file r_file_perms; 260 261# Allow zygote to canonicalize vendor APEX paths. This is used when zygote is checking the 262# preinstalled path of APEXes that contain runtime resource overlays for the 'android' package. 263allow zygote vendor_apex_file:dir { getattr search }; 264allow zygote vendor_apex_file:file { getattr }; 265allow zygote vendor_apex_metadata_file:dir { search }; 266 267# Allow zygote to query for compression/features. 268r_dir_file(zygote, sysfs_fs_f2fs) 269 270# Allow zygote to read fonts_customization.xml for preloading font files that matches device locale. 271allow zygote system_font_fallback_file:file r_file_perms; 272 273### 274### neverallow rules 275### 276 277# Ensure that all types assigned to app processes are included 278# in the appdomain attribute, so that all allow and neverallow rules 279# written on appdomain are applied to all app processes. 280# This is achieved by ensuring that it is impossible for zygote to 281# setcon (dyntransition) to any types other than those associated 282# with appdomain plus system_server_startup, webview_zygote and 283# app_zygote. 284neverallow zygote ~{ 285 appdomain 286 system_server_startup 287 webview_zygote 288 app_zygote 289}:process dyntransition; 290 291# Zygote should never execute anything from /data except for 292# /data/dalvik-cache files or files generated during on-device 293# signing under /data/misc/apexdata/com.android.art/. 294neverallow zygote { 295 data_file_type 296 -apex_art_data_file # map PROT_EXEC 297 -dalvikcache_data_file # map PROT_EXEC 298}:file no_x_file_perms; 299 300# Do not allow access to Bluetooth-related system properties and files 301neverallow zygote { 302 bluetooth_a2dp_offload_prop 303 bluetooth_audio_hal_prop 304 bluetooth_prop 305 exported_bluetooth_prop 306}:file create_file_perms; 307 308# Zygote should not be able to access app private data. 309neverallow zygote app_data_file_type:dir ~getattr; 310