blob: 16ae1a074d59c5eaf3b0c177b3c0eaeaddb3caf6 [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
Nick Kralevichdb5962c2017-04-26 16:14:40 -070013}')
Chad Brubaker46e5a062017-01-27 15:53:38 -080014# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080015neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080016
17# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080018neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080019
20# Too much leaky information in debugfs. It's a security
21# best practice to ensure these files aren't readable.
Dan Austin55d90962018-11-29 10:37:18 -080022neverallow all_untrusted_apps { debugfs_type -debugfs_kcov }:file read;
23neverallow {all_untrusted_apps userdebug_or_eng(`-domain')} 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
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070044# Block calling execve() on files in an apps home directory.
45# This is a W^X violation (loading executable code from a writable
46# home directory). For compatibility, allow for targetApi <= 28.
47# b/112357170
48neverallow {
49 all_untrusted_apps
50 -untrusted_app_25
51 -untrusted_app_27
Yabin Cuiffa2b612018-11-02 14:34:06 -070052 -runas_app
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070053} { app_data_file privapp_data_file }:file execute_no_trans;
54
David Brazdil535c5d22018-11-19 23:02:49 +000055# Do not allow untrusted apps to invoke dex2oat. This was historically required
56# by ART for compiling secondary dex files but has been removed in Q.
57# Exempt legacy apps (targetApi<=28) for compatibility.
58neverallow {
59 all_untrusted_apps
60 -untrusted_app_25
61 -untrusted_app_27
62} dex2oat_exec:file no_x_file_perms;
63
Chad Brubaker46e5a062017-01-27 15:53:38 -080064# Do not allow untrusted apps to be assigned mlstrustedsubject.
65# This would undermine the per-user isolation model being
66# enforced via levelFrom=user in seapp_contexts and the mls
67# constraints. As there is no direct way to specify a neverallow
68# on attribute assignment, this relies on the fact that fork
69# permission only makes sense within a domain (hence should
70# never be granted to any other domain within mlstrustedsubject)
71# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080072neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080073
74# Do not allow untrusted apps to hard link to any files.
75# In particular, if an untrusted app links to other app data
76# files, installd will not be able to guarantee the deletion
77# of the linked to file. Hard links also contribute to security
78# bugs, so we want to ensure untrusted apps never have this
79# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080080neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080081
82# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080083neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080084
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070085# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070086neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
87
88# Apps may never access the default sysfs label.
89neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070090
Chad Brubaker46e5a062017-01-27 15:53:38 -080091# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
92# ioctl permission, or 3. disallow the socket class.
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -070093neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
Chad Brubakera782a812017-02-06 10:31:45 -080094neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
95neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080096 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050097 netlink_tcpdiag_socket netlink_nflog_socket
98 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080099 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
100 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
101 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700102 netlink_rdma_socket netlink_crypto_socket sctp_socket
103 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
104 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
105 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
Nick Kralevicha194d372018-11-16 02:48:03 -0800106 alg_socket nfc_socket vsock_socket kcm_socket qipcrtr_socket smc_socket xdp_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800107} *;
108
109# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -0700110neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
111neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800112
113# Do not allow untrusted apps to create/unlink files outside of its sandbox,
114# internal storage or sdcard.
115# World accessible data locations allow application to fill the device
116# with unaccounted for data. This data will not get removed during
117# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -0700118neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -0800119 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600120 -sdcard_type
Chad Brubaker46e5a062017-01-27 15:53:38 -0800121 file_type
122 -app_data_file # The apps sandbox itself
Nick Kralevich23c9d912018-08-02 15:54:23 -0700123 -privapp_data_file
Chad Brubaker46e5a062017-01-27 15:53:38 -0800124 -media_rw_data_file # Internal storage. Known that apps can
125 # leave artfacts here after uninstall.
126 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800127 userdebug_or_eng(`
128 -method_trace_data_file # only on ro.debuggable=1
129 -coredump_file # userdebug/eng only
130 ')
131}:dir_file_class_set { create unlink };
132
Nick Kralevich45766d42017-04-26 11:40:48 -0700133# No untrusted component should be touching /dev/fuse
134neverallow all_untrusted_apps fuse_device:chr_file *;
135
Nick Kralevich3b2df192018-11-15 06:14:07 -0800136# Do not allow untrusted apps to directly open the tun_device
137neverallow all_untrusted_apps tun_device:chr_file open;
138# The tun_device ioctls below are not allowed, to prove equivalence
139# to the kernel patch at
Nick Kralevich619c1ef2018-10-30 20:12:41 -0700140# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21
141neverallowxperm all_untrusted_apps tun_device:chr_file ioctl {
142 SIOCGIFHWADDR
143 SIOCSIFHWADDR
144 TUNATTACHFILTER
145 TUNDETACHFILTER
146 TUNGETFEATURES
147 TUNGETFILTER
148 TUNGETSNDBUF
149 TUNGETVNETHDRSZ
150 TUNSETDEBUG
151 TUNSETGROUP
152 TUNSETIFF
153 TUNSETLINK
154 TUNSETNOCSUM
155 TUNSETOFFLOAD
156 TUNSETOWNER
157 TUNSETPERSIST
158 TUNSETQUEUE
159 TUNSETSNDBUF
160 TUNSETTXFILTER
161 TUNSETVNETHDRSZ
162};
Chad Brubaker46e5a062017-01-27 15:53:38 -0800163
164# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800165neverallow all_untrusted_apps anr_data_file:file ~{ open append };
166neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800167
168# Avoid reads from generically labeled /proc files
169# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700170neverallow all_untrusted_apps {
171 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700172 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700173 proc_filesystems
174 proc_kmsg
175 proc_loadavg
176 proc_mounts
177 proc_pagetypeinfo
Mark Salyzynd6eaed82018-06-14 07:34:19 -0700178 proc_slabinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700179 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700180 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700181 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700182 proc_version
183 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700184 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700185}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700186
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700187# Avoid all access to kernel configuration
188neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
189
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700190# Do not allow untrusted apps access to preloads data files
191neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700192
193# Locking of files on /system could lead to denial of service attacks
194# against privileged system components
195neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700196
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700197# Do not permit untrusted apps to perform actions on HwBinder service_manager
198# other than find actions for services listed below
199neverallow all_untrusted_apps *:hwservice_manager ~find;
200
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700201# Do not permit access from apps which host arbitrary code to HwBinder services,
202# except those considered sufficiently safe for access from such apps.
203# The two main reasons for this are:
204# 1. HwBinder servers do not perform client authentication because HIDL
205# currently does not expose caller UID information and, even if it did, many
206# HwBinder services either operate at a level below that of apps (e.g., HALs)
207# or must not rely on app identity for authorization. Thus, to be safe, the
208# default assumption is that every HwBinder service treats all its clients as
209# equally authorized to perform operations offered by the service.
210# 2. HAL servers (a subset of HwBinder services) contain code with higher
211# incidence rate of security issues than system/core components and have
212# access to lower layes of the stack (all the way down to hardware) thus
213# increasing opportunities for bypassing the Android security model.
Dan Cashman3e307a42017-06-21 10:00:32 -0700214#
215# Safe services include:
216# - same process services: because they by definition run in the process
217# of the client and thus have the same access as the client domain in which
218# the process runs
219# - coredomain_hwservice: are considered safe because they do not pose risks
220# associated with reason #2 above.
221# - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been
222# designed for use by any domain.
223# - hal_graphics_allocator_hwservice: because these operations are also offered
224# by surfaceflinger Binder service, which apps are permitted to access
225# - hal_omx_hwservice: because this is a HwBinder version of the mediacodec
226# Binder service which apps were permitted to access.
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700227# - hal_codec2_hwservice: because this is a newer version of hal_omx_hwservice.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700228neverallow all_untrusted_apps {
229 hwservice_manager_type
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700230 -same_process_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700231 -coredomain_hwservice
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700232 -hal_codec2_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700233 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700234 -hal_graphics_allocator_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700235 -hal_omx_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700236 -hal_cas_hwservice
Michael Butlerea331aa2017-12-15 14:16:25 -0800237 -hal_neuralnetworks_hwservice
Tri Vo7f8b6cc2018-07-28 16:48:06 -0700238 -untrusted_app_visible_hwservice_violators
Dan Cashman3e307a42017-06-21 10:00:32 -0700239}:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700240
Dan Cashman3e307a42017-06-21 10:00:32 -0700241# Make sure that the following services are never accessible by untrusted_apps
242neverallow all_untrusted_apps {
243 default_android_hwservice
Wei Wangbc71a612018-09-19 16:06:28 -0700244 hal_atrace_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700245 hal_audio_hwservice
Andrew Scull64f35fa2018-01-10 16:11:46 +0000246 hal_authsecret_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700247 hal_bluetooth_hwservice
248 hal_bootctl_hwservice
249 hal_camera_hwservice
Janis Danisevskis97c56bd2018-01-09 17:42:53 -0500250 hal_confirmationui_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700251 hal_contexthub_hwservice
252 hal_drm_hwservice
253 hal_dumpstate_hwservice
254 hal_fingerprint_hwservice
255 hal_gatekeeper_hwservice
256 hal_gnss_hwservice
257 hal_graphics_composer_hwservice
258 hal_health_hwservice
259 hal_ir_hwservice
260 hal_keymaster_hwservice
261 hal_light_hwservice
262 hal_memtrack_hwservice
263 hal_nfc_hwservice
264 hal_oemlock_hwservice
265 hal_power_hwservice
Ruchi Kandoi8a2b4a72018-01-04 10:33:20 -0800266 hal_secure_element_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700267 hal_sensors_hwservice
268 hal_telephony_hwservice
269 hal_thermal_hwservice
270 hal_tv_cec_hwservice
271 hal_tv_input_hwservice
272 hal_usb_hwservice
273 hal_vibrator_hwservice
274 hal_vr_hwservice
275 hal_weaver_hwservice
276 hal_wifi_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700277 hal_wifi_offload_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700278 hal_wifi_supplicant_hwservice
279 hidl_base_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700280 system_net_netd_hwservice
281 thermalcallback_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700282}:hwservice_manager find;
283# HwBinder services offered by core components (as opposed to vendor components)
284# are considered somewhat safer due to point #2 above.
285neverallow all_untrusted_apps {
286 coredomain_hwservice
287 -same_process_hwservice
288 -hidl_allocator_hwservice # Designed for use by any domain
289 -hidl_manager_hwservice # Designed for use by any domain
290 -hidl_memory_hwservice # Designed for use by any domain
291 -hidl_token_hwservice # Designed for use by any domain
292}:hwservice_manager find;
293
Dan Cashman91d398d2017-09-26 12:58:29 -0700294# SELinux is not an API for untrusted apps to use
295neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
296
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700297# Restrict *Binder access from apps to HAL domains. We can only do this on full
298# Treble devices where *Binder communications between apps and HALs are tightly
299# restricted.
300full_treble_only(`
301 neverallow all_untrusted_apps {
302 halserverdomain
303 -coredomain
304 -hal_configstore_server
305 -hal_graphics_allocator_server
Dan Cashman91d398d2017-09-26 12:58:29 -0700306 -hal_cas_server
Michael Butlerea331aa2017-12-15 14:16:25 -0800307 -hal_neuralnetworks_server
Steven Moreland7baf7252018-05-25 16:23:37 -0700308 -hal_omx_server
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700309 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
Tri Vo7f8b6cc2018-07-28 16:48:06 -0700310 -untrusted_app_visible_halserver_violators
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700311 }:binder { call transfer };
312')
Dongwon Kang1134bd02017-11-06 11:19:07 -0800313
314# Untrusted apps are not allowed to find mediaextractor update service.
315neverallow all_untrusted_apps mediaextractor_update_service:service_manager find;
Jeff Vander Stoepff511cb2018-09-07 07:39:28 -0700316
317# Access to /proc/tty/drivers, to allow apps to determine if they
318# are running in an emulated environment.
319# b/33214085 b/33814662 b/33791054 b/33211769
320# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java
321# This will go away in a future Android release
322neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms;
323neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms;
Tri Vof55c9892018-10-10 22:48:15 +0000324
325# Untrusted apps are not allowed to use cgroups.
326neverallow all_untrusted_apps cgroup:file *;