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# Write to /data/dalvik-cache. 40allow zygote dalvikcache_data_file:dir create_dir_perms; 41allow zygote dalvikcache_data_file:file create_file_perms; 42 43# Create symlinks in /data/dalvik-cache. 44allow zygote dalvikcache_data_file:lnk_file create_file_perms; 45 46# Write to /data/resource-cache. 47allow zygote resourcecache_data_file:dir rw_dir_perms; 48allow zygote resourcecache_data_file:file create_file_perms; 49 50# For updateability, the zygote may fetch the current boot 51# classpath from the dalvik cache. Integrity of the files 52# is ensured by fsverity protection (checked in art_apex_boot_integrity). 53allow zygote dalvikcache_data_file:file execute; 54 55# Allow zygote to find files in APEX data directories. 56allow zygote apex_module_data_file:dir search; 57 58# Allow zygote to find and map files created by on device signing. 59allow zygote apex_art_data_file:dir { getattr search }; 60allow zygote apex_art_data_file:file { r_file_perms execute }; 61 62# Bind mount on /data/data and mounted volumes 63allow zygote { system_data_file mnt_expand_file }:dir mounton; 64 65# Relabel /data/user /data/user_de /data/data and /data/misc_{ce,de}/<user-id>/sdksandbox 66allow zygote tmpfs:{ dir lnk_file } relabelfrom; 67allow zygote system_data_file:{ dir lnk_file } relabelto; 68allow zygote sdk_sandbox_system_data_file:dir { search relabelto }; 69 70# Zygote opens /mnt/expand to mount CE DE storage on each vol 71allow zygote mnt_expand_file:dir { open read search relabelto }; 72 73# Bind mount subdirectories on /data/misc/profiles/cur and /data/misc/profiles/ref 74allow zygote { user_profile_root_file user_profile_data_file }:dir { mounton search }; 75 76# Create and bind dirs on /data/data 77allow zygote tmpfs:dir { create_dir_perms mounton }; 78 79# Goes into media directory and bind mount obb directory 80allow zygote media_rw_data_file:dir { getattr search }; 81 82# Bind mount on top of existing mounted obb and data directory 83allow zygote media_rw_data_file:dir { mounton }; 84 85# Read if sdcardfs is supported 86allow zygote proc_filesystems:file r_file_perms; 87 88# Create symlink for /data/user/0 89allow zygote tmpfs:lnk_file create; 90 91allow zygote mirror_data_file:dir r_dir_perms; 92 93# Get inode of directories for app data isolation 94allow zygote { 95 app_data_file_type 96 system_data_file 97 mnt_expand_file 98 sdk_sandbox_system_data_file 99}:dir getattr; 100 101# Allow zygote to create JIT memory. 102allow zygote self:process execmem; 103allow zygote zygote_tmpfs:file execute; 104allow zygote ashmem_libcutils_device:chr_file execute; 105 106# Execute idmap and dex2oat within zygote's own domain. 107# TODO: Should either of these be transitioned to the same domain 108# used by installd or stay in-domain for zygote? 109allow zygote idmap_exec:file rx_file_perms; 110allow zygote dex2oat_exec:file rx_file_perms; 111 112# Allow apps access to /vendor/overlay 113r_dir_file(zygote, vendor_overlay_file) 114 115# Control cgroups. 116allow zygote cgroup:dir create_dir_perms; 117allow zygote cgroup:{ file lnk_file } { r_file_perms setattr }; 118allow zygote cgroup_v2:dir create_dir_perms; 119allow zygote cgroup_v2:{ file lnk_file } { r_file_perms setattr }; 120allow zygote self:global_capability_class_set sys_admin; 121 122# Allow zygote to stat the files that it opens. The zygote must 123# be able to inspect them so that it can reopen them on fork 124# if necessary: b/30963384. 125allow zygote pmsg_device:chr_file getattr; 126allow zygote debugfs_trace_marker:file getattr; 127 128# Get seapp_contexts 129allow zygote seapp_contexts_file:file r_file_perms; 130# Check validity of SELinux context before use. 131selinux_check_context(zygote) 132# Check SELinux permissions. 133selinux_check_access(zygote) 134 135# Native bridge functionality requires that zygote replaces 136# /proc/cpuinfo with /system/lib/<ISA>/cpuinfo using a bind mount 137allow zygote proc_cpuinfo:file mounton; 138 139# Allow remounting rootfs as MS_SLAVE. 140allow zygote rootfs:dir mounton; 141allow zygote tmpfs:filesystem { mount unmount }; 142allow zygote fuse:filesystem { unmount }; 143allow zygote sdcardfs:filesystem { unmount }; 144allow zygote labeledfs:filesystem { unmount }; 145 146# Allow creating user-specific storage source if started before vold. 147allow zygote mnt_user_file:dir { create_dir_perms mounton }; 148allow zygote mnt_user_file:lnk_file create_file_perms; 149allow zygote mnt_user_file:file create_file_perms; 150 151# Allow mounting user-specific storage source if started before vold. 152allow zygote mnt_pass_through_file:dir { create_dir_perms mounton }; 153 154# Allowed to mount user-specific storage into place 155allow zygote storage_file:dir { search mounton }; 156 157# Allow mounting and creating files, dirs on sdcardfs. 158allow zygote { sdcard_type fuse }:dir { create_dir_perms mounton }; 159allow zygote { sdcard_type fuse }:file { create_file_perms }; 160 161# Handle --invoke-with command when launching Zygote with a wrapper command. 162allow zygote zygote_exec:file rx_file_perms; 163 164# Allow zygote to write to statsd. 165unix_socket_send(zygote, statsdw, statsd) 166 167# Root fs. 168r_dir_file(zygote, rootfs) 169 170# System file accesses. 171r_dir_file(zygote, system_file) 172 173# /oem accesses. 174allow zygote oemfs:dir search; 175 176userdebug_or_eng(` 177 # Allow zygote to create and write method traces in /data/misc/trace. 178 allow zygote method_trace_data_file:dir w_dir_perms; 179 allow zygote method_trace_data_file:file { create w_file_perms }; 180') 181 182allow zygote ion_device:chr_file r_file_perms; 183allow zygote tmpfs:dir r_dir_perms; 184 185allow zygote same_process_hal_file:file { execute read open getattr map }; 186 187# Allow the zygote to access storage properties to check if sdcardfs is enabled. 188get_prop(zygote, storage_config_prop); 189 190# Let the zygote access overlays so it can initialize the AssetManager. 191get_prop(zygote, overlay_prop) 192get_prop(zygote, exported_overlay_prop) 193 194# Allow the zygote to access the runtime feature flag properties. 195get_prop(zygote, device_config_runtime_native_prop) 196get_prop(zygote, device_config_runtime_native_boot_prop) 197 198# Allow the zygote to access window manager native boot feature flags 199# to initialize WindowManager static properties. 200get_prop(zygote, device_config_window_manager_native_boot_prop) 201 202# ingore spurious denials 203# fsetid can be checked as a consequence of chmod when using cgroup v2 uid/pid hierarchy. This is 204# done to determine if the file should inherit setgid. In this case, setgid on the file is 205# undesirable, so suppress the denial. 206dontaudit zygote self:global_capability_class_set { sys_resource fsetid }; 207 208# Ignore spurious denials calling access() on fuse. 209# Also ignore read and open as sdcardfs may read and open dir when app tries to access a dir that 210# doesn't exist. 211# TODO(b/151316657): avoid the denials 212dontaudit zygote media_rw_data_file:dir { read open setattr }; 213 214# Allow zygote to use ashmem fds from system_server. 215allow zygote system_server:fd use; 216 217# Send unsolicited message to system_server 218unix_socket_send(zygote, system_unsolzygote, system_server) 219 220# Allow zygote to access media_variant_prop for static initialization 221get_prop(zygote, media_variant_prop) 222 223# Allow zygote to access odsign verification status 224get_prop(zygote, odsign_prop) 225 226# Allow zygote to read ro.control_privapp_permissions and ro.cp_system_other_odex 227get_prop(zygote, packagemanager_config_prop) 228 229# Allow zygote to read qemu.sf.lcd_density 230get_prop(zygote, qemu_sf_lcd_density_prop) 231 232# Allow zygote to read /apex/apex-info-list.xml 233allow zygote apex_info_file:file r_file_perms; 234 235# Allow zygote to canonicalize vendor APEX paths. This is used when zygote is checking the 236# preinstalled path of APEXes that contain runtime resource overlays for the 'android' package. 237allow zygote vendor_apex_file:dir { getattr search }; 238allow zygote vendor_apex_file:file { getattr }; 239 240# Allow zygote to query for compression/features. 241r_dir_file(zygote, sysfs_fs_f2fs) 242 243### 244### neverallow rules 245### 246 247# Ensure that all types assigned to app processes are included 248# in the appdomain attribute, so that all allow and neverallow rules 249# written on appdomain are applied to all app processes. 250# This is achieved by ensuring that it is impossible for zygote to 251# setcon (dyntransition) to any types other than those associated 252# with appdomain plus system_server_startup, webview_zygote and 253# app_zygote. 254neverallow zygote ~{ 255 appdomain 256 system_server_startup 257 webview_zygote 258 app_zygote 259}:process dyntransition; 260 261# Zygote should never execute anything from /data except for 262# /data/dalvik-cache files or files generated during on-device 263# signing under /data/misc/apexdata/com.android.art/. 264neverallow zygote { 265 data_file_type 266 -apex_art_data_file # map PROT_EXEC 267 -dalvikcache_data_file # map PROT_EXEC 268}:file no_x_file_perms; 269 270# Do not allow access to Bluetooth-related system properties and files 271neverallow zygote { 272 bluetooth_a2dp_offload_prop 273 bluetooth_audio_hal_prop 274 bluetooth_prop 275 exported_bluetooth_prop 276}:file create_file_perms; 277 278# Zygote should not be able to access app private data. 279neverallow zygote app_data_file_type:dir ~getattr; 280