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