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### 12### Neverallow rules 13### 14### These are things that Android apps should NEVER be able to do 15### 16 17# Superuser capabilities. 18# bluetooth requires net_admin and wake_alarm. network stack app requires net_admin. 19neverallow { appdomain -bluetooth -network_stack } self:capability_class_set *; 20 21# Block device access. 22neverallow appdomain dev_type:blk_file { read write }; 23 24# Note: Try expanding list of app domains in the future. 25neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write }; 26 27neverallow { appdomain -nfc } nfc_device:chr_file 28 { read write }; 29neverallow { appdomain -bluetooth } hci_attach_dev:chr_file 30 { read write }; 31neverallow appdomain tee_device:chr_file { read write }; 32 33# Privileged netlink socket interfaces. 34neverallow { appdomain -network_stack } 35 domain:{ 36 netlink_tcpdiag_socket 37 netlink_nflog_socket 38 netlink_xfrm_socket 39 netlink_audit_socket 40 netlink_dnrt_socket 41 } *; 42 43# These messages are broadcast messages from the kernel to userspace. 44# Do not allow the writing of netlink messages, which has been a source 45# of rooting vulns in the past. 46neverallow { appdomain -network_stack } 47 domain:netlink_kobject_uevent_socket { write append }; 48 49# Sockets under /dev/socket that are not specifically typed. 50neverallow appdomain socket_device:sock_file write; 51 52# Unix domain sockets. 53neverallow appdomain adbd_socket:sock_file write; 54neverallow { appdomain -radio } rild_socket:sock_file write; 55 56# ptrace access to non-app domains. 57neverallow appdomain { domain -appdomain }:process ptrace; 58 59# The Android security model guarantees the confidentiality and integrity 60# of application data and execution state. Ptrace bypasses those 61# confidentiality guarantees. Disallow ptrace access from system components 62# to apps. Crash_dump is excluded, as it needs ptrace access to 63# produce stack traces. llkd is excluded, as it needs ptrace access to 64# inspect stack traces for live lock conditions. 65 66neverallow { 67 domain 68 -appdomain 69 -crash_dump 70 userdebug_or_eng(`-llkd') 71} appdomain:process ptrace; 72 73# Read or write access to /proc/pid entries for any non-app domain. 74# A different form of hidepid=2 like protections 75neverallow appdomain { domain -appdomain }:file no_w_file_perms; 76neverallow { appdomain -shell } { domain -appdomain }:file no_rw_file_perms; 77 78# signal access to non-app domains. 79# sigchld allowed for parent death notification. 80# signull allowed for kill(pid, 0) existence test. 81# All others prohibited. 82# -perfetto is to allow shell (which is an appdomain) to kill perfetto 83# (see private/shell.te). 84neverallow appdomain { domain -appdomain -perfetto }:process 85 { sigkill sigstop signal }; 86 87# Write to rootfs. 88neverallow appdomain rootfs:dir_file_class_set 89 { create write setattr relabelfrom relabelto append unlink link rename }; 90 91# Write to /system. 92neverallow appdomain system_file:dir_file_class_set 93 { create write setattr relabelfrom relabelto append unlink link rename }; 94 95# Write to entrypoint executables. 96neverallow appdomain exec_type:file 97 { create write setattr relabelfrom relabelto append unlink link rename }; 98 99# Write to system-owned parts of /data. 100# This is the default type for anything under /data not otherwise 101# specified in file_contexts. Define a different type for portions 102# that should be writable by apps. 103neverallow appdomain system_data_file:dir_file_class_set 104 { create write setattr relabelfrom relabelto append unlink link rename }; 105 106# Write to various other parts of /data. 107neverallow appdomain drm_data_file:dir_file_class_set 108 { create write setattr relabelfrom relabelto append unlink link rename }; 109neverallow { appdomain -platform_app } 110 apk_data_file:dir_file_class_set 111 { create write setattr relabelfrom relabelto append unlink link rename }; 112neverallow { appdomain -platform_app } 113 apk_tmp_file:dir_file_class_set 114 { create write setattr relabelfrom relabelto append unlink link rename }; 115neverallow { appdomain -platform_app } 116 apk_private_data_file:dir_file_class_set 117 { create write setattr relabelfrom relabelto append unlink link rename }; 118neverallow { appdomain -platform_app } 119 apk_private_tmp_file:dir_file_class_set 120 { create write setattr relabelfrom relabelto append unlink link rename }; 121neverallow { appdomain -shell } 122 shell_data_file:dir_file_class_set 123 { create setattr relabelfrom relabelto append unlink link rename }; 124neverallow { appdomain -bluetooth } 125 bluetooth_data_file:dir_file_class_set 126 { create write setattr relabelfrom relabelto append unlink link rename }; 127neverallow { domain -credstore -init } credstore_data_file:dir_file_class_set *; 128neverallow appdomain 129 keystore_data_file:dir_file_class_set 130 { create write setattr relabelfrom relabelto append unlink link rename }; 131neverallow appdomain 132 systemkeys_data_file:dir_file_class_set 133 { create write setattr relabelfrom relabelto append unlink link rename }; 134neverallow appdomain 135 wifi_data_file:dir_file_class_set 136 { create write setattr relabelfrom relabelto append unlink link rename }; 137neverallow appdomain 138 dhcp_data_file:dir_file_class_set 139 { create write setattr relabelfrom relabelto append unlink link rename }; 140 141# access tmp apk files 142neverallow { appdomain -untrusted_app_all -platform_app -priv_app } 143 { apk_tmp_file apk_private_tmp_file }:dir_file_class_set *; 144 145neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *; 146neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read }; 147 148# Access to factory files. 149neverallow appdomain efs_file:dir_file_class_set write; 150neverallow { appdomain -shell } efs_file:dir_file_class_set read; 151 152# Write to various pseudo file systems. 153neverallow { appdomain -bluetooth -nfc } 154 sysfs:dir_file_class_set write; 155neverallow appdomain 156 proc:dir_file_class_set write; 157 158# Access to syslog(2) or /proc/kmsg. 159neverallow appdomain kernel:system { syslog_read syslog_mod syslog_console }; 160 161# SELinux is not an API for apps to use 162neverallow { appdomain -shell } *:security { compute_av check_context }; 163neverallow { appdomain -shell } *:netlink_selinux_socket *; 164 165# Ability to perform any filesystem operation other than statfs(2). 166# i.e. no mount(2), unmount(2), etc. 167neverallow appdomain fs_type:filesystem ~getattr; 168 169# prevent creation/manipulation of globally readable symlinks 170neverallow appdomain { 171 apk_data_file 172 cache_file 173 cache_recovery_file 174 dev_type 175 rootfs 176 system_file 177 tmpfs 178}:lnk_file no_w_file_perms; 179 180# Applications should use the activity model for receiving events 181neverallow { 182 appdomain 183 -shell # bugreport 184} input_device:chr_file ~getattr; 185 186# Do not allow access to Bluetooth-related system properties except for a few allowed domains. 187# neverallow rules for access to Bluetooth-related data files are above. 188neverallow { 189 appdomain 190 -bluetooth 191 -system_app 192} { bluetooth_audio_hal_prop bluetooth_a2dp_offload_prop bluetooth_prop exported_bluetooth_prop }:file create_file_perms; 193 194# allow system_app to access Nfc-related system properties. 195set_prop(system_app, nfc_prop) 196 197# allow system_app to access radio_config system properties. 198set_prop(system_app, radio_control_prop) 199 200# Apps cannot access proc_uid_time_in_state 201neverallow appdomain proc_uid_time_in_state:file *; 202 203# Apps cannot access proc_uid_concurrent_active_time 204neverallow appdomain proc_uid_concurrent_active_time:file *; 205 206# Apps cannot access proc_uid_concurrent_policy_time 207neverallow appdomain proc_uid_concurrent_policy_time:file *; 208 209# Apps cannot access proc_uid_cpupower 210neverallow appdomain proc_uid_cpupower:file *; 211 212# Apps may not read /proc/net/{tcp,tcp6,udp,udp6}. These files leak information across the 213# application boundary. VPN apps may use the ConnectivityManager.getConnectionOwnerUid() API to 214# perform UID lookups. 215neverallow { appdomain -shell } proc_net_tcp_udp:file *; 216 217# Apps cannot access bootstrap files. The bootstrap files are only for 218# extremely early processes (like init, etc.) which are started before 219# the runtime APEX is activated and Bionic libs are provided from there. 220# If app process accesses (or even load/execute) the bootstrap files, 221# it might cause problems such as ODR violation, etc. 222neverallow appdomain system_bootstrap_lib_file:file 223 { open read write append execute execute_no_trans map }; 224neverallow appdomain system_bootstrap_lib_file:dir 225 { open read getattr search }; 226