blob: bf723c5be3d4abd58b830d010df9b1781b4e1da9 [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
Charles Chenccf80142023-01-20 03:34:19 +00008 isolated_app_all
Charles Chen3d4a6b72023-01-17 08:16:44 +00009 isolated_compute_app
Nick Kralevichdb5962c2017-04-26 16:14:40 -070010 mediaprovider
Martijn Coenene3f1d5a2020-01-30 16:52:45 +010011 mediaprovider_app
Nick Kralevichdb5962c2017-04-26 16:14:40 -070012 untrusted_app
13 untrusted_app_25
Jeff Vander Stoep3aa7ca52018-04-03 11:22:38 -070014 untrusted_app_27
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +010015 untrusted_app_29
Bram Bonnéea5460a2021-05-12 14:19:24 +020016 untrusted_app_30
Nick Kralevichdb5962c2017-04-26 16:14:40 -070017 untrusted_app_all
Nick Kralevichdb5962c2017-04-26 16:14:40 -070018}')
Chad Brubaker46e5a062017-01-27 15:53:38 -080019# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080020neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080021
22# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080023neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080024
Alan Stokesa0518b72020-10-27 11:28:00 +000025# Read or write kernel printk buffer
26neverallow all_untrusted_apps kmsg_device:chr_file no_rw_file_perms;
27
Chad Brubaker46e5a062017-01-27 15:53:38 -080028# Too much leaky information in debugfs. It's a security
29# best practice to ensure these files aren't readable.
Dan Austin55d90962018-11-29 10:37:18 -080030neverallow all_untrusted_apps { debugfs_type -debugfs_kcov }:file read;
Jeff Vander Stoep0ac2eec2019-02-04 10:07:15 -080031neverallow {all_untrusted_apps userdebug_or_eng(`-domain')} debugfs_type:{ file lnk_file } read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080032
33# Do not allow untrusted apps to register services.
34# Only trusted components of Android should be registering
35# services.
Chad Brubakera782a812017-02-06 10:31:45 -080036neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080037
Alex Klyubin00657832017-04-25 09:27:54 -070038# Do not allow untrusted apps to use VendorBinder
39neverallow all_untrusted_apps vndbinder_device:chr_file *;
40neverallow all_untrusted_apps vndservice_manager_type:service_manager *;
41
Chad Brubaker46e5a062017-01-27 15:53:38 -080042# Do not allow untrusted apps to connect to the property service
43# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070044neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
45neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
46neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080047
Jeff Vander Stoep28903d92019-10-15 21:00:22 +020048# net.dns properties are not a public API. Disallow untrusted apps from reading this property.
49neverallow { all_untrusted_apps } net_dns_prop:file read;
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070050
Nazanind65a7bf2021-04-29 21:52:42 -070051# radio_cdma_ecm_prop properties are not a public API. Disallow untrusted apps from reading this property.
52neverallow { all_untrusted_apps } radio_cdma_ecm_prop:file read;
53
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080054# Shared libraries created by trusted components within an app home
55# directory can be dlopen()ed. To maintain the W^X property, these files
Nick Kralevich0eb0a162018-12-12 09:06:05 -080056# must never be writable to the app.
Nick Kralevichfb66c6f2019-01-11 09:37:46 -080057neverallow all_untrusted_apps app_exec_data_file:file
Nick Kralevich0eb0a162018-12-12 09:06:05 -080058 { append create link relabelfrom relabelto rename setattr write };
59
Nick Kralevich65a89c12018-12-21 10:03:50 -080060# Block calling execve() on files in an apps home directory.
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070061# This is a W^X violation (loading executable code from a writable
62# home directory). For compatibility, allow for targetApi <= 28.
63# b/112357170
64neverallow {
65 all_untrusted_apps
66 -untrusted_app_25
67 -untrusted_app_27
Yabin Cuiffa2b612018-11-02 14:34:06 -070068 -runas_app
Yabin Cui5dc2c8c2018-11-02 11:12:43 -070069} { app_data_file privapp_data_file }:file execute_no_trans;
70
Ellen Arteca27b515e2024-04-30 20:26:55 +000071is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
72 # block apps from executing files in their storage areas
73 # this is a stronger and more desirable guarantee than blocking execute_no_trans, but
74 # execute cannot be blocked on all of app_data_file without causing
75 # backwards compatibility issues (see b/237289679)
76 neverallow appdomain storage_area_content_file:file execute;
77')
78
79is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
80 # dont allow apps to modify their own directories of storage areas
81 neverallow appdomain storage_area_app_dir:dir_file_class_set {
82 create write setattr relabelfrom relabelto append unlink link rename
83 };
84')
85
David Brazdil535c5d22018-11-19 23:02:49 +000086# Do not allow untrusted apps to invoke dex2oat. This was historically required
87# by ART for compiling secondary dex files but has been removed in Q.
88# Exempt legacy apps (targetApi<=28) for compatibility.
89neverallow {
90 all_untrusted_apps
91 -untrusted_app_25
92 -untrusted_app_27
93} dex2oat_exec:file no_x_file_perms;
94
Chad Brubaker46e5a062017-01-27 15:53:38 -080095# Do not allow untrusted apps to be assigned mlstrustedsubject.
96# This would undermine the per-user isolation model being
97# enforced via levelFrom=user in seapp_contexts and the mls
98# constraints. As there is no direct way to specify a neverallow
99# on attribute assignment, this relies on the fact that fork
100# permission only makes sense within a domain (hence should
101# never be granted to any other domain within mlstrustedsubject)
102# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -0800103neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800104
105# Do not allow untrusted apps to hard link to any files.
106# In particular, if an untrusted app links to other app data
107# files, installd will not be able to guarantee the deletion
108# of the linked to file. Hard links also contribute to security
109# bugs, so we want to ensure untrusted apps never have this
110# capability.
Chad Brubakera782a812017-02-06 10:31:45 -0800111neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800112
113# Do not allow untrusted apps to access network MAC address file
Maciej Żenczykowski804d99a2019-07-18 00:04:54 -0700114neverallow all_untrusted_apps sysfs_net:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800115
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -0700116# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700117neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
118
119# Apps may never access the default sysfs label.
120neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -0700121
Chad Brubaker46e5a062017-01-27 15:53:38 -0800122# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
123# ioctl permission, or 3. disallow the socket class.
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700124neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
Chad Brubakera782a812017-02-06 10:31:45 -0800125neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
126neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -0800127 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -0500128 netlink_tcpdiag_socket netlink_nflog_socket
129 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800130 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
131 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
132 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -0700133 netlink_rdma_socket netlink_crypto_socket sctp_socket
134 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
135 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
136 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
Jiyong Park5e20d832021-07-12 21:11:33 +0900137 alg_socket nfc_socket kcm_socket qipcrtr_socket smc_socket xdp_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -0800138} *;
139
Alan Stokesf96cd652021-09-07 12:25:38 +0100140# Apps can read/write an already open vsock (e.g. created by
141# virtualizationservice) but nothing more than that (e.g. creating a
142# new vsock, etc.)
Alice Wang40718f42022-08-30 14:10:48 +0000143neverallow all_untrusted_apps *:vsock_socket ~{ getattr getopt read write };
Jiyong Park5e20d832021-07-12 21:11:33 +0900144
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +0100145# Disallow sending RTM_GETLINK messages on netlink sockets.
Bram Bonnéa4433b42021-04-30 15:48:09 +0200146neverallow all_untrusted_apps domain:netlink_route_socket { bind nlmsg_readpriv };
Bram Bonneaf609b22022-05-17 14:22:02 +0200147neverallow priv_app domain:netlink_route_socket { bind nlmsg_readpriv };
Jeff Vander Stoep1f7ae8e2020-01-20 10:14:48 +0100148
Bram Bonnéea5460a2021-05-12 14:19:24 +0200149# Disallow sending RTM_GETNEIGH{TBL} messages on netlink sockets.
150neverallow {
151 all_untrusted_apps
152 -untrusted_app_25
153 -untrusted_app_27
154 -untrusted_app_29
155 -untrusted_app_30
156} domain:netlink_route_socket nlmsg_getneigh;
157
Chad Brubaker46e5a062017-01-27 15:53:38 -0800158# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -0700159neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
160neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800161
162# Do not allow untrusted apps to create/unlink files outside of its sandbox,
163# internal storage or sdcard.
164# World accessible data locations allow application to fill the device
165# with unaccounted for data. This data will not get removed during
166# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -0700167neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -0800168 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600169 -sdcard_type
Thiébaud Weksteen9ec53272021-06-23 10:21:49 +0200170 -fuse
Chad Brubaker46e5a062017-01-27 15:53:38 -0800171 file_type
172 -app_data_file # The apps sandbox itself
Nick Kralevich23c9d912018-08-02 15:54:23 -0700173 -privapp_data_file
Ellen Arteca27b515e2024-04-30 20:26:55 +0000174 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `-storage_area_content_file')
Nick Kralevichfb66c6f2019-01-11 09:37:46 -0800175 -app_exec_data_file # stored within the app sandbox directory
Chad Brubaker46e5a062017-01-27 15:53:38 -0800176 -media_rw_data_file # Internal storage. Known that apps can
177 # leave artfacts here after uninstall.
178 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800179 userdebug_or_eng(`
180 -method_trace_data_file # only on ro.debuggable=1
181 -coredump_file # userdebug/eng only
182 ')
183}:dir_file_class_set { create unlink };
184
Martijn Coenene3f1d5a2020-01-30 16:52:45 +0100185# No untrusted component except mediaprovider_app should be touching /dev/fuse
186neverallow { all_untrusted_apps -mediaprovider_app } fuse_device:chr_file *;
Nick Kralevich45766d42017-04-26 11:40:48 -0700187
Nick Kralevich3b2df192018-11-15 06:14:07 -0800188# Do not allow untrusted apps to directly open the tun_device
189neverallow all_untrusted_apps tun_device:chr_file open;
190# The tun_device ioctls below are not allowed, to prove equivalence
191# to the kernel patch at
Nick Kralevich619c1ef2018-10-30 20:12:41 -0700192# https://android.googlesource.com/kernel/common/+/11cee2be0c2062ba88f04eb51196506f870a3b5d%5E%21
Maciej Żenczykowskie346fbc2020-07-07 17:39:22 -0700193neverallowxperm all_untrusted_apps tun_device:chr_file ioctl ~{ FIOCLEX FIONCLEX TUNGETIFF };
Chad Brubaker46e5a062017-01-27 15:53:38 -0800194
195# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800196neverallow all_untrusted_apps anr_data_file:file ~{ open append };
197neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800198
199# Avoid reads from generically labeled /proc files
200# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700201neverallow all_untrusted_apps {
202 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700203 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700204 proc_kmsg
205 proc_loadavg
206 proc_mounts
207 proc_pagetypeinfo
Mark Salyzynd6eaed82018-06-14 07:34:19 -0700208 proc_slabinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700209 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700210 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700211 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700212 proc_version
213 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700214 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700215}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700216
Martijn Coenenfd548032020-02-19 17:10:43 +0100217# /proc/filesystems is accessible to mediaprovider_app only since it handles
218# external storage
219neverallow { all_untrusted_apps - mediaprovider_app } proc_filesystems:file { no_rw_file_perms no_x_file_perms };
220
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700221# Avoid all access to kernel configuration
222neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
223
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700224# Do not allow untrusted apps access to preloads data files
225neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700226
227# Locking of files on /system could lead to denial of service attacks
228# against privileged system components
229neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700230
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700231# Do not permit untrusted apps to perform actions on HwBinder service_manager
232# other than find actions for services listed below
233neverallow all_untrusted_apps *:hwservice_manager ~find;
234
Steven Morelanda43e26e2020-10-21 21:47:00 +0000235# Do not permit access from apps which host arbitrary code to the protected services
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700236# The two main reasons for this are:
Steven Morelanda43e26e2020-10-21 21:47:00 +0000237# 1. Protected HwBinder servers do not perform client authentication because
238# vendor code does not have a way to understand apps or their relation to
239# caller UID information and, even if it did, those services either operate
240# at a level below that of apps (e.g., HALs) or must not rely on app identity
241# for authorization. Thus, to be safe, the default assumption for all added
242# vendor services is that they treat all their clients as equally authorized
243# to perform operations offered by the service.
244# 2. HAL servers contain code with higher incidence rate of security issues
245# than system/core components and have access to lower layes of the stack
246# (all the way down to hardware) thus increasing opportunities for bypassing
247# the Android security model.
Jiyong Parke95c7042019-08-22 00:04:50 +0900248neverallow all_untrusted_apps protected_hwservice:hwservice_manager find;
Steven Morelanda43e26e2020-10-21 21:47:00 +0000249neverallow all_untrusted_apps protected_service:service_manager find;
Steven Morelandb75b0472019-08-20 22:42:58 +0000250
Dan Cashman91d398d2017-09-26 12:58:29 -0700251# SELinux is not an API for untrusted apps to use
252neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
253
Jeff Vander Stoepff511cb2018-09-07 07:39:28 -0700254# Access to /proc/tty/drivers, to allow apps to determine if they
255# are running in an emulated environment.
256# b/33214085 b/33814662 b/33791054 b/33211769
257# https://github.com/strazzere/anti-emulator/blob/master/AntiEmulator/src/diff/strazzere/anti/emulator/FindEmulator.java
258# This will go away in a future Android release
259neverallow { all_untrusted_apps -untrusted_app_25 } proc_tty_drivers:file r_file_perms;
260neverallow all_untrusted_apps proc_tty_drivers:file ~r_file_perms;
Tri Vof55c9892018-10-10 22:48:15 +0000261
262# Untrusted apps are not allowed to use cgroups.
263neverallow all_untrusted_apps cgroup:file *;
Marco Ballesioaa4ce952021-02-11 15:18:11 -0800264neverallow all_untrusted_apps cgroup_v2:file *;
Tri Vo73d0a672019-01-27 13:39:19 -0800265
Tri Vo8eff3e22019-04-11 15:23:24 -0700266# /mnt/sdcard symlink was supposed to have been removed in Gingerbread. Apps
267# must not use it.
268neverallow {
269 all_untrusted_apps
270 -untrusted_app_25
271 -untrusted_app_27
272} mnt_sdcard_file:lnk_file *;
Jeff Vander Stoep2aa80422020-05-13 14:40:49 +0200273
274# Only privileged apps may find the incident service
275neverallow all_untrusted_apps incident_service:service_manager find;
Alessandra Lorod0e108f2022-07-14 11:52:21 +0000276
Tej Singh000b2512024-02-13 23:27:00 -0800277# Only privileged apps may find stats service
278neverallow all_untrusted_apps stats_service:service_manager find;
279
Alessandra Loro8a7dcb52022-08-18 13:09:36 +0000280# Do not allow untrusted app to read hidden system proprerties.
281# We do not include in the exclusions other normally untrusted applications such as mediaprovider
282# due to the specific logging use cases.
Alessandra Lorod0e108f2022-07-14 11:52:21 +0000283# Context: b/193912100
284neverallow {
Alessandra Loro24d90e72022-11-18 14:09:41 +0000285 all_untrusted_apps
286 -mediaprovider
287 -mediaprovider_app
Alessandra Lorod0e108f2022-07-14 11:52:21 +0000288} { userdebug_or_eng_prop }:file read;
Yuyang Huangcfdea5f2023-01-18 16:52:43 +0900289
Yuyang Huangcfdea5f2023-01-18 16:52:43 +0900290# Do not allow untrusted app to access /dev/socket/mdnsd since U. The socket is
291# used to communicate to the mdnsd responder. The mdnsd responder will be
292# replaced by a java implementation which is integrated into the system server.
293# For untrusted apps running with API level 33-, they still have access to
294# /dev/socket/mdnsd for backward compatibility.
295neverallow {
296 all_untrusted_apps
297 -untrusted_app_25
298 -untrusted_app_27
299 -untrusted_app_29
300 -untrusted_app_30
301 -untrusted_app_32
302} mdnsd_socket:sock_file write;
303neverallow {
304 all_untrusted_apps
305 -untrusted_app_25
306 -untrusted_app_27
307 -untrusted_app_29
308 -untrusted_app_30
309 -untrusted_app_32
310} mdnsd:unix_stream_socket connectto;
Gil Cukierman214294c2022-11-14 17:06:36 -0500311
312# Do not allow untrusted apps to use anonymous inodes. At the moment,
313# type transitions are the only way to distinguish between different
314# anon_inode usages like userfaultfd and io_uring. This prevents us from
315# creating a more fine-grained neverallow policy for each anon_inode usage.
316neverallow all_untrusted_apps domain:anon_inode *;
Daniel Norman4245d042023-11-30 23:28:04 +0000317
318# Do not allow untrusted app access to hidraw devices.
319neverallow all_untrusted_apps hidraw_device:chr_file *;