Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 1 | ### |
| 2 | ### neverallow rules for untrusted app domains |
| 3 | ### |
| 4 | |
Nick Kralevich | db5962c | 2017-04-26 16:14:40 -0700 | [diff] [blame] | 5 | define(`all_untrusted_apps',`{ |
| 6 | ephemeral_app |
| 7 | isolated_app |
| 8 | mediaprovider |
| 9 | untrusted_app |
| 10 | untrusted_app_25 |
Jeff Vander Stoep | 3aa7ca5 | 2018-04-03 11:22:38 -0700 | [diff] [blame] | 11 | untrusted_app_27 |
Nick Kralevich | db5962c | 2017-04-26 16:14:40 -0700 | [diff] [blame] | 12 | untrusted_app_all |
| 13 | untrusted_v2_app |
| 14 | }') |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 15 | # Receive or send uevent messages. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 16 | neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 17 | |
| 18 | # Receive or send generic netlink messages |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 19 | neverallow all_untrusted_apps domain:netlink_socket *; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 20 | |
| 21 | # Too much leaky information in debugfs. It's a security |
| 22 | # best practice to ensure these files aren't readable. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 23 | neverallow all_untrusted_apps debugfs_type:file read; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 24 | |
| 25 | # Do not allow untrusted apps to register services. |
| 26 | # Only trusted components of Android should be registering |
| 27 | # services. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 28 | neverallow all_untrusted_apps service_manager_type:service_manager add; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 29 | |
Alex Klyubin | 0065783 | 2017-04-25 09:27:54 -0700 | [diff] [blame] | 30 | # Do not allow untrusted apps to use VendorBinder |
| 31 | neverallow all_untrusted_apps vndbinder_device:chr_file *; |
| 32 | neverallow all_untrusted_apps vndservice_manager_type:service_manager *; |
| 33 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 34 | # Do not allow untrusted apps to connect to the property service |
| 35 | # or set properties. b/10243159 |
Jerry Zhang | 9f152d9 | 2017-04-10 16:57:48 -0700 | [diff] [blame] | 36 | neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write; |
| 37 | neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto; |
| 38 | neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 39 | |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 40 | # net.dns properties are not a public API. Temporarily exempt pre-Oreo apps, |
| 41 | # but otherwise disallow untrusted apps from reading this property. |
| 42 | neverallow { all_untrusted_apps -untrusted_app_25 } net_dns_prop:file read; |
| 43 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 44 | # Do not allow untrusted apps to be assigned mlstrustedsubject. |
| 45 | # This would undermine the per-user isolation model being |
| 46 | # enforced via levelFrom=user in seapp_contexts and the mls |
| 47 | # constraints. As there is no direct way to specify a neverallow |
| 48 | # on attribute assignment, this relies on the fact that fork |
| 49 | # permission only makes sense within a domain (hence should |
| 50 | # never be granted to any other domain within mlstrustedsubject) |
| 51 | # and an untrusted app is allowed fork permission to itself. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 52 | neverallow all_untrusted_apps mlstrustedsubject:process fork; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 53 | |
| 54 | # Do not allow untrusted apps to hard link to any files. |
| 55 | # In particular, if an untrusted app links to other app data |
| 56 | # files, installd will not be able to guarantee the deletion |
| 57 | # of the linked to file. Hard links also contribute to security |
| 58 | # bugs, so we want to ensure untrusted apps never have this |
| 59 | # capability. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 60 | neverallow all_untrusted_apps file_type:file link; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 61 | |
| 62 | # Do not allow untrusted apps to access network MAC address file |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 63 | neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 64 | |
Jeff Vander Stoep | 06cef4f | 2017-10-04 13:12:25 -0700 | [diff] [blame] | 65 | # Do not allow any write access to files in /sys |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 66 | neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms }; |
| 67 | |
| 68 | # Apps may never access the default sysfs label. |
| 69 | neverallow all_untrusted_apps sysfs:file no_rw_file_perms; |
Jeff Vander Stoep | 06cef4f | 2017-10-04 13:12:25 -0700 | [diff] [blame] | 70 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 71 | # Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the |
| 72 | # ioctl permission, or 3. disallow the socket class. |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 73 | neverallowxperm all_untrusted_apps domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls; |
| 74 | neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl; |
| 75 | neverallow all_untrusted_apps *:{ |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 76 | socket netlink_socket packet_socket key_socket appletalk_socket |
Stephen Smalley | 4921085 | 2017-02-06 14:14:58 -0500 | [diff] [blame] | 77 | netlink_tcpdiag_socket netlink_nflog_socket |
| 78 | netlink_xfrm_socket netlink_audit_socket |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 79 | netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket |
| 80 | netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket |
| 81 | netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket |
| 82 | netlink_rdma_socket netlink_crypto_socket |
| 83 | } *; |
| 84 | |
| 85 | # Do not allow untrusted apps access to /cache |
Jerry Zhang | 9f152d9 | 2017-04-10 16:57:48 -0700 | [diff] [blame] | 86 | neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms }; |
| 87 | neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr }; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 88 | |
| 89 | # Do not allow untrusted apps to create/unlink files outside of its sandbox, |
| 90 | # internal storage or sdcard. |
| 91 | # World accessible data locations allow application to fill the device |
| 92 | # with unaccounted for data. This data will not get removed during |
| 93 | # application un-installation. |
Jerry Zhang | 9f152d9 | 2017-04-10 16:57:48 -0700 | [diff] [blame] | 94 | neverallow { all_untrusted_apps -mediaprovider } { |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 95 | fs_type |
Jeff Sharkey | 000cafc | 2018-03-30 12:22:54 -0600 | [diff] [blame] | 96 | -sdcard_type |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 97 | file_type |
| 98 | -app_data_file # The apps sandbox itself |
| 99 | -media_rw_data_file # Internal storage. Known that apps can |
| 100 | # leave artfacts here after uninstall. |
| 101 | -user_profile_data_file # Access to profile files |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 102 | userdebug_or_eng(` |
| 103 | -method_trace_data_file # only on ro.debuggable=1 |
| 104 | -coredump_file # userdebug/eng only |
| 105 | ') |
| 106 | }:dir_file_class_set { create unlink }; |
| 107 | |
Nick Kralevich | 45766d4 | 2017-04-26 11:40:48 -0700 | [diff] [blame] | 108 | # No untrusted component should be touching /dev/fuse |
| 109 | neverallow all_untrusted_apps fuse_device:chr_file *; |
| 110 | |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 111 | # Do not allow untrusted apps to directly open tun_device |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 112 | neverallow all_untrusted_apps tun_device:chr_file open; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 113 | |
| 114 | # Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553) |
Chad Brubaker | a782a81 | 2017-02-06 10:31:45 -0800 | [diff] [blame] | 115 | neverallow all_untrusted_apps anr_data_file:file ~{ open append }; |
| 116 | neverallow all_untrusted_apps anr_data_file:dir ~search; |
Chad Brubaker | 46e5a06 | 2017-01-27 15:53:38 -0800 | [diff] [blame] | 117 | |
| 118 | # Avoid reads from generically labeled /proc files |
| 119 | # Create a more specific label if needed |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 120 | neverallow all_untrusted_apps { |
| 121 | proc |
Tri Vo | 464f59a | 2017-10-06 10:20:53 -0700 | [diff] [blame] | 122 | proc_asound |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 123 | proc_filesystems |
| 124 | proc_kmsg |
| 125 | proc_loadavg |
| 126 | proc_mounts |
| 127 | proc_pagetypeinfo |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 128 | proc_stat |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 129 | proc_swaps |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 130 | proc_uptime |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 131 | proc_version |
| 132 | proc_vmallocinfo |
Jeff Vander Stoep | 886aa54 | 2018-03-28 15:34:37 -0700 | [diff] [blame] | 133 | proc_vmstat |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 134 | }:file { no_rw_file_perms no_x_file_perms }; |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 135 | |
Sandeep Patil | 2da9cfd | 2017-04-21 11:25:29 -0700 | [diff] [blame] | 136 | # Avoid all access to kernel configuration |
| 137 | neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms }; |
| 138 | |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 139 | # Do not allow untrusted apps access to preloads data files |
| 140 | neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms; |
Nick Kralevich | 92c44a5 | 2017-03-22 10:35:24 -0700 | [diff] [blame] | 141 | |
| 142 | # Locking of files on /system could lead to denial of service attacks |
| 143 | # against privileged system components |
| 144 | neverallow all_untrusted_apps system_file:file lock; |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 145 | |
Alex Klyubin | 5c5b626 | 2017-04-24 15:09:19 -0700 | [diff] [blame] | 146 | # Do not permit untrusted apps to perform actions on HwBinder service_manager |
| 147 | # other than find actions for services listed below |
| 148 | neverallow all_untrusted_apps *:hwservice_manager ~find; |
| 149 | |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 150 | # Do not permit access from apps which host arbitrary code to HwBinder services, |
| 151 | # except those considered sufficiently safe for access from such apps. |
| 152 | # The two main reasons for this are: |
| 153 | # 1. HwBinder servers do not perform client authentication because HIDL |
| 154 | # currently does not expose caller UID information and, even if it did, many |
| 155 | # HwBinder services either operate at a level below that of apps (e.g., HALs) |
| 156 | # or must not rely on app identity for authorization. Thus, to be safe, the |
| 157 | # default assumption is that every HwBinder service treats all its clients as |
| 158 | # equally authorized to perform operations offered by the service. |
| 159 | # 2. HAL servers (a subset of HwBinder services) contain code with higher |
| 160 | # incidence rate of security issues than system/core components and have |
| 161 | # access to lower layes of the stack (all the way down to hardware) thus |
| 162 | # increasing opportunities for bypassing the Android security model. |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 163 | # |
| 164 | # Safe services include: |
| 165 | # - same process services: because they by definition run in the process |
| 166 | # of the client and thus have the same access as the client domain in which |
| 167 | # the process runs |
| 168 | # - coredomain_hwservice: are considered safe because they do not pose risks |
| 169 | # associated with reason #2 above. |
| 170 | # - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been |
| 171 | # designed for use by any domain. |
| 172 | # - hal_graphics_allocator_hwservice: because these operations are also offered |
| 173 | # by surfaceflinger Binder service, which apps are permitted to access |
| 174 | # - hal_omx_hwservice: because this is a HwBinder version of the mediacodec |
| 175 | # Binder service which apps were permitted to access. |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 176 | neverallow all_untrusted_apps { |
| 177 | hwservice_manager_type |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 178 | -same_process_hwservice |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 179 | -coredomain_hwservice |
| 180 | -hal_configstore_ISurfaceFlingerConfigs |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 181 | -hal_graphics_allocator_hwservice |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 182 | -hal_omx_hwservice |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 183 | -hal_cas_hwservice |
Michael Butler | ea331aa | 2017-12-15 14:16:25 -0800 | [diff] [blame] | 184 | -hal_neuralnetworks_hwservice |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 185 | -untrusted_app_visible_hwservice |
| 186 | }:hwservice_manager find; |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 187 | |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 188 | # Make sure that the following services are never accessible by untrusted_apps |
| 189 | neverallow all_untrusted_apps { |
| 190 | default_android_hwservice |
| 191 | hal_audio_hwservice |
Andrew Scull | 64f35fa | 2018-01-10 16:11:46 +0000 | [diff] [blame] | 192 | hal_authsecret_hwservice |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 193 | hal_bluetooth_hwservice |
| 194 | hal_bootctl_hwservice |
| 195 | hal_camera_hwservice |
Janis Danisevskis | 97c56bd | 2018-01-09 17:42:53 -0500 | [diff] [blame] | 196 | hal_confirmationui_hwservice |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 197 | hal_contexthub_hwservice |
| 198 | hal_drm_hwservice |
| 199 | hal_dumpstate_hwservice |
| 200 | hal_fingerprint_hwservice |
| 201 | hal_gatekeeper_hwservice |
| 202 | hal_gnss_hwservice |
| 203 | hal_graphics_composer_hwservice |
| 204 | hal_health_hwservice |
| 205 | hal_ir_hwservice |
| 206 | hal_keymaster_hwservice |
| 207 | hal_light_hwservice |
| 208 | hal_memtrack_hwservice |
| 209 | hal_nfc_hwservice |
| 210 | hal_oemlock_hwservice |
| 211 | hal_power_hwservice |
Ruchi Kandoi | 8a2b4a7 | 2018-01-04 10:33:20 -0800 | [diff] [blame] | 212 | hal_secure_element_hwservice |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 213 | hal_sensors_hwservice |
| 214 | hal_telephony_hwservice |
| 215 | hal_thermal_hwservice |
| 216 | hal_tv_cec_hwservice |
| 217 | hal_tv_input_hwservice |
| 218 | hal_usb_hwservice |
| 219 | hal_vibrator_hwservice |
| 220 | hal_vr_hwservice |
| 221 | hal_weaver_hwservice |
| 222 | hal_wifi_hwservice |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 223 | hal_wifi_offload_hwservice |
Dan Cashman | 3e307a4 | 2017-06-21 10:00:32 -0700 | [diff] [blame] | 224 | hal_wifi_supplicant_hwservice |
| 225 | hidl_base_hwservice |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 226 | system_net_netd_hwservice |
| 227 | thermalcallback_hwservice |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 228 | }:hwservice_manager find; |
| 229 | # HwBinder services offered by core components (as opposed to vendor components) |
| 230 | # are considered somewhat safer due to point #2 above. |
| 231 | neverallow all_untrusted_apps { |
| 232 | coredomain_hwservice |
| 233 | -same_process_hwservice |
| 234 | -hidl_allocator_hwservice # Designed for use by any domain |
| 235 | -hidl_manager_hwservice # Designed for use by any domain |
| 236 | -hidl_memory_hwservice # Designed for use by any domain |
| 237 | -hidl_token_hwservice # Designed for use by any domain |
| 238 | }:hwservice_manager find; |
| 239 | |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 240 | # SELinux is not an API for untrusted apps to use |
| 241 | neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms; |
| 242 | |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 243 | # Restrict *Binder access from apps to HAL domains. We can only do this on full |
| 244 | # Treble devices where *Binder communications between apps and HALs are tightly |
| 245 | # restricted. |
| 246 | full_treble_only(` |
| 247 | neverallow all_untrusted_apps { |
| 248 | halserverdomain |
| 249 | -coredomain |
| 250 | -hal_configstore_server |
| 251 | -hal_graphics_allocator_server |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 252 | -hal_cas_server |
Michael Butler | ea331aa | 2017-12-15 14:16:25 -0800 | [diff] [blame] | 253 | -hal_neuralnetworks_server |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 254 | -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 255 | -untrusted_app_visible_halserver |
Alex Klyubin | 2a7f4fb | 2017-04-21 17:06:43 -0700 | [diff] [blame] | 256 | }:binder { call transfer }; |
| 257 | ') |
Dongwon Kang | 1134bd0 | 2017-11-06 11:19:07 -0800 | [diff] [blame] | 258 | |
| 259 | # Untrusted apps are not allowed to find mediaextractor update service. |
| 260 | neverallow all_untrusted_apps mediaextractor_update_service:service_manager find; |
Jeff Vander Stoep | 4d3ee1a | 2018-04-16 07:49:49 -0700 | [diff] [blame] | 261 | |
| 262 | # Untrusted apps are not allowed to use the signature|privileged|development |
| 263 | # android.permission.READ_LOGS permission, so they may not read dropbox files. |
| 264 | # Access to the the dropbox directory is covered by a neverallow for domain. |
| 265 | neverallow all_untrusted_apps dropbox_data_file:file *; |