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