blob: ab080c29029f9de861dfe2969c47fc0f7f233188 [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.
Chad Brubakera782a812017-02-06 10:31:45 -080022neverallow all_untrusted_apps debugfs_type:file read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080023
24# Do not allow untrusted apps to register services.
25# Only trusted components of Android should be registering
26# services.
Chad Brubakera782a812017-02-06 10:31:45 -080027neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080028
Alex Klyubin00657832017-04-25 09:27:54 -070029# Do not allow untrusted apps to use VendorBinder
30neverallow all_untrusted_apps vndbinder_device:chr_file *;
31neverallow all_untrusted_apps vndservice_manager_type:service_manager *;
32
Chad Brubaker46e5a062017-01-27 15:53:38 -080033# Do not allow untrusted apps to connect to the property service
34# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070035neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
36neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
37neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080038
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070039# net.dns properties are not a public API. Temporarily exempt pre-Oreo apps,
40# but otherwise disallow untrusted apps from reading this property.
41neverallow { all_untrusted_apps -untrusted_app_25 } net_dns_prop:file read;
42
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070043# Block calling execve() on files in an apps home directory.
44# This is a W^X violation (loading executable code from a writable
45# home directory). For compatibility, allow for targetApi <= 28.
46# b/112357170
47neverallow {
48 all_untrusted_apps
49 -untrusted_app_25
50 -untrusted_app_27
Yabin Cuiffa2b612018-11-02 14:34:06 -070051 -runas_app
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070052} { app_data_file privapp_data_file }:file execute_no_trans;
53
Chad Brubaker46e5a062017-01-27 15:53:38 -080054# Do not allow untrusted apps to be assigned mlstrustedsubject.
55# This would undermine the per-user isolation model being
56# enforced via levelFrom=user in seapp_contexts and the mls
57# constraints. As there is no direct way to specify a neverallow
58# on attribute assignment, this relies on the fact that fork
59# permission only makes sense within a domain (hence should
60# never be granted to any other domain within mlstrustedsubject)
61# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080062neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080063
64# Do not allow untrusted apps to hard link to any files.
65# In particular, if an untrusted app links to other app data
66# files, installd will not be able to guarantee the deletion
67# of the linked to file. Hard links also contribute to security
68# bugs, so we want to ensure untrusted apps never have this
69# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080070neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080071
72# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080073neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080074
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070075# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070076neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
77
78# Apps may never access the default sysfs label.
79neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070080
Chad Brubaker46e5a062017-01-27 15:53:38 -080081# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
82# ioctl permission, or 3. disallow the socket class.
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -070083neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
Chad Brubakera782a812017-02-06 10:31:45 -080084neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
85neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080086 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050087 netlink_tcpdiag_socket netlink_nflog_socket
88 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080089 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
90 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
91 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -070092 netlink_rdma_socket netlink_crypto_socket sctp_socket
93 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
94 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
95 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
96 alg_socket nfc_socket vsock_socket kcm_socket qipcrtr_socket smc_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080097} *;
98
99# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -0700100neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
101neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800102
103# Do not allow untrusted apps to create/unlink files outside of its sandbox,
104# internal storage or sdcard.
105# World accessible data locations allow application to fill the device
106# with unaccounted for data. This data will not get removed during
107# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -0700108neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -0800109 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600110 -sdcard_type
Chad Brubaker46e5a062017-01-27 15:53:38 -0800111 file_type
112 -app_data_file # The apps sandbox itself
Nick Kralevich23c9d912018-08-02 15:54:23 -0700113 -privapp_data_file
Chad Brubaker46e5a062017-01-27 15:53:38 -0800114 -media_rw_data_file # Internal storage. Known that apps can
115 # leave artfacts here after uninstall.
116 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800117 userdebug_or_eng(`
118 -method_trace_data_file # only on ro.debuggable=1
119 -coredump_file # userdebug/eng only
120 ')
121}:dir_file_class_set { create unlink };
122
Nick Kralevich45766d42017-04-26 11:40:48 -0700123# No untrusted component should be touching /dev/fuse
124neverallow all_untrusted_apps fuse_device:chr_file *;
125
Nick Kralevich619c1ef2018-10-30 20:12:41 -0700126# Do not allow untrusted apps to directly open or
127# issue ioctls to the tun_device
128neverallow all_untrusted_apps tun_device:chr_file { open ioctl };
129# Additionally, assert that the following ioctls are never reachable.
130# This should already be blocked by the neverallow rule above, but this
131# is added for robustness, and to prove equivalence to the kernel patch at
132# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21
133neverallowxperm all_untrusted_apps tun_device:chr_file ioctl {
134 SIOCGIFHWADDR
135 SIOCSIFHWADDR
136 TUNATTACHFILTER
137 TUNDETACHFILTER
138 TUNGETFEATURES
139 TUNGETFILTER
140 TUNGETSNDBUF
141 TUNGETVNETHDRSZ
142 TUNSETDEBUG
143 TUNSETGROUP
144 TUNSETIFF
145 TUNSETLINK
146 TUNSETNOCSUM
147 TUNSETOFFLOAD
148 TUNSETOWNER
149 TUNSETPERSIST
150 TUNSETQUEUE
151 TUNSETSNDBUF
152 TUNSETTXFILTER
153 TUNSETVNETHDRSZ
154};
Chad Brubaker46e5a062017-01-27 15:53:38 -0800155
156# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800157neverallow all_untrusted_apps anr_data_file:file ~{ open append };
158neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800159
160# Avoid reads from generically labeled /proc files
161# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700162neverallow all_untrusted_apps {
163 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700164 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700165 proc_filesystems
166 proc_kmsg
167 proc_loadavg
168 proc_mounts
169 proc_pagetypeinfo
Mark Salyzynd6eaed82018-06-14 07:34:19 -0700170 proc_slabinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700171 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700172 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700173 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700174 proc_version
175 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700176 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700177}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700178
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700179# Avoid all access to kernel configuration
180neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
181
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700182# Do not allow untrusted apps access to preloads data files
183neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700184
185# Locking of files on /system could lead to denial of service attacks
186# against privileged system components
187neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700188
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700189# Do not permit untrusted apps to perform actions on HwBinder service_manager
190# other than find actions for services listed below
191neverallow all_untrusted_apps *:hwservice_manager ~find;
192
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700193# Do not permit access from apps which host arbitrary code to HwBinder services,
194# except those considered sufficiently safe for access from such apps.
195# The two main reasons for this are:
196# 1. HwBinder servers do not perform client authentication because HIDL
197# currently does not expose caller UID information and, even if it did, many
198# HwBinder services either operate at a level below that of apps (e.g., HALs)
199# or must not rely on app identity for authorization. Thus, to be safe, the
200# default assumption is that every HwBinder service treats all its clients as
201# equally authorized to perform operations offered by the service.
202# 2. HAL servers (a subset of HwBinder services) contain code with higher
203# incidence rate of security issues than system/core components and have
204# access to lower layes of the stack (all the way down to hardware) thus
205# increasing opportunities for bypassing the Android security model.
Dan Cashman3e307a42017-06-21 10:00:32 -0700206#
207# Safe services include:
208# - same process services: because they by definition run in the process
209# of the client and thus have the same access as the client domain in which
210# the process runs
211# - coredomain_hwservice: are considered safe because they do not pose risks
212# associated with reason #2 above.
213# - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been
214# designed for use by any domain.
215# - hal_graphics_allocator_hwservice: because these operations are also offered
216# by surfaceflinger Binder service, which apps are permitted to access
217# - hal_omx_hwservice: because this is a HwBinder version of the mediacodec
218# Binder service which apps were permitted to access.
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700219# - hal_codec2_hwservice: because this is a newer version of hal_omx_hwservice.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700220neverallow all_untrusted_apps {
221 hwservice_manager_type
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700222 -same_process_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700223 -coredomain_hwservice
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700224 -hal_codec2_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700225 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700226 -hal_graphics_allocator_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700227 -hal_omx_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700228 -hal_cas_hwservice
Michael Butlerea331aa2017-12-15 14:16:25 -0800229 -hal_neuralnetworks_hwservice
Tri Vo7f8b6cc2018-07-28 16:48:06 -0700230 -untrusted_app_visible_hwservice_violators
Dan Cashman3e307a42017-06-21 10:00:32 -0700231}:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700232
Dan Cashman3e307a42017-06-21 10:00:32 -0700233# Make sure that the following services are never accessible by untrusted_apps
234neverallow all_untrusted_apps {
235 default_android_hwservice
Wei Wangbc71a612018-09-19 16:06:28 -0700236 hal_atrace_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700237 hal_audio_hwservice
Andrew Scull64f35fa2018-01-10 16:11:46 +0000238 hal_authsecret_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700239 hal_bluetooth_hwservice
240 hal_bootctl_hwservice
241 hal_camera_hwservice
Janis Danisevskis97c56bd2018-01-09 17:42:53 -0500242 hal_confirmationui_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700243 hal_contexthub_hwservice
244 hal_drm_hwservice
245 hal_dumpstate_hwservice
246 hal_fingerprint_hwservice
247 hal_gatekeeper_hwservice
248 hal_gnss_hwservice
249 hal_graphics_composer_hwservice
250 hal_health_hwservice
251 hal_ir_hwservice
252 hal_keymaster_hwservice
253 hal_light_hwservice
254 hal_memtrack_hwservice
255 hal_nfc_hwservice
256 hal_oemlock_hwservice
257 hal_power_hwservice
Ruchi Kandoi8a2b4a72018-01-04 10:33:20 -0800258 hal_secure_element_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700259 hal_sensors_hwservice
260 hal_telephony_hwservice
261 hal_thermal_hwservice
262 hal_tv_cec_hwservice
263 hal_tv_input_hwservice
264 hal_usb_hwservice
265 hal_vibrator_hwservice
266 hal_vr_hwservice
267 hal_weaver_hwservice
268 hal_wifi_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700269 hal_wifi_offload_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700270 hal_wifi_supplicant_hwservice
271 hidl_base_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700272 system_net_netd_hwservice
273 thermalcallback_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700274}:hwservice_manager find;
275# HwBinder services offered by core components (as opposed to vendor components)
276# are considered somewhat safer due to point #2 above.
277neverallow all_untrusted_apps {
278 coredomain_hwservice
279 -same_process_hwservice
280 -hidl_allocator_hwservice # Designed for use by any domain
281 -hidl_manager_hwservice # Designed for use by any domain
282 -hidl_memory_hwservice # Designed for use by any domain
283 -hidl_token_hwservice # Designed for use by any domain
284}:hwservice_manager find;
285
Dan Cashman91d398d2017-09-26 12:58:29 -0700286# SELinux is not an API for untrusted apps to use
287neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
288
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700289# Restrict *Binder access from apps to HAL domains. We can only do this on full
290# Treble devices where *Binder communications between apps and HALs are tightly
291# restricted.
292full_treble_only(`
293 neverallow all_untrusted_apps {
294 halserverdomain
295 -coredomain
296 -hal_configstore_server
297 -hal_graphics_allocator_server
Dan Cashman91d398d2017-09-26 12:58:29 -0700298 -hal_cas_server
Michael Butlerea331aa2017-12-15 14:16:25 -0800299 -hal_neuralnetworks_server
Steven Moreland7baf7252018-05-25 16:23:37 -0700300 -hal_omx_server
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700301 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
Tri Vo7f8b6cc2018-07-28 16:48:06 -0700302 -untrusted_app_visible_halserver_violators
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700303 }:binder { call transfer };
304')
Dongwon Kang1134bd02017-11-06 11:19:07 -0800305
306# Untrusted apps are not allowed to find mediaextractor update service.
307neverallow all_untrusted_apps mediaextractor_update_service:service_manager find;
Jeff Vander Stoepff511cb2018-09-07 07:39:28 -0700308
309# Access to /proc/tty/drivers, to allow apps to determine if they
310# are running in an emulated environment.
311# b/33214085 b/33814662 b/33791054 b/33211769
312# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java
313# This will go away in a future Android release
314neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms;
315neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms;
Tri Vof55c9892018-10-10 22:48:15 +0000316
317# Untrusted apps are not allowed to use cgroups.
318neverallow all_untrusted_apps cgroup:file *;