blob: 12357c79d6c8c5a0959c4ef789e4068cb38fc58a [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
Martijn Coenene3f1d5a2020-01-30 16:52:45 +01009 mediaprovider_app
Nick Kralevichdb5962c2017-04-26 16:14:40 -070010 untrusted_app
11 untrusted_app_25
Jeff Vander Stoep3aa7ca52018-04-03 11:22:38 -070012 untrusted_app_27
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +010013 untrusted_app_29
Nick Kralevichdb5962c2017-04-26 16:14:40 -070014 untrusted_app_all
Nick Kralevichdb5962c2017-04-26 16:14:40 -070015}')
Chad Brubaker46e5a062017-01-27 15:53:38 -080016# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080017neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080018
19# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080020neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080021
22# Too much leaky information in debugfs. It's a security
23# best practice to ensure these files aren't readable.
Dan Austin55d90962018-11-29 10:37:18 -080024neverallow all_untrusted_apps { debugfs_type -debugfs_kcov }:file read;
Jeff Vander Stoep0ac2eec2019-02-04 10:07:15 -080025neverallow {all_untrusted_apps userdebug_or_eng(`-domain')} debugfs_type:{ file lnk_file } read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080026
27# Do not allow untrusted apps to register services.
28# Only trusted components of Android should be registering
29# services.
Chad Brubakera782a812017-02-06 10:31:45 -080030neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080031
Alex Klyubin00657832017-04-25 09:27:54 -070032# Do not allow untrusted apps to use VendorBinder
33neverallow all_untrusted_apps vndbinder_device:chr_file *;
34neverallow all_untrusted_apps vndservice_manager_type:service_manager *;
35
Chad Brubaker46e5a062017-01-27 15:53:38 -080036# Do not allow untrusted apps to connect to the property service
37# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070038neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
39neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
40neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080041
Jeff Vander Stoep28903d92019-10-15 21:00:22 +020042# net.dns properties are not a public API. Disallow untrusted apps from reading this property.
43neverallow { all_untrusted_apps } net_dns_prop:file read;
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070044
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080045# Shared libraries created by trusted components within an app home
46# directory can be dlopen()ed. To maintain the W^X property, these files
Nick Kralevich0eb0a162018-12-12 09:06:05 -080047# must never be writable to the app.
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080048neverallow all_untrusted_apps app_exec_data_file:file
Nick Kralevich0eb0a162018-12-12 09:06:05 -080049 { append create link relabelfrom relabelto rename setattr write };
50
Nick Kralevich65a89c12018-12-21 10:03:50 -080051# Block calling execve() on files in an apps home directory.
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070052# This is a W^X violation (loading executable code from a writable
53# home directory). For compatibility, allow for targetApi <= 28.
54# b/112357170
55neverallow {
56 all_untrusted_apps
57 -untrusted_app_25
58 -untrusted_app_27
Yabin Cuiffa2b612018-11-02 14:34:06 -070059 -runas_app
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070060} { app_data_file privapp_data_file }:file execute_no_trans;
61
David Brazdil535c5d22018-11-19 23:02:49 +000062# Do not allow untrusted apps to invoke dex2oat. This was historically required
63# by ART for compiling secondary dex files but has been removed in Q.
64# Exempt legacy apps (targetApi<=28) for compatibility.
65neverallow {
66 all_untrusted_apps
67 -untrusted_app_25
68 -untrusted_app_27
69} dex2oat_exec:file no_x_file_perms;
70
Chad Brubaker46e5a062017-01-27 15:53:38 -080071# Do not allow untrusted apps to be assigned mlstrustedsubject.
72# This would undermine the per-user isolation model being
73# enforced via levelFrom=user in seapp_contexts and the mls
74# constraints. As there is no direct way to specify a neverallow
75# on attribute assignment, this relies on the fact that fork
76# permission only makes sense within a domain (hence should
77# never be granted to any other domain within mlstrustedsubject)
78# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080079neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080080
81# Do not allow untrusted apps to hard link to any files.
82# In particular, if an untrusted app links to other app data
83# files, installd will not be able to guarantee the deletion
84# of the linked to file. Hard links also contribute to security
85# bugs, so we want to ensure untrusted apps never have this
86# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080087neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080088
89# Do not allow untrusted apps to access network MAC address file
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
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +0100116# Disallow sending RTM_GETLINK messages on netlink sockets.
Bram Bonné80b8e3c2020-12-01 10:00:55 +0000117neverallow {
118 all_untrusted_apps
119 -untrusted_app_25
120 -untrusted_app_27
121 -untrusted_app_29
122} domain:netlink_route_socket { bind nlmsg_readpriv };
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +0100123
Chad Brubaker46e5a062017-01-27 15:53:38 -0800124# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -0700125neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
126neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800127
128# Do not allow untrusted apps to create/unlink files outside of its sandbox,
129# internal storage or sdcard.
130# World accessible data locations allow application to fill the device
131# with unaccounted for data. This data will not get removed during
132# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -0700133neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -0800134 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600135 -sdcard_type
Chad Brubaker46e5a062017-01-27 15:53:38 -0800136 file_type
137 -app_data_file # The apps sandbox itself
Nick Kralevich23c9d912018-08-02 15:54:23 -0700138 -privapp_data_file
Nick Kralevichfb66c6f2019-01-11 09:37:46 -0800139 -app_exec_data_file # stored within the app sandbox directory
Chad Brubaker46e5a062017-01-27 15:53:38 -0800140 -media_rw_data_file # Internal storage. Known that apps can
141 # leave artfacts here after uninstall.
142 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800143 userdebug_or_eng(`
144 -method_trace_data_file # only on ro.debuggable=1
145 -coredump_file # userdebug/eng only
146 ')
147}:dir_file_class_set { create unlink };
148
Martijn Coenene3f1d5a2020-01-30 16:52:45 +0100149# No untrusted component except mediaprovider_app should be touching /dev/fuse
150neverallow { all_untrusted_apps -mediaprovider_app } fuse_device:chr_file *;
Nick Kralevich45766d42017-04-26 11:40:48 -0700151
Nick Kralevich3b2df192018-11-15 06:14:07 -0800152# Do not allow untrusted apps to directly open the tun_device
153neverallow all_untrusted_apps tun_device:chr_file open;
154# The tun_device ioctls below are not allowed, to prove equivalence
155# to the kernel patch at
Nick Kralevich619c1ef2018-10-30 20:12:41 -0700156# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21
Maciej Żenczykowskie346fbc2020-07-07 17:39:22 -0700157neverallowxperm all_untrusted_apps tun_device:chr_file ioctl ~{ FIOCLEX FIONCLEX TUNGETIFF };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800158
159# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800160neverallow all_untrusted_apps anr_data_file:file ~{ open append };
161neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800162
163# Avoid reads from generically labeled /proc files
164# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700165neverallow all_untrusted_apps {
166 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700167 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700168 proc_kmsg
169 proc_loadavg
170 proc_mounts
171 proc_pagetypeinfo
Mark Salyzynd6eaed82018-06-14 07:34:19 -0700172 proc_slabinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700173 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700174 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700175 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700176 proc_version
177 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700178 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700179}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700180
Martijn Coenenfd548032020-02-19 17:10:43 +0100181# /proc/filesystems is accessible to mediaprovider_app only since it handles
182# external storage
183neverallow { all_untrusted_apps - mediaprovider_app } proc_filesystems:file { no_rw_file_perms no_x_file_perms };
184
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700185# Avoid all access to kernel configuration
186neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
187
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700188# Do not allow untrusted apps access to preloads data files
189neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700190
191# Locking of files on /system could lead to denial of service attacks
192# against privileged system components
193neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700194
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700195# Do not permit untrusted apps to perform actions on HwBinder service_manager
196# other than find actions for services listed below
197neverallow all_untrusted_apps *:hwservice_manager ~find;
198
Jiyong Parke95c7042019-08-22 00:04:50 +0900199# Do not permit access from apps which host arbitrary code to the protected HwBinder
200# services.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700201# The two main reasons for this are:
Jiyong Parke95c7042019-08-22 00:04:50 +0900202# 1. Protected HwBinder servers do not perform client authentication because HIDL
203# currently does not expose caller UID information and, even if it did, those
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700204# HwBinder services either operate at a level below that of apps (e.g., HALs)
205# or must not rely on app identity for authorization. Thus, to be safe, the
206# default assumption is that every HwBinder service treats all its clients as
207# equally authorized to perform operations offered by the service.
208# 2. HAL servers (a subset of HwBinder services) contain code with higher
209# incidence rate of security issues than system/core components and have
210# access to lower layes of the stack (all the way down to hardware) thus
211# increasing opportunities for bypassing the Android security model.
Jiyong Parke95c7042019-08-22 00:04:50 +0900212neverallow all_untrusted_apps protected_hwservice:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700213
Steven Morelandb75b0472019-08-20 22:42:58 +0000214neverallow all_untrusted_apps {
215 vendor_service
Steven Morelandb75b0472019-08-20 22:42:58 +0000216}:service_manager find;
217
Dan Cashman91d398d2017-09-26 12:58:29 -0700218# SELinux is not an API for untrusted apps to use
219neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
220
Jeff Vander Stoepff511cb2018-09-07 07:39:28 -0700221# Access to /proc/tty/drivers, to allow apps to determine if they
222# are running in an emulated environment.
223# b/33214085 b/33814662 b/33791054 b/33211769
224# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java
225# This will go away in a future Android release
226neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms;
227neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms;
Tri Vof55c9892018-10-10 22:48:15 +0000228
229# Untrusted apps are not allowed to use cgroups.
230neverallow all_untrusted_apps cgroup:file *;
Tri Vo73d0a672019-01-27 13:39:19 -0800231
Tri Vo8eff3e22019-04-11 15:23:24 -0700232# /mnt/sdcard symlink was supposed to have been removed in Gingerbread. Apps
233# must not use it.
234neverallow {
235 all_untrusted_apps
236 -untrusted_app_25
237 -untrusted_app_27
238} mnt_sdcard_file:lnk_file *;
Jeff Vander Stoep2aa80422020-05-13 14:40:49 +0200239
240# Only privileged apps may find the incident service
241neverallow all_untrusted_apps incident_service:service_manager find;