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 27# Move children into the peer process group. 28allow zygote system_server:process { getpgid setpgid }; 29allow zygote appdomain:process { getpgid setpgid }; 30allow zygote webview_zygote:process { getpgid setpgid }; 31allow zygote app_zygote:process { getpgid setpgid }; 32 33# Read system data. 34allow zygote system_data_file:dir r_dir_perms; 35allow zygote system_data_file:file r_file_perms; 36 37# Write to /data/dalvik-cache. 38allow zygote dalvikcache_data_file:dir create_dir_perms; 39allow zygote dalvikcache_data_file:file create_file_perms; 40 41# Create symlinks in /data/dalvik-cache. 42allow zygote dalvikcache_data_file:lnk_file create_file_perms; 43 44# Write to /data/resource-cache. 45allow zygote resourcecache_data_file:dir rw_dir_perms; 46allow zygote resourcecache_data_file:file create_file_perms; 47 48# For updateability, the zygote may fetch the current boot 49# classpath from the dalvik cache. Integrity of the files 50# is ensured by fsverity protection (checked in art_apex_boot_integrity). 51allow zygote dalvikcache_data_file:file execute; 52 53# Bind mount on /data/data and mounted volumes 54allow zygote { system_data_file mnt_expand_file }:dir mounton; 55 56# Relabel /data/user /data/user_de and /data/data 57allow zygote tmpfs:{ dir lnk_file } relabelfrom; 58allow zygote system_data_file:{ dir lnk_file } relabelto; 59 60# Zygote opens /mnt/expand to mount CE DE storage on each vol 61allow zygote mnt_expand_file:dir { open read search relabelto }; 62 63# Bind mount subdirectories on /data/misc/profiles/cur 64allow zygote { user_profile_data_file }:dir { mounton search }; 65 66# Create and bind dirs on /data/data 67allow zygote tmpfs:dir { create_dir_perms mounton }; 68 69# Goes into media directory and bind mount obb directory 70allow zygote media_rw_data_file:dir { getattr search }; 71 72# Read if sdcardfs is supported 73allow zygote proc_filesystems:file r_file_perms; 74 75# Create symlink for /data/user/0 76allow zygote tmpfs:lnk_file create; 77 78allow zygote mirror_data_file:dir r_dir_perms; 79 80# Get inode of data directories 81allow zygote { 82 system_data_file 83 radio_data_file 84 app_data_file 85 shell_data_file 86 bluetooth_data_file 87 privapp_data_file 88 nfc_data_file 89 mnt_expand_file 90}:dir getattr; 91 92# Allow zygote to create JIT memory. 93allow zygote self:process execmem; 94allow zygote zygote_tmpfs:file execute; 95allow zygote ashmem_libcutils_device:chr_file execute; 96 97# Execute idmap and dex2oat within zygote's own domain. 98# TODO: Should either of these be transitioned to the same domain 99# used by installd or stay in-domain for zygote? 100allow zygote idmap_exec:file rx_file_perms; 101allow zygote dex2oat_exec:file rx_file_perms; 102 103# Allow apps access to /vendor/overlay 104r_dir_file(zygote, vendor_overlay_file) 105 106# Control cgroups. 107allow zygote cgroup:dir create_dir_perms; 108allow zygote cgroup:{ file lnk_file } r_file_perms; 109allow zygote self:global_capability_class_set sys_admin; 110 111# Allow zygote to stat the files that it opens. The zygote must 112# be able to inspect them so that it can reopen them on fork 113# if necessary: b/30963384. 114allow zygote pmsg_device:chr_file getattr; 115allow zygote debugfs_trace_marker:file getattr; 116 117# Get seapp_contexts 118allow zygote seapp_contexts_file:file r_file_perms; 119# Check validity of SELinux context before use. 120selinux_check_context(zygote) 121# Check SELinux permissions. 122selinux_check_access(zygote) 123 124# Native bridge functionality requires that zygote replaces 125# /proc/cpuinfo with /system/lib/<ISA>/cpuinfo using a bind mount 126allow zygote proc_cpuinfo:file mounton; 127 128# Allow remounting rootfs as MS_SLAVE. 129allow zygote rootfs:dir mounton; 130allow zygote tmpfs:filesystem { mount unmount }; 131allow zygote fuse:filesystem { unmount }; 132allow zygote sdcardfs:filesystem { unmount }; 133 134# Allow creating user-specific storage source if started before vold. 135allow zygote mnt_user_file:dir { create_dir_perms mounton }; 136allow zygote mnt_user_file:lnk_file create_file_perms; 137allow zygote mnt_user_file:file create_file_perms; 138 139# Allow mounting user-specific storage source if started before vold. 140allow zygote mnt_pass_through_file:dir { create_dir_perms mounton }; 141 142# Allowed to mount user-specific storage into place 143allow zygote storage_file:dir { search mounton }; 144 145# Allow mounting and creating files, dirs on sdcardfs. 146allow zygote { sdcard_type }:dir { create_dir_perms mounton }; 147allow zygote { sdcard_type }:file { create_file_perms }; 148 149# Handle --invoke-with command when launching Zygote with a wrapper command. 150allow zygote zygote_exec:file rx_file_perms; 151 152# Allow zygote to write to statsd. 153unix_socket_send(zygote, statsdw, statsd) 154 155# Root fs. 156r_dir_file(zygote, rootfs) 157 158# System file accesses. 159r_dir_file(zygote, system_file) 160 161# /oem accesses. 162allow zygote oemfs:dir search; 163 164userdebug_or_eng(` 165 # Allow zygote to create and write method traces in /data/misc/trace. 166 allow zygote method_trace_data_file:dir w_dir_perms; 167 allow zygote method_trace_data_file:file { create w_file_perms }; 168') 169 170allow zygote ion_device:chr_file r_file_perms; 171allow zygote tmpfs:dir r_dir_perms; 172 173allow zygote same_process_hal_file:file { execute read open getattr map }; 174 175# Let the zygote access overlays so it can initialize the AssetManager. 176get_prop(zygote, overlay_prop) 177get_prop(zygote, exported_overlay_prop) 178 179# Allow the zygote to access the runtime feature flag properties. 180get_prop(zygote, device_config_runtime_native_prop) 181get_prop(zygote, device_config_runtime_native_boot_prop) 182 183# Allow the zygote to access window manager native boot feature flags 184# to initialize WindowManager static properties. 185get_prop(zygote, device_config_window_manager_native_boot_prop) 186 187# ingore spurious denials 188dontaudit zygote self:global_capability_class_set sys_resource; 189 190# Ignore spurious denials calling access() on fuse 191# TODO(b/151316657): avoid the denials 192dontaudit zygote media_rw_data_file:dir setattr; 193 194# Allow zygote to use ashmem fds from system_server. 195allow zygote system_server:fd use; 196 197# Send unsolicited message to system_server 198unix_socket_send(zygote, system_unsolzygote, system_server) 199 200# Allow zygote to access media_variant_prop for static initialization 201get_prop(zygote, media_variant_prop) 202 203### 204### neverallow rules 205### 206 207# Ensure that all types assigned to app processes are included 208# in the appdomain attribute, so that all allow and neverallow rules 209# written on appdomain are applied to all app processes. 210# This is achieved by ensuring that it is impossible for zygote to 211# setcon (dyntransition) to any types other than those associated 212# with appdomain plus system_server_startup, webview_zygote and 213# app_zygote. 214neverallow zygote ~{ 215 appdomain 216 system_server_startup 217 webview_zygote 218 app_zygote 219}:process dyntransition; 220 221# Zygote should never execute anything from /data except for /data/dalvik-cache files. 222neverallow zygote { 223 data_file_type 224 -dalvikcache_data_file # map PROT_EXEC 225}:file no_x_file_perms; 226 227# Do not allow access to Bluetooth-related system properties and files 228neverallow zygote { 229 bluetooth_a2dp_offload_prop 230 bluetooth_audio_hal_prop 231 bluetooth_prop 232 exported_bluetooth_prop 233}:file create_file_perms; 234 235# Zygote should not be able to access app private data. 236neverallow zygote { 237 privapp_data_file 238 app_data_file 239}:dir ~getattr; 240