blob: 5572f5418a381d5646386b7c7a0790a263925a13 [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 Stoep28903d92019-10-15 21:00:22 +020040# net.dns properties are not a public API. Disallow untrusted apps from reading this property.
41neverallow { all_untrusted_apps } net_dns_prop:file read;
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070042
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080043# Shared libraries created by trusted components within an app home
44# directory can be dlopen()ed. To maintain the W^X property, these files
Nick Kralevich0eb0a162018-12-12 09:06:05 -080045# must never be writable to the app.
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080046neverallow all_untrusted_apps app_exec_data_file:file
Nick Kralevich0eb0a162018-12-12 09:06:05 -080047 { append create link relabelfrom relabelto rename setattr write };
48
Nick Kralevich65a89c12018-12-21 10:03:50 -080049# Block calling execve() on files in an apps home directory.
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070050# This is a W^X violation (loading executable code from a writable
51# home directory). For compatibility, allow for targetApi <= 28.
52# b/112357170
53neverallow {
54 all_untrusted_apps
55 -untrusted_app_25
56 -untrusted_app_27
Yabin Cuiffa2b612018-11-02 14:34:06 -070057 -runas_app
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070058} { app_data_file privapp_data_file }:file execute_no_trans;
59
David Brazdil535c5d22018-11-19 23:02:49 +000060# Do not allow untrusted apps to invoke dex2oat. This was historically required
61# by ART for compiling secondary dex files but has been removed in Q.
62# Exempt legacy apps (targetApi<=28) for compatibility.
63neverallow {
64 all_untrusted_apps
65 -untrusted_app_25
66 -untrusted_app_27
67} dex2oat_exec:file no_x_file_perms;
68
Chad Brubaker46e5a062017-01-27 15:53:38 -080069# Do not allow untrusted apps to be assigned mlstrustedsubject.
70# This would undermine the per-user isolation model being
71# enforced via levelFrom=user in seapp_contexts and the mls
72# constraints. As there is no direct way to specify a neverallow
73# on attribute assignment, this relies on the fact that fork
74# permission only makes sense within a domain (hence should
75# never be granted to any other domain within mlstrustedsubject)
76# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080077neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080078
79# Do not allow untrusted apps to hard link to any files.
80# In particular, if an untrusted app links to other app data
81# files, installd will not be able to guarantee the deletion
82# of the linked to file. Hard links also contribute to security
83# bugs, so we want to ensure untrusted apps never have this
84# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080085neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080086
87# Do not allow untrusted apps to access network MAC address file
Maciej Żenczykowski804d99a2019-07-18 00:04:54 -070088neverallow all_untrusted_apps sysfs_net:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080089
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070090# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070091neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
92
93# Apps may never access the default sysfs label.
94neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070095
Chad Brubaker46e5a062017-01-27 15:53:38 -080096# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
97# ioctl permission, or 3. disallow the socket class.
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -070098neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
Chad Brubakera782a812017-02-06 10:31:45 -080099neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
100neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -0800101 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -0500102 netlink_tcpdiag_socket netlink_nflog_socket
103 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800104 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
105 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
106 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700107 netlink_rdma_socket netlink_crypto_socket sctp_socket
108 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
109 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
110 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
Nick Kralevicha194d372018-11-16 02:48:03 -0800111 alg_socket nfc_socket vsock_socket kcm_socket qipcrtr_socket smc_socket xdp_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800112} *;
113
114# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -0700115neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
116neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800117
118# Do not allow untrusted apps to create/unlink files outside of its sandbox,
119# internal storage or sdcard.
120# World accessible data locations allow application to fill the device
121# with unaccounted for data. This data will not get removed during
122# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -0700123neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -0800124 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600125 -sdcard_type
Chad Brubaker46e5a062017-01-27 15:53:38 -0800126 file_type
127 -app_data_file # The apps sandbox itself
Nick Kralevich23c9d912018-08-02 15:54:23 -0700128 -privapp_data_file
Nick Kralevichfb66c6f2019-01-11 09:37:46 -0800129 -app_exec_data_file # stored within the app sandbox directory
Chad Brubaker46e5a062017-01-27 15:53:38 -0800130 -media_rw_data_file # Internal storage. Known that apps can
131 # leave artfacts here after uninstall.
132 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800133 userdebug_or_eng(`
134 -method_trace_data_file # only on ro.debuggable=1
135 -coredump_file # userdebug/eng only
136 ')
137}:dir_file_class_set { create unlink };
138
Zimb56cc6f2019-08-07 19:00:15 +0100139# No untrusted component except mediaprovider should be touching /dev/fuse
140neverallow { all_untrusted_apps -mediaprovider } fuse_device:chr_file *;
Nick Kralevich45766d42017-04-26 11:40:48 -0700141
Nick Kralevich3b2df192018-11-15 06:14:07 -0800142# Do not allow untrusted apps to directly open the tun_device
143neverallow all_untrusted_apps tun_device:chr_file open;
144# The tun_device ioctls below are not allowed, to prove equivalence
145# to the kernel patch at
Nick Kralevich619c1ef2018-10-30 20:12:41 -0700146# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21
147neverallowxperm all_untrusted_apps tun_device:chr_file ioctl {
148 SIOCGIFHWADDR
149 SIOCSIFHWADDR
150 TUNATTACHFILTER
151 TUNDETACHFILTER
152 TUNGETFEATURES
153 TUNGETFILTER
154 TUNGETSNDBUF
155 TUNGETVNETHDRSZ
156 TUNSETDEBUG
157 TUNSETGROUP
158 TUNSETIFF
159 TUNSETLINK
160 TUNSETNOCSUM
161 TUNSETOFFLOAD
162 TUNSETOWNER
163 TUNSETPERSIST
164 TUNSETQUEUE
165 TUNSETSNDBUF
166 TUNSETTXFILTER
167 TUNSETVNETHDRSZ
168};
Chad Brubaker46e5a062017-01-27 15:53:38 -0800169
170# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800171neverallow all_untrusted_apps anr_data_file:file ~{ open append };
172neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800173
174# Avoid reads from generically labeled /proc files
175# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700176neverallow all_untrusted_apps {
177 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700178 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700179 proc_filesystems
180 proc_kmsg
181 proc_loadavg
182 proc_mounts
183 proc_pagetypeinfo
Mark Salyzynd6eaed82018-06-14 07:34:19 -0700184 proc_slabinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700185 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700186 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700187 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700188 proc_version
189 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700190 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700191}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700192
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700193# Avoid all access to kernel configuration
194neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
195
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700196# Do not allow untrusted apps access to preloads data files
197neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700198
199# Locking of files on /system could lead to denial of service attacks
200# against privileged system components
201neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700202
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700203# Do not permit untrusted apps to perform actions on HwBinder service_manager
204# other than find actions for services listed below
205neverallow all_untrusted_apps *:hwservice_manager ~find;
206
Jiyong Parke95c7042019-08-22 00:04:50 +0900207# Do not permit access from apps which host arbitrary code to the protected HwBinder
208# services.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700209# The two main reasons for this are:
Jiyong Parke95c7042019-08-22 00:04:50 +0900210# 1. Protected HwBinder servers do not perform client authentication because HIDL
211# currently does not expose caller UID information and, even if it did, those
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700212# HwBinder services either operate at a level below that of apps (e.g., HALs)
213# or must not rely on app identity for authorization. Thus, to be safe, the
214# default assumption is that every HwBinder service treats all its clients as
215# equally authorized to perform operations offered by the service.
216# 2. HAL servers (a subset of HwBinder services) contain code with higher
217# incidence rate of security issues than system/core components and have
218# access to lower layes of the stack (all the way down to hardware) thus
219# increasing opportunities for bypassing the Android security model.
Jiyong Parke95c7042019-08-22 00:04:50 +0900220neverallow all_untrusted_apps protected_hwservice:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700221
Steven Morelandb75b0472019-08-20 22:42:58 +0000222neverallow all_untrusted_apps {
223 vendor_service
Steven Morelandb75b0472019-08-20 22:42:58 +0000224}:service_manager find;
225
Dan Cashman91d398d2017-09-26 12:58:29 -0700226# SELinux is not an API for untrusted apps to use
227neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
228
Jeff Vander Stoepff511cb2018-09-07 07:39:28 -0700229# Access to /proc/tty/drivers, to allow apps to determine if they
230# are running in an emulated environment.
231# b/33214085 b/33814662 b/33791054 b/33211769
232# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java
233# This will go away in a future Android release
234neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms;
235neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms;
Tri Vof55c9892018-10-10 22:48:15 +0000236
237# Untrusted apps are not allowed to use cgroups.
238neverallow all_untrusted_apps cgroup:file *;
Tri Vo73d0a672019-01-27 13:39:19 -0800239
Tri Vo73d0a672019-01-27 13:39:19 -0800240# Untrusted apps targetting >= Q are not allowed to open /dev/ashmem directly.
Tri Vo8b12ff52019-02-12 14:14:30 -0800241# They must use ASharedMemory NDK API instead.
242neverallow {
243 all_untrusted_apps
Tri Vo19200ae2019-04-09 11:48:35 -0700244 -ephemeral_app
Tri Vo8b12ff52019-02-12 14:14:30 -0800245 -untrusted_app_25
246 -untrusted_app_27
247} ashmem_device:chr_file open;
Tri Vo8eff3e22019-04-11 15:23:24 -0700248
249# /mnt/sdcard symlink was supposed to have been removed in Gingerbread. Apps
250# must not use it.
251neverallow {
252 all_untrusted_apps
253 -untrusted_app_25
254 -untrusted_app_27
255} mnt_sdcard_file:lnk_file *;