Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 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 | ### |
Jeff Vander Stoep | 9f5d0d9 | 2019-01-29 14:43:45 -0800 | [diff] [blame] | 9 | type appdomain_tmpfs, file_type; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 10 | |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 11 | ### |
| 12 | ### Neverallow rules |
| 13 | ### |
| 14 | ### These are things that Android apps should NEVER be able to do |
| 15 | ### |
| 16 | |
| 17 | # Superuser capabilities. |
Roshan Pius | d804a76 | 2019-11-22 09:36:20 -0800 | [diff] [blame] | 18 | # bluetooth requires net_admin and wake_alarm. network stack app requires net_admin. |
| 19 | neverallow { appdomain -bluetooth -network_stack } self:capability_class_set *; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 20 | |
| 21 | # Block device access. |
| 22 | neverallow appdomain dev_type:blk_file { read write }; |
| 23 | |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 24 | # Note: Try expanding list of app domains in the future. |
| 25 | neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write }; |
| 26 | |
| 27 | neverallow { appdomain -nfc } nfc_device:chr_file |
| 28 | { read write }; |
| 29 | neverallow { appdomain -bluetooth } hci_attach_dev:chr_file |
| 30 | { read write }; |
| 31 | neverallow appdomain tee_device:chr_file { read write }; |
| 32 | |
| 33 | # Privileged netlink socket interfaces. |
Chiachang Wang | e063585 | 2019-10-12 20:49:23 +0900 | [diff] [blame] | 34 | neverallow { appdomain -network_stack } |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 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. |
Patrick Rohr | ab02397 | 2022-05-19 21:34:31 -0700 | [diff] [blame] | 46 | neverallow { appdomain -network_stack } |
| 47 | domain:netlink_kobject_uevent_socket { write append }; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 48 | |
| 49 | # Sockets under /dev/socket that are not specifically typed. |
| 50 | neverallow appdomain socket_device:sock_file write; |
| 51 | |
| 52 | # Unix domain sockets. |
| 53 | neverallow appdomain adbd_socket:sock_file write; |
| 54 | neverallow { appdomain -radio } rild_socket:sock_file write; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 55 | |
| 56 | # ptrace access to non-app domains. |
| 57 | neverallow appdomain { domain -appdomain }:process ptrace; |
| 58 | |
Nick Kralevich | 84a42ea | 2018-07-25 23:48:14 -0700 | [diff] [blame] | 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 |
Mark Salyzyn | 275ea12 | 2018-08-07 16:03:47 -0700 | [diff] [blame] | 63 | # produce stack traces. llkd is excluded, as it needs ptrace access to |
| 64 | # inspect stack traces for live lock conditions. |
Nick Kralevich | 84a42ea | 2018-07-25 23:48:14 -0700 | [diff] [blame] | 65 | |
Mark Salyzyn | 275ea12 | 2018-08-07 16:03:47 -0700 | [diff] [blame] | 66 | neverallow { |
| 67 | domain |
| 68 | -appdomain |
| 69 | -crash_dump |
| 70 | userdebug_or_eng(`-llkd') |
| 71 | } appdomain:process ptrace; |
Nick Kralevich | 84a42ea | 2018-07-25 23:48:14 -0700 | [diff] [blame] | 72 | |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 73 | # Read or write access to /proc/pid entries for any non-app domain. |
| 74 | # A different form of hidepid=2 like protections |
| 75 | neverallow appdomain { domain -appdomain }:file no_w_file_perms; |
| 76 | neverallow { 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. |
Florian Mayer | aeca04b | 2018-12-06 13:28:01 +0000 | [diff] [blame] | 82 | # -perfetto is to allow shell (which is an appdomain) to kill perfetto |
| 83 | # (see private/shell.te). |
| 84 | neverallow appdomain { domain -appdomain -perfetto }:process |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 85 | { sigkill sigstop signal }; |
| 86 | |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 87 | # Write to rootfs. |
| 88 | neverallow appdomain rootfs:dir_file_class_set |
| 89 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 90 | |
| 91 | # Write to /system. |
Steven Moreland | 9c2a5cf | 2023-05-17 23:44:30 +0000 | [diff] [blame] | 92 | neverallow appdomain system_file_type:dir_file_class_set |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 93 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 94 | |
| 95 | # Write to entrypoint executables. |
| 96 | neverallow 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. |
| 103 | neverallow 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. |
| 107 | neverallow appdomain drm_data_file:dir_file_class_set |
| 108 | { create write setattr relabelfrom relabelto append unlink link rename }; |
Songchun Fan | a3c0b3f | 2020-12-10 10:51:30 -0800 | [diff] [blame] | 109 | neverallow { appdomain -platform_app } |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 110 | apk_data_file:dir_file_class_set |
| 111 | { create write setattr relabelfrom relabelto append unlink link rename }; |
Songchun Fan | a3c0b3f | 2020-12-10 10:51:30 -0800 | [diff] [blame] | 112 | neverallow { appdomain -platform_app } |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 113 | apk_tmp_file:dir_file_class_set |
| 114 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 115 | neverallow { appdomain -platform_app } |
| 116 | apk_private_data_file:dir_file_class_set |
| 117 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 118 | neverallow { appdomain -platform_app } |
| 119 | apk_private_tmp_file:dir_file_class_set |
| 120 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 121 | neverallow { appdomain -shell } |
| 122 | shell_data_file:dir_file_class_set |
| 123 | { create setattr relabelfrom relabelto append unlink link rename }; |
| 124 | neverallow { appdomain -bluetooth } |
| 125 | bluetooth_data_file:dir_file_class_set |
| 126 | { create write setattr relabelfrom relabelto append unlink link rename }; |
David Zeuthen | 02bf814 | 2020-01-17 16:47:53 -0500 | [diff] [blame] | 127 | neverallow { domain -credstore -init } credstore_data_file:dir_file_class_set *; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 128 | neverallow appdomain |
| 129 | keystore_data_file:dir_file_class_set |
| 130 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 131 | neverallow appdomain |
| 132 | systemkeys_data_file:dir_file_class_set |
| 133 | { create write setattr relabelfrom relabelto append unlink link rename }; |
Roshan Pius | d804a76 | 2019-11-22 09:36:20 -0800 | [diff] [blame] | 134 | neverallow appdomain |
| 135 | wifi_data_file:dir_file_class_set |
| 136 | { create write setattr relabelfrom relabelto append unlink link rename }; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 137 | neverallow 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 |
| 142 | neverallow { appdomain -untrusted_app_all -platform_app -priv_app } |
| 143 | { apk_tmp_file apk_private_tmp_file }:dir_file_class_set *; |
| 144 | |
| 145 | neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *; |
| 146 | neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read }; |
| 147 | |
| 148 | # Access to factory files. |
| 149 | neverallow appdomain efs_file:dir_file_class_set write; |
| 150 | neverallow { appdomain -shell } efs_file:dir_file_class_set read; |
| 151 | |
| 152 | # Write to various pseudo file systems. |
| 153 | neverallow { appdomain -bluetooth -nfc } |
| 154 | sysfs:dir_file_class_set write; |
| 155 | neverallow appdomain |
| 156 | proc:dir_file_class_set write; |
| 157 | |
| 158 | # Access to syslog(2) or /proc/kmsg. |
Roshan Pius | d804a76 | 2019-11-22 09:36:20 -0800 | [diff] [blame] | 159 | neverallow appdomain kernel:system { syslog_read syslog_mod syslog_console }; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 160 | |
| 161 | # SELinux is not an API for apps to use |
| 162 | neverallow { appdomain -shell } *:security { compute_av check_context }; |
| 163 | neverallow { 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. |
| 167 | neverallow appdomain fs_type:filesystem ~getattr; |
| 168 | |
| 169 | # prevent creation/manipulation of globally readable symlinks |
| 170 | neverallow 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 | |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 180 | # Applications should use the activity model for receiving events |
| 181 | neverallow { |
| 182 | appdomain |
| 183 | -shell # bugreport |
| 184 | } input_device:chr_file ~getattr; |
| 185 | |
Joel Galenson | b0d74a1 | 2020-07-27 09:30:34 -0700 | [diff] [blame] | 186 | # Do not allow access to Bluetooth-related system properties except for a few allowed domains. |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 187 | # neverallow rules for access to Bluetooth-related data files are above. |
| 188 | neverallow { |
| 189 | appdomain |
| 190 | -bluetooth |
| 191 | -system_app |
Cheney Ni | e55a74b | 2019-03-18 11:07:32 +0800 | [diff] [blame] | 192 | } { bluetooth_audio_hal_prop bluetooth_a2dp_offload_prop bluetooth_prop exported_bluetooth_prop }:file create_file_perms; |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 193 | |
Jack Yu | 4412ba4 | 2021-06-11 00:28:31 +0800 | [diff] [blame] | 194 | # allow system_app to access Nfc-related system properties. |
| 195 | set_prop(system_app, nfc_prop) |
| 196 | |
Gary Jian | 874dd08 | 2022-03-10 01:36:12 +0800 | [diff] [blame] | 197 | # allow system_app to access radio_config system properties. |
| 198 | set_prop(system_app, radio_control_prop) |
| 199 | |
Jeff Vander Stoep | 77b290f | 2017-12-19 08:19:52 -0800 | [diff] [blame] | 200 | # Apps cannot access proc_uid_time_in_state |
| 201 | neverallow appdomain proc_uid_time_in_state:file *; |
| 202 | |
| 203 | # Apps cannot access proc_uid_concurrent_active_time |
| 204 | neverallow appdomain proc_uid_concurrent_active_time:file *; |
| 205 | |
| 206 | # Apps cannot access proc_uid_concurrent_policy_time |
| 207 | neverallow appdomain proc_uid_concurrent_policy_time:file *; |
Marissa Wall | dfe063c | 2018-01-19 13:48:31 -0800 | [diff] [blame] | 208 | |
| 209 | # Apps cannot access proc_uid_cpupower |
| 210 | neverallow appdomain proc_uid_cpupower:file *; |
Jeff Vander Stoep | 4245177 | 2018-09-28 10:55:14 -0700 | [diff] [blame] | 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. |
| 215 | neverallow { appdomain -shell } proc_net_tcp_udp:file *; |
Jiyong Park | a0f998e | 2019-03-15 02:45:33 +0900 | [diff] [blame] | 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. |
| 222 | neverallow appdomain system_bootstrap_lib_file:file |
| 223 | { open read write append execute execute_no_trans map }; |
| 224 | neverallow appdomain system_bootstrap_lib_file:dir |
| 225 | { open read getattr search }; |