1### 2### Domain for all zygote spawned apps 3### 4### This file is the base policy for all zygote spawned apps. 5### Other policy files, such as isolated_app.te, untrusted_app.te, etc 6### extend from this policy. Only policies which should apply to ALL 7### zygote spawned apps should be added here. 8### 9type appdomain_tmpfs, file_type; 10 11# WebView and other application-specific JIT compilers 12allow appdomain self:process execmem; 13 14allow appdomain ashmem_device:chr_file execute; 15 16# Receive and use open file descriptors inherited from zygote. 17allow appdomain zygote:fd use; 18 19# gdbserver for ndk-gdb reads the zygote. 20# valgrind needs mmap exec for zygote 21allow appdomain zygote_exec:file rx_file_perms; 22 23# Notify zygote of death; 24allow appdomain zygote:process sigchld; 25 26# Read /data/dalvik-cache. 27allow appdomain dalvikcache_data_file:dir { search getattr }; 28allow appdomain dalvikcache_data_file:file r_file_perms; 29 30# Read the /sdcard and /mnt/sdcard symlinks 31allow { appdomain -isolated_app } rootfs:lnk_file r_file_perms; 32allow { appdomain -isolated_app } tmpfs:lnk_file r_file_perms; 33 34# Search /storage/emulated tmpfs mount. 35allow appdomain tmpfs:dir r_dir_perms; 36 37# Notify zygote of the wrapped process PID when using --invoke-with. 38allow appdomain zygote:fifo_file write; 39 40userdebug_or_eng(` 41 # Allow apps to create and write method traces in /data/misc/trace. 42 allow appdomain method_trace_data_file:dir w_dir_perms; 43 allow appdomain method_trace_data_file:file { create w_file_perms }; 44') 45 46# Notify shell and adbd of death when spawned via runas for ndk-gdb. 47allow appdomain shell:process sigchld; 48allow appdomain adbd:process sigchld; 49 50# child shell or gdbserver pty access for runas. 51allow appdomain devpts:chr_file { getattr read write ioctl }; 52 53# Use pipes and sockets provided by system_server via binder or local socket. 54allow appdomain system_server:fd use; 55allow appdomain system_server:fifo_file rw_file_perms; 56allow appdomain system_server:unix_stream_socket { read write setopt getattr getopt shutdown }; 57allow appdomain system_server:tcp_socket { read write getattr getopt shutdown }; 58 59# For AppFuse. 60allow appdomain vold:fd use; 61 62# Communication with other apps via fifos 63allow appdomain appdomain:fifo_file rw_file_perms; 64 65# Communicate with surfaceflinger. 66allow appdomain surfaceflinger:unix_stream_socket { read write setopt getattr getopt shutdown }; 67 68# App sandbox file accesses. 69allow { appdomain -isolated_app } { app_data_file privapp_data_file }:dir create_dir_perms; 70allow { appdomain -isolated_app } { app_data_file privapp_data_file }:file create_file_perms; 71 72# Traverse into expanded storage 73allow appdomain mnt_expand_file:dir r_dir_perms; 74 75# Keychain and user-trusted credentials 76r_dir_file(appdomain, keychain_data_file) 77allow appdomain misc_user_data_file:dir r_dir_perms; 78allow appdomain misc_user_data_file:file r_file_perms; 79 80# TextClassifier 81r_dir_file({ appdomain -isolated_app }, textclassifier_data_file) 82 83# Access to OEM provided data and apps 84allow appdomain oemfs:dir r_dir_perms; 85allow appdomain oemfs:file rx_file_perms; 86 87# Execute the shell or other system executables. 88allow { appdomain -ephemeral_app } shell_exec:file rx_file_perms; 89allow { appdomain -ephemeral_app } toolbox_exec:file rx_file_perms; 90allow appdomain system_file:file x_file_perms; 91not_full_treble(`allow { appdomain -ephemeral_app } vendor_file:file x_file_perms;') 92 93# Renderscript needs the ability to read directories on /system 94allow appdomain system_file:dir r_dir_perms; 95allow appdomain system_file:lnk_file { getattr open read }; 96# Renderscript specific permissions to open /system/vendor/lib64. 97not_full_treble(` 98 allow appdomain vendor_file_type:dir r_dir_perms; 99 allow appdomain vendor_file_type:lnk_file { getattr open read }; 100') 101 102full_treble_only(` 103 # For looking up Renderscript vendor drivers 104 allow { appdomain -isolated_app } vendor_file:dir { open read }; 105') 106 107# Allow apps access to /vendor/app except for privileged 108# apps which cannot be in /vendor. 109r_dir_file({ appdomain -ephemeral_app }, vendor_app_file) 110allow { appdomain -ephemeral_app } vendor_app_file:file execute; 111 112# Allow apps access to /vendor/overlay 113r_dir_file(appdomain, vendor_overlay_file) 114 115# Allow apps access to /vendor/framework 116# for vendor provided libraries. 117r_dir_file(appdomain, vendor_framework_file) 118 119# Allow apps read / execute access to vendor public libraries. 120allow appdomain vendor_public_lib_file:dir r_dir_perms; 121allow appdomain vendor_public_lib_file:file { execute read open getattr map }; 122 123# Read/write wallpaper file (opened by system). 124allow appdomain wallpaper_file:file { getattr read write map }; 125 126# Read/write cached ringtones (opened by system). 127allow appdomain ringtone_file:file { getattr read write map }; 128 129# Read ShortcutManager icon files (opened by system). 130allow appdomain shortcut_manager_icons:file { getattr read map }; 131 132# Read icon file (opened by system). 133allow appdomain icon_file:file { getattr read map }; 134 135# Old stack dumping scheme : append to a global trace file (/data/anr/traces.txt). 136# 137# TODO: All of these permissions except for anr_data_file:file append can be 138# withdrawn once we've switched to the new stack dumping mechanism, see b/32064548 139# and the rules below. 140allow appdomain anr_data_file:dir search; 141allow appdomain anr_data_file:file { open append }; 142 143# New stack dumping scheme : request an output FD from tombstoned via a unix 144# domain socket. 145# 146# Allow apps to connect and write to the tombstoned java trace socket in 147# order to dump their traces. Also allow them to append traces to pipes 148# created by dumptrace. (Also see the rules below where they are given 149# additional permissions to dumpstate pipes for other aspects of bug report 150# creation). 151unix_socket_connect(appdomain, tombstoned_java_trace, tombstoned) 152allow appdomain tombstoned:fd use; 153allow appdomain dumpstate:fifo_file append; 154allow appdomain incidentd:fifo_file append; 155 156# Allow apps to send dump information to dumpstate 157allow appdomain dumpstate:fd use; 158allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown }; 159allow appdomain dumpstate:fifo_file { write getattr }; 160allow appdomain shell_data_file:file { write getattr }; 161 162# Allow apps to send dump information to incidentd 163allow appdomain incidentd:fd use; 164allow appdomain incidentd:fifo_file { write getattr }; 165 166# Allow apps to send information to statsd socket. 167unix_socket_send(appdomain, statsdw, statsd) 168 169# Write profiles /data/misc/profiles 170allow appdomain user_profile_data_file:dir { search write add_name }; 171allow appdomain user_profile_data_file:file create_file_perms; 172 173# Send heap dumps to system_server via an already open file descriptor 174# % adb shell am set-watch-heap com.android.systemui 1048576 175# % adb shell dumpsys procstats --start-testing 176# debuggable builds only. 177userdebug_or_eng(` 178 allow appdomain heapdump_data_file:file append; 179') 180 181# /proc/net access. 182# TODO(b/9496886) Audit access for removal. 183# proc_net access for the negated domains below is granted (or not) in their 184# individual .te files. 185r_dir_file({ 186 appdomain 187 -ephemeral_app 188 -isolated_app 189 -platform_app 190 -priv_app 191 -shell 192 -system_app 193 -untrusted_app_all 194}, proc_net_type) 195# audit access for all these non-core app domains. 196userdebug_or_eng(` 197 auditallow { 198 appdomain 199 -ephemeral_app 200 -isolated_app 201 -platform_app 202 -priv_app 203 -shell 204 -su 205 -system_app 206 -untrusted_app_all 207 } proc_net_type:{ dir file lnk_file } { getattr open read }; 208') 209 210# Grant GPU access to all processes started by Zygote. 211# They need that to render the standard UI. 212allow { appdomain -isolated_app } gpu_device:chr_file rw_file_perms; 213 214# Use the Binder. 215binder_use(appdomain) 216# Perform binder IPC to binder services. 217binder_call(appdomain, binderservicedomain) 218# Perform binder IPC to other apps. 219binder_call(appdomain, appdomain) 220# Perform binder IPC to ephemeral apps. 221binder_call(appdomain, ephemeral_app) 222 223# Talk with graphics composer fences 224allow appdomain hal_graphics_composer:fd use; 225 226# Already connected, unnamed sockets being passed over some other IPC 227# hence no sock_file or connectto permission. This appears to be how 228# Chrome works, may need to be updated as more apps using isolated services 229# are examined. 230allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown }; 231 232# Backup ability for every app. BMS opens and passes the fd 233# to any app that has backup ability. Hence, no open permissions here. 234allow appdomain backup_data_file:file { read write getattr map }; 235allow appdomain cache_backup_file:file { read write getattr map }; 236allow appdomain cache_backup_file:dir getattr; 237# Backup ability using 'adb backup' 238allow appdomain system_data_file:lnk_file r_file_perms; 239allow appdomain system_data_file:file { getattr read map }; 240 241# Allow read/stat of /data/media files passed by Binder or local socket IPC. 242allow { appdomain -isolated_app } media_rw_data_file:file { read getattr }; 243 244# Read and write /data/data/com.android.providers.telephony files passed over Binder. 245allow { appdomain -isolated_app } radio_data_file:file { read write getattr }; 246 247# Allow access to external storage; we have several visible mount points under /storage 248# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary 249allow { appdomain -isolated_app -ephemeral_app } storage_file:dir r_dir_perms; 250allow { appdomain -isolated_app -ephemeral_app } storage_file:lnk_file r_file_perms; 251allow { appdomain -isolated_app -ephemeral_app } mnt_user_file:dir r_dir_perms; 252allow { appdomain -isolated_app -ephemeral_app } mnt_user_file:lnk_file r_file_perms; 253 254# Read/write visible storage 255allow { appdomain -isolated_app -ephemeral_app } sdcard_type:dir create_dir_perms; 256allow { appdomain -isolated_app -ephemeral_app } sdcard_type:file create_file_perms; 257# This should be removed if sdcardfs is modified to alter the secontext for its 258# accesses to the underlying FS. 259allow { appdomain -isolated_app -ephemeral_app } media_rw_data_file:dir create_dir_perms; 260allow { appdomain -isolated_app -ephemeral_app } media_rw_data_file:file create_file_perms; 261 262# Allow apps to use the USB Accessory interface. 263# http://developer.android.com/guide/topics/connectivity/usb/accessory.html 264# 265# USB devices are first opened by the system server (USBDeviceManagerService) 266# and the file descriptor is passed to the right Activity via binder. 267allow { appdomain -isolated_app -ephemeral_app } usb_device:chr_file { read write getattr ioctl }; 268allow { appdomain -isolated_app -ephemeral_app } usbaccessory_device:chr_file { read write getattr }; 269 270# For art. 271allow appdomain dalvikcache_data_file:file execute; 272allow appdomain dalvikcache_data_file:lnk_file r_file_perms; 273 274# Allow any app to read shared RELRO files. 275allow appdomain shared_relro_file:dir search; 276allow appdomain shared_relro_file:file r_file_perms; 277 278# Allow apps to read/execute installed binaries 279allow appdomain apk_data_file:dir r_dir_perms; 280allow appdomain apk_data_file:file rx_file_perms; 281 282# /data/resource-cache 283allow appdomain resourcecache_data_file:file r_file_perms; 284allow appdomain resourcecache_data_file:dir r_dir_perms; 285 286# logd access 287read_logd(appdomain) 288control_logd({ appdomain -ephemeral_app }) 289# application inherit logd write socket (urge is to deprecate this long term) 290allow appdomain zygote:unix_dgram_socket write; 291 292allow { appdomain -isolated_app -ephemeral_app } keystore:keystore_key { get_state get insert delete exist list sign verify }; 293 294use_keystore({ appdomain -isolated_app -ephemeral_app }) 295 296allow appdomain console_device:chr_file { read write }; 297 298# only allow unprivileged socket ioctl commands 299allowxperm { appdomain -bluetooth } self:{ rawip_socket tcp_socket udp_socket } 300 ioctl { unpriv_sock_ioctls unpriv_tty_ioctls }; 301 302allow { appdomain -isolated_app } ion_device:chr_file r_file_perms; 303 304# Allow AAudio apps to use shared memory file descriptors from the HAL 305allow { appdomain -isolated_app } hal_audio:fd use; 306 307# Allow app to access shared memory created by camera HAL1 308allow { appdomain -isolated_app } hal_camera:fd use; 309 310# RenderScript always-passthrough HAL 311allow { appdomain -isolated_app } hal_renderscript_hwservice:hwservice_manager find; 312allow appdomain same_process_hal_file:file { execute read open getattr map }; 313 314# TODO: switch to meminfo service 315allow appdomain proc_meminfo:file r_file_perms; 316 317# For app fuse. 318allow appdomain app_fuse_file:file { getattr read append write }; 319 320pdx_client({ appdomain -isolated_app -ephemeral_app }, display_client) 321pdx_client({ appdomain -isolated_app -ephemeral_app }, display_manager) 322pdx_client({ appdomain -isolated_app -ephemeral_app }, display_vsync) 323pdx_client({ appdomain -isolated_app -ephemeral_app }, performance_client) 324# Apps do not directly open the IPC socket for bufferhubd. 325pdx_use({ appdomain -isolated_app -ephemeral_app }, bufferhub_client) 326 327### 328### CTS-specific rules 329### 330 331# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java. 332# testRunAsHasCorrectCapabilities 333allow appdomain runas_exec:file getattr; 334# Others are either allowed elsewhere or not desired. 335 336# Apps receive an open tun fd from the framework for 337# device traffic. Do not allow untrusted app to directly open tun_device 338allow { appdomain -isolated_app -ephemeral_app } tun_device:chr_file { read write getattr append ioctl }; 339allowxperm { appdomain -isolated_app -ephemeral_app } tun_device:chr_file ioctl TUNGETIFF; 340 341# Connect to adbd and use a socket transferred from it. 342# This is used for e.g. adb backup/restore. 343allow appdomain adbd:unix_stream_socket connectto; 344allow appdomain adbd:fd use; 345allow appdomain adbd:unix_stream_socket { getattr getopt ioctl read write shutdown }; 346 347allow appdomain cache_file:dir getattr; 348 349# Allow apps to run with asanwrapper. 350with_asan(`allow appdomain asanwrapper_exec:file rx_file_perms;') 351 352# Read access to FDs from the DropboxManagerService. 353allow appdomain dropbox_data_file:file { getattr read }; 354 355# Read tmpfs types from these processes. 356allow appdomain audioserver_tmpfs:file { getattr map read write }; 357allow appdomain system_server_tmpfs:file { getattr map read write }; 358allow appdomain zygote_tmpfs:file { map read }; 359 360# Allow vendor apps access to ashmemd to request /dev/ashmem fds. 361binder_call({ appdomain -coredomain }, ashmemd) 362 363### 364### Neverallow rules 365### 366### These are things that Android apps should NEVER be able to do 367### 368 369# Superuser capabilities. 370# bluetooth requires net_admin and wake_alarm. network stack app requires net_admin. 371neverallow { appdomain -bluetooth -network_stack } self:capability_class_set *; 372 373# Block device access. 374neverallow appdomain dev_type:blk_file { read write }; 375 376# Access to any of the following character devices. 377neverallow appdomain { 378 audio_device 379 camera_device 380 dm_device 381 radio_device 382 rpmsg_device 383 video_device 384}:chr_file { read write }; 385 386# Note: Try expanding list of app domains in the future. 387neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write }; 388 389neverallow { appdomain -nfc } nfc_device:chr_file 390 { read write }; 391neverallow { appdomain -bluetooth } hci_attach_dev:chr_file 392 { read write }; 393neverallow appdomain tee_device:chr_file { read write }; 394 395# Privileged netlink socket interfaces. 396neverallow appdomain 397 domain:{ 398 netlink_tcpdiag_socket 399 netlink_nflog_socket 400 netlink_xfrm_socket 401 netlink_audit_socket 402 netlink_dnrt_socket 403 } *; 404 405# These messages are broadcast messages from the kernel to userspace. 406# Do not allow the writing of netlink messages, which has been a source 407# of rooting vulns in the past. 408neverallow appdomain domain:netlink_kobject_uevent_socket { write append }; 409 410# Sockets under /dev/socket that are not specifically typed. 411neverallow appdomain socket_device:sock_file write; 412 413# Unix domain sockets. 414neverallow appdomain adbd_socket:sock_file write; 415neverallow { appdomain -radio } rild_socket:sock_file write; 416 417# ptrace access to non-app domains. 418neverallow appdomain { domain -appdomain }:process ptrace; 419 420# The Android security model guarantees the confidentiality and integrity 421# of application data and execution state. Ptrace bypasses those 422# confidentiality guarantees. Disallow ptrace access from system components 423# to apps. Crash_dump is excluded, as it needs ptrace access to 424# produce stack traces. llkd is excluded, as it needs ptrace access to 425# inspect stack traces for live lock conditions. 426 427neverallow { 428 domain 429 -appdomain 430 -crash_dump 431 userdebug_or_eng(`-llkd') 432} appdomain:process ptrace; 433 434# Read or write access to /proc/pid entries for any non-app domain. 435# A different form of hidepid=2 like protections 436neverallow appdomain { domain -appdomain }:file no_w_file_perms; 437neverallow { appdomain -shell } { domain -appdomain }:file no_rw_file_perms; 438 439# signal access to non-app domains. 440# sigchld allowed for parent death notification. 441# signull allowed for kill(pid, 0) existence test. 442# All others prohibited. 443# -perfetto is to allow shell (which is an appdomain) to kill perfetto 444# (see private/shell.te). 445neverallow appdomain { domain -appdomain -perfetto }:process 446 { sigkill sigstop signal }; 447 448# Write to rootfs. 449neverallow appdomain rootfs:dir_file_class_set 450 { create write setattr relabelfrom relabelto append unlink link rename }; 451 452# Write to /system. 453neverallow appdomain system_file:dir_file_class_set 454 { create write setattr relabelfrom relabelto append unlink link rename }; 455 456# Write to entrypoint executables. 457neverallow appdomain exec_type:file 458 { create write setattr relabelfrom relabelto append unlink link rename }; 459 460# Write to system-owned parts of /data. 461# This is the default type for anything under /data not otherwise 462# specified in file_contexts. Define a different type for portions 463# that should be writable by apps. 464neverallow appdomain system_data_file:dir_file_class_set 465 { create write setattr relabelfrom relabelto append unlink link rename }; 466 467# Write to various other parts of /data. 468neverallow appdomain drm_data_file:dir_file_class_set 469 { create write setattr relabelfrom relabelto append unlink link rename }; 470neverallow { appdomain -platform_app } 471 apk_data_file:dir_file_class_set 472 { create write setattr relabelfrom relabelto append unlink link rename }; 473neverallow { appdomain -platform_app } 474 apk_tmp_file:dir_file_class_set 475 { create write setattr relabelfrom relabelto append unlink link rename }; 476neverallow { appdomain -platform_app } 477 apk_private_data_file:dir_file_class_set 478 { create write setattr relabelfrom relabelto append unlink link rename }; 479neverallow { appdomain -platform_app } 480 apk_private_tmp_file:dir_file_class_set 481 { create write setattr relabelfrom relabelto append unlink link rename }; 482neverallow { appdomain -shell } 483 shell_data_file:dir_file_class_set 484 { create setattr relabelfrom relabelto append unlink link rename }; 485neverallow { appdomain -bluetooth } 486 bluetooth_data_file:dir_file_class_set 487 { create write setattr relabelfrom relabelto append unlink link rename }; 488neverallow appdomain 489 keystore_data_file:dir_file_class_set 490 { create write setattr relabelfrom relabelto append unlink link rename }; 491neverallow appdomain 492 systemkeys_data_file:dir_file_class_set 493 { create write setattr relabelfrom relabelto append unlink link rename }; 494neverallow appdomain 495 wifi_data_file:dir_file_class_set 496 { create write setattr relabelfrom relabelto append unlink link rename }; 497neverallow appdomain 498 dhcp_data_file:dir_file_class_set 499 { create write setattr relabelfrom relabelto append unlink link rename }; 500 501# access tmp apk files 502neverallow { appdomain -untrusted_app_all -platform_app -priv_app } 503 { apk_tmp_file apk_private_tmp_file }:dir_file_class_set *; 504 505neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *; 506neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read }; 507 508# Access to factory files. 509neverallow appdomain efs_file:dir_file_class_set write; 510neverallow { appdomain -shell } efs_file:dir_file_class_set read; 511 512# Write to various pseudo file systems. 513neverallow { appdomain -bluetooth -nfc } 514 sysfs:dir_file_class_set write; 515neverallow appdomain 516 proc:dir_file_class_set write; 517 518# Access to syslog(2) or /proc/kmsg. 519neverallow appdomain kernel:system { syslog_read syslog_mod syslog_console }; 520 521# SELinux is not an API for apps to use 522neverallow { appdomain -shell } *:security { compute_av check_context }; 523neverallow { appdomain -shell } *:netlink_selinux_socket *; 524 525# Ability to perform any filesystem operation other than statfs(2). 526# i.e. no mount(2), unmount(2), etc. 527neverallow appdomain fs_type:filesystem ~getattr; 528 529# prevent creation/manipulation of globally readable symlinks 530neverallow appdomain { 531 apk_data_file 532 cache_file 533 cache_recovery_file 534 dev_type 535 rootfs 536 system_file 537 tmpfs 538}:lnk_file no_w_file_perms; 539 540# Denylist app domains not allowed to execute from /data 541neverallow { 542 bluetooth 543 isolated_app 544 nfc 545 radio 546 shared_relro 547 system_app 548} { 549 data_file_type 550 -dalvikcache_data_file 551 -system_data_file # shared libs in apks 552 -apk_data_file 553}:file no_x_file_perms; 554 555# Applications should use the activity model for receiving events 556neverallow { 557 appdomain 558 -shell # bugreport 559} input_device:chr_file ~getattr; 560 561# Do not allow access to Bluetooth-related system properties except for a few allowlisted domains. 562# neverallow rules for access to Bluetooth-related data files are above. 563neverallow { 564 appdomain 565 -bluetooth 566 -system_app 567} { bluetooth_audio_hal_prop bluetooth_a2dp_offload_prop bluetooth_prop exported_bluetooth_prop }:file create_file_perms; 568 569# Apps cannot access proc_uid_time_in_state 570neverallow appdomain proc_uid_time_in_state:file *; 571 572# Apps cannot access proc_uid_concurrent_active_time 573neverallow appdomain proc_uid_concurrent_active_time:file *; 574 575# Apps cannot access proc_uid_concurrent_policy_time 576neverallow appdomain proc_uid_concurrent_policy_time:file *; 577 578# Apps cannot access proc_uid_cpupower 579neverallow appdomain proc_uid_cpupower:file *; 580 581# Apps may not read /proc/net/{tcp,tcp6,udp,udp6}. These files leak information across the 582# application boundary. VPN apps may use the ConnectivityManager.getConnectionOwnerUid() API to 583# perform UID lookups. 584neverallow { appdomain -shell } proc_net_tcp_udp:file *; 585 586# Apps cannot access bootstrap files. The bootstrap files are only for 587# extremely early processes (like init, etc.) which are started before 588# the runtime APEX is activated and Bionic libs are provided from there. 589# If app process accesses (or even load/execute) the bootstrap files, 590# it might cause problems such as ODR violation, etc. 591neverallow appdomain system_bootstrap_lib_file:file 592 { open read write append execute execute_no_trans map }; 593neverallow appdomain system_bootstrap_lib_file:dir 594 { open read getattr search }; 595