blob: ca18c0396cc606235005e48f19ede76712673ba5 [file] [log] [blame]
Chad Brubaker46e5a062017-01-27 15:53:38 -08001###
2### neverallow rules for untrusted app domains
3###
4
Nick Kralevichdb5962c2017-04-26 16:14:40 -07005define(`all_untrusted_apps',`{
6 ephemeral_app
7 isolated_app
8 mediaprovider
9 untrusted_app
10 untrusted_app_25
Jeff Vander Stoep3aa7ca52018-04-03 11:22:38 -070011 untrusted_app_27
Nick Kralevichdb5962c2017-04-26 16:14:40 -070012 untrusted_app_all
13 untrusted_v2_app
14}')
Chad Brubaker46e5a062017-01-27 15:53:38 -080015# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080016neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080017
18# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080019neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080020
21# Too much leaky information in debugfs. It's a security
22# best practice to ensure these files aren't readable.
Chad Brubakera782a812017-02-06 10:31:45 -080023neverallow all_untrusted_apps debugfs_type:file read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080024
25# Do not allow untrusted apps to register services.
26# Only trusted components of Android should be registering
27# services.
Chad Brubakera782a812017-02-06 10:31:45 -080028neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080029
Alex Klyubin00657832017-04-25 09:27:54 -070030# Do not allow untrusted apps to use VendorBinder
31neverallow all_untrusted_apps vndbinder_device:chr_file *;
32neverallow all_untrusted_apps vndservice_manager_type:service_manager *;
33
Chad Brubaker46e5a062017-01-27 15:53:38 -080034# Do not allow untrusted apps to connect to the property service
35# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070036neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
37neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
38neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080039
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070040# net.dns properties are not a public API. Temporarily exempt pre-Oreo apps,
41# but otherwise disallow untrusted apps from reading this property.
42neverallow { all_untrusted_apps -untrusted_app_25 } net_dns_prop:file read;
43
Chad Brubaker46e5a062017-01-27 15:53:38 -080044# 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 Brubakera782a812017-02-06 10:31:45 -080052neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080053
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 Brubakera782a812017-02-06 10:31:45 -080060neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080061
62# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080063neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080064
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070065# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070066neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
67
68# Apps may never access the default sysfs label.
69neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070070
Chad Brubaker46e5a062017-01-27 15:53:38 -080071# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
72# ioctl permission, or 3. disallow the socket class.
Chad Brubakera782a812017-02-06 10:31:45 -080073neverallowxperm all_untrusted_apps domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
74neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
75neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080076 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050077 netlink_tcpdiag_socket netlink_nflog_socket
78 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080079 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 Zhang9f152d92017-04-10 16:57:48 -070086neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
87neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -080088
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 Zhang9f152d92017-04-10 16:57:48 -070094neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -080095 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -060096 -sdcard_type
Chad Brubaker46e5a062017-01-27 15:53:38 -080097 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 Brubaker46e5a062017-01-27 15:53:38 -0800102 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 Kralevich45766d42017-04-26 11:40:48 -0700108# No untrusted component should be touching /dev/fuse
109neverallow all_untrusted_apps fuse_device:chr_file *;
110
Chad Brubaker46e5a062017-01-27 15:53:38 -0800111# Do not allow untrusted apps to directly open tun_device
Chad Brubakera782a812017-02-06 10:31:45 -0800112neverallow all_untrusted_apps tun_device:chr_file open;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800113
114# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800115neverallow all_untrusted_apps anr_data_file:file ~{ open append };
116neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800117
118# Avoid reads from generically labeled /proc files
119# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700120neverallow all_untrusted_apps {
121 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700122 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700123 proc_filesystems
124 proc_kmsg
125 proc_loadavg
126 proc_mounts
127 proc_pagetypeinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700128 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700129 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700130 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700131 proc_version
132 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700133 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700134}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700135
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700136# Avoid all access to kernel configuration
137neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
138
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700139# Do not allow untrusted apps access to preloads data files
140neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700141
142# Locking of files on /system could lead to denial of service attacks
143# against privileged system components
144neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700145
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700146# Do not permit untrusted apps to perform actions on HwBinder service_manager
147# other than find actions for services listed below
148neverallow all_untrusted_apps *:hwservice_manager ~find;
149
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700150# 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 Cashman3e307a42017-06-21 10:00:32 -0700163#
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 Klyubin2a7f4fb2017-04-21 17:06:43 -0700176neverallow all_untrusted_apps {
177 hwservice_manager_type
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700178 -same_process_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700179 -coredomain_hwservice
180 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700181 -hal_graphics_allocator_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700182 -hal_omx_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700183 -hal_cas_hwservice
Michael Butlerea331aa2017-12-15 14:16:25 -0800184 -hal_neuralnetworks_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700185 -untrusted_app_visible_hwservice
186}:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700187
Dan Cashman3e307a42017-06-21 10:00:32 -0700188# Make sure that the following services are never accessible by untrusted_apps
189neverallow all_untrusted_apps {
190 default_android_hwservice
191 hal_audio_hwservice
Andrew Scull64f35fa2018-01-10 16:11:46 +0000192 hal_authsecret_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700193 hal_bluetooth_hwservice
194 hal_bootctl_hwservice
195 hal_camera_hwservice
Janis Danisevskis97c56bd2018-01-09 17:42:53 -0500196 hal_confirmationui_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700197 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 Kandoi8a2b4a72018-01-04 10:33:20 -0800212 hal_secure_element_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700213 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 Cashman91d398d2017-09-26 12:58:29 -0700223 hal_wifi_offload_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700224 hal_wifi_supplicant_hwservice
225 hidl_base_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700226 system_net_netd_hwservice
227 thermalcallback_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700228}: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.
231neverallow 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 Cashman91d398d2017-09-26 12:58:29 -0700240# SELinux is not an API for untrusted apps to use
241neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
242
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700243# 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.
246full_treble_only(`
247 neverallow all_untrusted_apps {
248 halserverdomain
249 -coredomain
250 -hal_configstore_server
251 -hal_graphics_allocator_server
Dan Cashman91d398d2017-09-26 12:58:29 -0700252 -hal_cas_server
Michael Butlerea331aa2017-12-15 14:16:25 -0800253 -hal_neuralnetworks_server
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700254 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
Dan Cashman91d398d2017-09-26 12:58:29 -0700255 -untrusted_app_visible_halserver
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700256 }:binder { call transfer };
257')
Dongwon Kang1134bd02017-11-06 11:19:07 -0800258
259# Untrusted apps are not allowed to find mediaextractor update service.
260neverallow all_untrusted_apps mediaextractor_update_service:service_manager find;
Jeff Vander Stoep4d3ee1a2018-04-16 07:49:49 -0700261
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.
265neverallow all_untrusted_apps dropbox_data_file:file *;