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