blob: f33cff929e879cb50ea74083a08bf0ce424d14b0 [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
Bram Bonnéea5460a2021-05-12 14:19:24 +020014 untrusted_app_30
Nick Kralevichdb5962c2017-04-26 16:14:40 -070015 untrusted_app_all
Nick Kralevichdb5962c2017-04-26 16:14:40 -070016}')
Chad Brubaker46e5a062017-01-27 15:53:38 -080017# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080018neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080019
20# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080021neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080022
Alan Stokesa0518b72020-10-27 11:28:00 +000023# Read or write kernel printk buffer
24neverallow all_untrusted_apps kmsg_device:chr_file no_rw_file_perms;
25
Chad Brubaker46e5a062017-01-27 15:53:38 -080026# Too much leaky information in debugfs. It's a security
27# best practice to ensure these files aren't readable.
Dan Austin55d90962018-11-29 10:37:18 -080028neverallow all_untrusted_apps { debugfs_type -debugfs_kcov }:file read;
Jeff Vander Stoep0ac2eec2019-02-04 10:07:15 -080029neverallow {all_untrusted_apps userdebug_or_eng(`-domain')} debugfs_type:{ file lnk_file } read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080030
31# Do not allow untrusted apps to register services.
32# Only trusted components of Android should be registering
33# services.
Chad Brubakera782a812017-02-06 10:31:45 -080034neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080035
Alex Klyubin00657832017-04-25 09:27:54 -070036# Do not allow untrusted apps to use VendorBinder
37neverallow all_untrusted_apps vndbinder_device:chr_file *;
38neverallow all_untrusted_apps vndservice_manager_type:service_manager *;
39
Chad Brubaker46e5a062017-01-27 15:53:38 -080040# Do not allow untrusted apps to connect to the property service
41# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070042neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
43neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
44neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080045
Jeff Vander Stoep28903d92019-10-15 21:00:22 +020046# net.dns properties are not a public API. Disallow untrusted apps from reading this property.
47neverallow { all_untrusted_apps } net_dns_prop:file read;
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070048
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080049# Shared libraries created by trusted components within an app home
50# directory can be dlopen()ed. To maintain the W^X property, these files
Nick Kralevich0eb0a162018-12-12 09:06:05 -080051# must never be writable to the app.
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080052neverallow all_untrusted_apps app_exec_data_file:file
Nick Kralevich0eb0a162018-12-12 09:06:05 -080053 { append create link relabelfrom relabelto rename setattr write };
54
Nick Kralevich65a89c12018-12-21 10:03:50 -080055# Block calling execve() on files in an apps home directory.
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070056# This is a W^X violation (loading executable code from a writable
57# home directory). For compatibility, allow for targetApi <= 28.
58# b/112357170
59neverallow {
60 all_untrusted_apps
61 -untrusted_app_25
62 -untrusted_app_27
Yabin Cuiffa2b612018-11-02 14:34:06 -070063 -runas_app
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070064} { app_data_file privapp_data_file }:file execute_no_trans;
65
David Brazdil535c5d22018-11-19 23:02:49 +000066# Do not allow untrusted apps to invoke dex2oat. This was historically required
67# by ART for compiling secondary dex files but has been removed in Q.
68# Exempt legacy apps (targetApi<=28) for compatibility.
69neverallow {
70 all_untrusted_apps
71 -untrusted_app_25
72 -untrusted_app_27
73} dex2oat_exec:file no_x_file_perms;
74
Chad Brubaker46e5a062017-01-27 15:53:38 -080075# Do not allow untrusted apps to be assigned mlstrustedsubject.
76# This would undermine the per-user isolation model being
77# enforced via levelFrom=user in seapp_contexts and the mls
78# constraints. As there is no direct way to specify a neverallow
79# on attribute assignment, this relies on the fact that fork
80# permission only makes sense within a domain (hence should
81# never be granted to any other domain within mlstrustedsubject)
82# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080083neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080084
85# Do not allow untrusted apps to hard link to any files.
86# In particular, if an untrusted app links to other app data
87# files, installd will not be able to guarantee the deletion
88# of the linked to file. Hard links also contribute to security
89# bugs, so we want to ensure untrusted apps never have this
90# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080091neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080092
93# Do not allow untrusted apps to access network MAC address file
Maciej Żenczykowski804d99a2019-07-18 00:04:54 -070094neverallow all_untrusted_apps sysfs_net:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080095
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070096# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070097neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
98
99# Apps may never access the default sysfs label.
100neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -0700101
Chad Brubaker46e5a062017-01-27 15:53:38 -0800102# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
103# ioctl permission, or 3. disallow the socket class.
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700104neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
Chad Brubakera782a812017-02-06 10:31:45 -0800105neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
106neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -0800107 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -0500108 netlink_tcpdiag_socket netlink_nflog_socket
109 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800110 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
111 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
112 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700113 netlink_rdma_socket netlink_crypto_socket sctp_socket
114 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
115 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
116 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
Jiyong Park5e20d832021-07-12 21:11:33 +0900117 alg_socket nfc_socket kcm_socket qipcrtr_socket smc_socket xdp_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800118} *;
119
Alan Stokesf96cd652021-09-07 12:25:38 +0100120# Apps can read/write an already open vsock (e.g. created by
121# virtualizationservice) but nothing more than that (e.g. creating a
122# new vsock, etc.)
123neverallow all_untrusted_apps *:vsock_socket ~{ getattr read write };
Jiyong Park5e20d832021-07-12 21:11:33 +0900124
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +0100125# Disallow sending RTM_GETLINK messages on netlink sockets.
Bram Bonnéa4433b42021-04-30 15:48:09 +0200126neverallow all_untrusted_apps domain:netlink_route_socket { bind nlmsg_readpriv };
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +0100127
Bram Bonnéea5460a2021-05-12 14:19:24 +0200128# Disallow sending RTM_GETNEIGH{TBL} messages on netlink sockets.
129neverallow {
130 all_untrusted_apps
131 -untrusted_app_25
132 -untrusted_app_27
133 -untrusted_app_29
134 -untrusted_app_30
135} domain:netlink_route_socket nlmsg_getneigh;
136
Chad Brubaker46e5a062017-01-27 15:53:38 -0800137# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -0700138neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
139neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800140
141# Do not allow untrusted apps to create/unlink files outside of its sandbox,
142# internal storage or sdcard.
143# World accessible data locations allow application to fill the device
144# with unaccounted for data. This data will not get removed during
145# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -0700146neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -0800147 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600148 -sdcard_type
Thiébaud Weksteen9ec53272021-06-23 10:21:49 +0200149 -fuse
Chad Brubaker46e5a062017-01-27 15:53:38 -0800150 file_type
151 -app_data_file # The apps sandbox itself
Nick Kralevich23c9d912018-08-02 15:54:23 -0700152 -privapp_data_file
Nick Kralevichfb66c6f2019-01-11 09:37:46 -0800153 -app_exec_data_file # stored within the app sandbox directory
Chad Brubaker46e5a062017-01-27 15:53:38 -0800154 -media_rw_data_file # Internal storage. Known that apps can
155 # leave artfacts here after uninstall.
156 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800157 userdebug_or_eng(`
158 -method_trace_data_file # only on ro.debuggable=1
159 -coredump_file # userdebug/eng only
160 ')
161}:dir_file_class_set { create unlink };
162
Martijn Coenene3f1d5a2020-01-30 16:52:45 +0100163# No untrusted component except mediaprovider_app should be touching /dev/fuse
164neverallow { all_untrusted_apps -mediaprovider_app } fuse_device:chr_file *;
Nick Kralevich45766d42017-04-26 11:40:48 -0700165
Nick Kralevich3b2df192018-11-15 06:14:07 -0800166# Do not allow untrusted apps to directly open the tun_device
167neverallow all_untrusted_apps tun_device:chr_file open;
168# The tun_device ioctls below are not allowed, to prove equivalence
169# to the kernel patch at
Nick Kralevich619c1ef2018-10-30 20:12:41 -0700170# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21
Maciej Żenczykowskie346fbc2020-07-07 17:39:22 -0700171neverallowxperm all_untrusted_apps tun_device:chr_file ioctl ~{ FIOCLEX FIONCLEX TUNGETIFF };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800172
173# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800174neverallow all_untrusted_apps anr_data_file:file ~{ open append };
175neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800176
177# Avoid reads from generically labeled /proc files
178# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700179neverallow all_untrusted_apps {
180 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700181 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700182 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
Martijn Coenenfd548032020-02-19 17:10:43 +0100195# /proc/filesystems is accessible to mediaprovider_app only since it handles
196# external storage
197neverallow { all_untrusted_apps - mediaprovider_app } proc_filesystems:file { no_rw_file_perms no_x_file_perms };
198
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700199# Avoid all access to kernel configuration
200neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
201
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700202# Do not allow untrusted apps access to preloads data files
203neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700204
205# Locking of files on /system could lead to denial of service attacks
206# against privileged system components
207neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700208
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700209# Do not permit untrusted apps to perform actions on HwBinder service_manager
210# other than find actions for services listed below
211neverallow all_untrusted_apps *:hwservice_manager ~find;
212
Steven Morelanda43e26e2020-10-21 21:47:00 +0000213# Do not permit access from apps which host arbitrary code to the protected services
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700214# The two main reasons for this are:
Steven Morelanda43e26e2020-10-21 21:47:00 +0000215# 1. Protected HwBinder servers do not perform client authentication because
216# vendor code does not have a way to understand apps or their relation to
217# caller UID information and, even if it did, those services either operate
218# at a level below that of apps (e.g., HALs) or must not rely on app identity
219# for authorization. Thus, to be safe, the default assumption for all added
220# vendor services is that they treat all their clients as equally authorized
221# to perform operations offered by the service.
222# 2. HAL servers contain code with higher incidence rate of security issues
223# than system/core components and have access to lower layes of the stack
224# (all the way down to hardware) thus increasing opportunities for bypassing
225# the Android security model.
Jiyong Parke95c7042019-08-22 00:04:50 +0900226neverallow all_untrusted_apps protected_hwservice:hwservice_manager find;
Steven Morelanda43e26e2020-10-21 21:47:00 +0000227neverallow all_untrusted_apps protected_service:service_manager find;
Steven Morelandb75b0472019-08-20 22:42:58 +0000228
Dan Cashman91d398d2017-09-26 12:58:29 -0700229# SELinux is not an API for untrusted apps to use
230neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
231
Jeff Vander Stoepff511cb2018-09-07 07:39:28 -0700232# Access to /proc/tty/drivers, to allow apps to determine if they
233# are running in an emulated environment.
234# b/33214085 b/33814662 b/33791054 b/33211769
235# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java
236# This will go away in a future Android release
237neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms;
238neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms;
Tri Vof55c9892018-10-10 22:48:15 +0000239
240# Untrusted apps are not allowed to use cgroups.
241neverallow all_untrusted_apps cgroup:file *;
Marco Ballesioaa4ce952021-02-11 15:18:11 -0800242neverallow all_untrusted_apps cgroup_v2:file *;
Tri Vo73d0a672019-01-27 13:39:19 -0800243
Tri Vo8eff3e22019-04-11 15:23:24 -0700244# /mnt/sdcard symlink was supposed to have been removed in Gingerbread. Apps
245# must not use it.
246neverallow {
247 all_untrusted_apps
248 -untrusted_app_25
249 -untrusted_app_27
250} mnt_sdcard_file:lnk_file *;
Jeff Vander Stoep2aa80422020-05-13 14:40:49 +0200251
252# Only privileged apps may find the incident service
253neverallow all_untrusted_apps incident_service:service_manager find;