blob: ae9f1728ae25c67fb27b5616e7e4918934ac88a0 [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;
Jeff Vander Stoep0ac2eec2019-02-04 10:07:15 -080023neverallow {all_untrusted_apps userdebug_or_eng(`-domain')} debugfs_type:{ file lnk_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
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080044# Shared libraries created by trusted components within an app home
45# directory can be dlopen()ed. To maintain the W^X property, these files
Nick Kralevich0eb0a162018-12-12 09:06:05 -080046# must never be writable to the app.
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080047neverallow all_untrusted_apps app_exec_data_file:file
Nick Kralevich0eb0a162018-12-12 09:06:05 -080048 { append create link relabelfrom relabelto rename setattr write };
49
Nick Kralevich65a89c12018-12-21 10:03:50 -080050# Block calling execve() on files in an apps home directory.
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070051# This is a W^X violation (loading executable code from a writable
52# home directory). For compatibility, allow for targetApi <= 28.
53# b/112357170
54neverallow {
55 all_untrusted_apps
56 -untrusted_app_25
57 -untrusted_app_27
Yabin Cuiffa2b612018-11-02 14:34:06 -070058 -runas_app
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070059} { app_data_file privapp_data_file }:file execute_no_trans;
60
David Brazdil535c5d22018-11-19 23:02:49 +000061# Do not allow untrusted apps to invoke dex2oat. This was historically required
62# by ART for compiling secondary dex files but has been removed in Q.
63# Exempt legacy apps (targetApi<=28) for compatibility.
64neverallow {
65 all_untrusted_apps
66 -untrusted_app_25
67 -untrusted_app_27
68} dex2oat_exec:file no_x_file_perms;
69
Chad Brubaker46e5a062017-01-27 15:53:38 -080070# Do not allow untrusted apps to be assigned mlstrustedsubject.
71# This would undermine the per-user isolation model being
72# enforced via levelFrom=user in seapp_contexts and the mls
73# constraints. As there is no direct way to specify a neverallow
74# on attribute assignment, this relies on the fact that fork
75# permission only makes sense within a domain (hence should
76# never be granted to any other domain within mlstrustedsubject)
77# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080078neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080079
80# Do not allow untrusted apps to hard link to any files.
81# In particular, if an untrusted app links to other app data
82# files, installd will not be able to guarantee the deletion
83# of the linked to file. Hard links also contribute to security
84# bugs, so we want to ensure untrusted apps never have this
85# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080086neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080087
88# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080089neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Maciej Żenczykowski804d99a2019-07-18 00:04:54 -070090neverallow all_untrusted_apps sysfs_net:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080091
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070092# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070093neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
94
95# Apps may never access the default sysfs label.
96neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070097
Chad Brubaker46e5a062017-01-27 15:53:38 -080098# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
99# ioctl permission, or 3. disallow the socket class.
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700100neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
Chad Brubakera782a812017-02-06 10:31:45 -0800101neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
102neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -0800103 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -0500104 netlink_tcpdiag_socket netlink_nflog_socket
105 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800106 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
107 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
108 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700109 netlink_rdma_socket netlink_crypto_socket sctp_socket
110 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
111 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
112 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
Nick Kralevicha194d372018-11-16 02:48:03 -0800113 alg_socket nfc_socket vsock_socket kcm_socket qipcrtr_socket smc_socket xdp_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800114} *;
115
116# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -0700117neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
118neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800119
120# Do not allow untrusted apps to create/unlink files outside of its sandbox,
121# internal storage or sdcard.
122# World accessible data locations allow application to fill the device
123# with unaccounted for data. This data will not get removed during
124# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -0700125neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -0800126 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600127 -sdcard_type
Chad Brubaker46e5a062017-01-27 15:53:38 -0800128 file_type
129 -app_data_file # The apps sandbox itself
Nick Kralevich23c9d912018-08-02 15:54:23 -0700130 -privapp_data_file
Nick Kralevichfb66c6f2019-01-11 09:37:46 -0800131 -app_exec_data_file # stored within the app sandbox directory
Chad Brubaker46e5a062017-01-27 15:53:38 -0800132 -media_rw_data_file # Internal storage. Known that apps can
133 # leave artfacts here after uninstall.
134 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800135 userdebug_or_eng(`
136 -method_trace_data_file # only on ro.debuggable=1
137 -coredump_file # userdebug/eng only
138 ')
139}:dir_file_class_set { create unlink };
140
Zimb56cc6f2019-08-07 19:00:15 +0100141# No untrusted component except mediaprovider should be touching /dev/fuse
142neverallow { all_untrusted_apps -mediaprovider } fuse_device:chr_file *;
Nick Kralevich45766d42017-04-26 11:40:48 -0700143
Nick Kralevich3b2df192018-11-15 06:14:07 -0800144# Do not allow untrusted apps to directly open the tun_device
145neverallow all_untrusted_apps tun_device:chr_file open;
146# The tun_device ioctls below are not allowed, to prove equivalence
147# to the kernel patch at
Nick Kralevich619c1ef2018-10-30 20:12:41 -0700148# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21
149neverallowxperm all_untrusted_apps tun_device:chr_file ioctl {
150 SIOCGIFHWADDR
151 SIOCSIFHWADDR
152 TUNATTACHFILTER
153 TUNDETACHFILTER
154 TUNGETFEATURES
155 TUNGETFILTER
156 TUNGETSNDBUF
157 TUNGETVNETHDRSZ
158 TUNSETDEBUG
159 TUNSETGROUP
160 TUNSETIFF
161 TUNSETLINK
162 TUNSETNOCSUM
163 TUNSETOFFLOAD
164 TUNSETOWNER
165 TUNSETPERSIST
166 TUNSETQUEUE
167 TUNSETSNDBUF
168 TUNSETTXFILTER
169 TUNSETVNETHDRSZ
170};
Chad Brubaker46e5a062017-01-27 15:53:38 -0800171
172# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800173neverallow all_untrusted_apps anr_data_file:file ~{ open append };
174neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800175
176# Avoid reads from generically labeled /proc files
177# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700178neverallow all_untrusted_apps {
179 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700180 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700181 proc_filesystems
182 proc_kmsg
183 proc_loadavg
184 proc_mounts
185 proc_pagetypeinfo
Mark Salyzynd6eaed82018-06-14 07:34:19 -0700186 proc_slabinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700187 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700188 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700189 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700190 proc_version
191 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700192 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700193}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700194
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700195# Avoid all access to kernel configuration
196neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
197
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700198# Do not allow untrusted apps access to preloads data files
199neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700200
201# Locking of files on /system could lead to denial of service attacks
202# against privileged system components
203neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700204
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700205# Do not permit untrusted apps to perform actions on HwBinder service_manager
206# other than find actions for services listed below
207neverallow all_untrusted_apps *:hwservice_manager ~find;
208
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700209# Do not permit access from apps which host arbitrary code to HwBinder services,
210# except those considered sufficiently safe for access from such apps.
211# The two main reasons for this are:
212# 1. HwBinder servers do not perform client authentication because HIDL
213# currently does not expose caller UID information and, even if it did, many
214# HwBinder services either operate at a level below that of apps (e.g., HALs)
215# or must not rely on app identity for authorization. Thus, to be safe, the
216# default assumption is that every HwBinder service treats all its clients as
217# equally authorized to perform operations offered by the service.
218# 2. HAL servers (a subset of HwBinder services) contain code with higher
219# incidence rate of security issues than system/core components and have
220# access to lower layes of the stack (all the way down to hardware) thus
221# increasing opportunities for bypassing the Android security model.
Dan Cashman3e307a42017-06-21 10:00:32 -0700222#
223# Safe services include:
224# - same process services: because they by definition run in the process
225# of the client and thus have the same access as the client domain in which
226# the process runs
227# - coredomain_hwservice: are considered safe because they do not pose risks
228# associated with reason #2 above.
229# - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been
230# designed for use by any domain.
231# - hal_graphics_allocator_hwservice: because these operations are also offered
232# by surfaceflinger Binder service, which apps are permitted to access
233# - hal_omx_hwservice: because this is a HwBinder version of the mediacodec
234# Binder service which apps were permitted to access.
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700235# - hal_codec2_hwservice: because this is a newer version of hal_omx_hwservice.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700236neverallow all_untrusted_apps {
237 hwservice_manager_type
Steven Moreland68b6f802019-04-29 13:10:37 -0700238 -fwk_bufferhub_hwservice
239 -hal_cas_hwservice
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700240 -hal_codec2_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700241 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700242 -hal_graphics_allocator_hwservice
Steven Moreland68b6f802019-04-29 13:10:37 -0700243 -hal_graphics_mapper_hwservice
Michael Butlerea331aa2017-12-15 14:16:25 -0800244 -hal_neuralnetworks_hwservice
Steven Moreland68b6f802019-04-29 13:10:37 -0700245 -hal_omx_hwservice
246 -hal_renderscript_hwservice
247 -hidl_allocator_hwservice
248 -hidl_manager_hwservice
249 -hidl_memory_hwservice
250 -hidl_token_hwservice
Tri Vo7f8b6cc2018-07-28 16:48:06 -0700251 -untrusted_app_visible_hwservice_violators
Dan Cashman3e307a42017-06-21 10:00:32 -0700252}:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700253
Dan Cashman91d398d2017-09-26 12:58:29 -0700254# SELinux is not an API for untrusted apps to use
255neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
256
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700257# Restrict *Binder access from apps to HAL domains. We can only do this on full
258# Treble devices where *Binder communications between apps and HALs are tightly
259# restricted.
260full_treble_only(`
261 neverallow all_untrusted_apps {
262 halserverdomain
263 -coredomain
264 -hal_configstore_server
265 -hal_graphics_allocator_server
Dan Cashman91d398d2017-09-26 12:58:29 -0700266 -hal_cas_server
Michael Butlerea331aa2017-12-15 14:16:25 -0800267 -hal_neuralnetworks_server
Steven Moreland7baf7252018-05-25 16:23:37 -0700268 -hal_omx_server
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700269 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
Tri Vo7f8b6cc2018-07-28 16:48:06 -0700270 -untrusted_app_visible_halserver_violators
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700271 }:binder { call transfer };
272')
Dongwon Kang1134bd02017-11-06 11:19:07 -0800273
274# Untrusted apps are not allowed to find mediaextractor update service.
275neverallow all_untrusted_apps mediaextractor_update_service:service_manager find;
Jeff Vander Stoepff511cb2018-09-07 07:39:28 -0700276
277# Access to /proc/tty/drivers, to allow apps to determine if they
278# are running in an emulated environment.
279# b/33214085 b/33814662 b/33791054 b/33211769
280# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java
281# This will go away in a future Android release
282neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms;
283neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms;
Tri Vof55c9892018-10-10 22:48:15 +0000284
285# Untrusted apps are not allowed to use cgroups.
286neverallow all_untrusted_apps cgroup:file *;
Tri Vo73d0a672019-01-27 13:39:19 -0800287
Tri Vo73d0a672019-01-27 13:39:19 -0800288# Untrusted apps targetting >= Q are not allowed to open /dev/ashmem directly.
Tri Vo8b12ff52019-02-12 14:14:30 -0800289# They must use ASharedMemory NDK API instead.
290neverallow {
291 all_untrusted_apps
Tri Vo19200ae2019-04-09 11:48:35 -0700292 -ephemeral_app
Tri Vo8b12ff52019-02-12 14:14:30 -0800293 -untrusted_app_25
294 -untrusted_app_27
295} ashmem_device:chr_file open;
Tri Vo8eff3e22019-04-11 15:23:24 -0700296
297# /mnt/sdcard symlink was supposed to have been removed in Gingerbread. Apps
298# must not use it.
299neverallow {
300 all_untrusted_apps
301 -untrusted_app_25
302 -untrusted_app_27
303} mnt_sdcard_file:lnk_file *;