blob: 640775520f89f765187360ca4b645ee6da284c96 [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
13 untrusted_v2_app
14}')
Chad Brubaker46e5a062017-01-27 15:53:38 -080015# Receive or send uevent messages.
Chad Brubakera782a812017-02-06 10:31:45 -080016neverallow all_untrusted_apps domain:netlink_kobject_uevent_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080017
18# Receive or send generic netlink messages
Chad Brubakera782a812017-02-06 10:31:45 -080019neverallow all_untrusted_apps domain:netlink_socket *;
Chad Brubaker46e5a062017-01-27 15:53:38 -080020
21# Too much leaky information in debugfs. It's a security
22# best practice to ensure these files aren't readable.
Chad Brubakera782a812017-02-06 10:31:45 -080023neverallow all_untrusted_apps debugfs_type: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
Chad Brubaker46e5a062017-01-27 15:53:38 -080044# Do not allow untrusted apps to be assigned mlstrustedsubject.
45# This would undermine the per-user isolation model being
46# enforced via levelFrom=user in seapp_contexts and the mls
47# constraints. As there is no direct way to specify a neverallow
48# on attribute assignment, this relies on the fact that fork
49# permission only makes sense within a domain (hence should
50# never be granted to any other domain within mlstrustedsubject)
51# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080052neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080053
54# Do not allow untrusted apps to hard link to any files.
55# In particular, if an untrusted app links to other app data
56# files, installd will not be able to guarantee the deletion
57# of the linked to file. Hard links also contribute to security
58# bugs, so we want to ensure untrusted apps never have this
59# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080060neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080061
62# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080063neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080064
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070065# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070066neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
67
68# Apps may never access the default sysfs label.
69neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070070
Chad Brubaker46e5a062017-01-27 15:53:38 -080071# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
72# ioctl permission, or 3. disallow the socket class.
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -070073neverallowxperm all_untrusted_apps domain:{ icmp_socket rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
Chad Brubakera782a812017-02-06 10:31:45 -080074neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
75neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080076 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050077 netlink_tcpdiag_socket netlink_nflog_socket
78 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080079 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
80 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
81 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
Jeff Vander Stoep0597ade2018-06-21 16:57:58 -070082 netlink_rdma_socket netlink_crypto_socket sctp_socket
83 ax25_socket ipx_socket netrom_socket atmpvc_socket x25_socket rose_socket decnet_socket
84 atmsvc_socket rds_socket irda_socket pppox_socket llc_socket can_socket tipc_socket
85 bluetooth_socket iucv_socket rxrpc_socket isdn_socket phonet_socket ieee802154_socket caif_socket
86 alg_socket nfc_socket vsock_socket kcm_socket qipcrtr_socket smc_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080087} *;
88
89# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -070090neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
91neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -080092
93# Do not allow untrusted apps to create/unlink files outside of its sandbox,
94# internal storage or sdcard.
95# World accessible data locations allow application to fill the device
96# with unaccounted for data. This data will not get removed during
97# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -070098neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -080099 fs_type
Jeff Sharkey000cafc2018-03-30 12:22:54 -0600100 -sdcard_type
Chad Brubaker46e5a062017-01-27 15:53:38 -0800101 file_type
102 -app_data_file # The apps sandbox itself
103 -media_rw_data_file # Internal storage. Known that apps can
104 # leave artfacts here after uninstall.
105 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800106 userdebug_or_eng(`
107 -method_trace_data_file # only on ro.debuggable=1
108 -coredump_file # userdebug/eng only
109 ')
110}:dir_file_class_set { create unlink };
111
Nick Kralevich45766d42017-04-26 11:40:48 -0700112# No untrusted component should be touching /dev/fuse
113neverallow all_untrusted_apps fuse_device:chr_file *;
114
Chad Brubaker46e5a062017-01-27 15:53:38 -0800115# Do not allow untrusted apps to directly open tun_device
Chad Brubakera782a812017-02-06 10:31:45 -0800116neverallow all_untrusted_apps tun_device:chr_file open;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800117
118# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800119neverallow all_untrusted_apps anr_data_file:file ~{ open append };
120neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800121
122# Avoid reads from generically labeled /proc files
123# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700124neverallow all_untrusted_apps {
125 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700126 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700127 proc_filesystems
128 proc_kmsg
129 proc_loadavg
130 proc_mounts
131 proc_pagetypeinfo
Mark Salyzynd6eaed82018-06-14 07:34:19 -0700132 proc_slabinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700133 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700134 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700135 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700136 proc_version
137 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700138 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700139}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700140
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700141# Avoid all access to kernel configuration
142neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
143
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700144# Do not allow untrusted apps access to preloads data files
145neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700146
147# Locking of files on /system could lead to denial of service attacks
148# against privileged system components
149neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700150
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700151# Do not permit untrusted apps to perform actions on HwBinder service_manager
152# other than find actions for services listed below
153neverallow all_untrusted_apps *:hwservice_manager ~find;
154
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700155# Do not permit access from apps which host arbitrary code to HwBinder services,
156# except those considered sufficiently safe for access from such apps.
157# The two main reasons for this are:
158# 1. HwBinder servers do not perform client authentication because HIDL
159# currently does not expose caller UID information and, even if it did, many
160# HwBinder services either operate at a level below that of apps (e.g., HALs)
161# or must not rely on app identity for authorization. Thus, to be safe, the
162# default assumption is that every HwBinder service treats all its clients as
163# equally authorized to perform operations offered by the service.
164# 2. HAL servers (a subset of HwBinder services) contain code with higher
165# incidence rate of security issues than system/core components and have
166# access to lower layes of the stack (all the way down to hardware) thus
167# increasing opportunities for bypassing the Android security model.
Dan Cashman3e307a42017-06-21 10:00:32 -0700168#
169# Safe services include:
170# - same process services: because they by definition run in the process
171# of the client and thus have the same access as the client domain in which
172# the process runs
173# - coredomain_hwservice: are considered safe because they do not pose risks
174# associated with reason #2 above.
175# - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been
176# designed for use by any domain.
177# - hal_graphics_allocator_hwservice: because these operations are also offered
178# by surfaceflinger Binder service, which apps are permitted to access
179# - hal_omx_hwservice: because this is a HwBinder version of the mediacodec
180# Binder service which apps were permitted to access.
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700181# - hal_codec2_hwservice: because this is a newer version of hal_omx_hwservice.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700182neverallow all_untrusted_apps {
183 hwservice_manager_type
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700184 -same_process_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700185 -coredomain_hwservice
Pawin Vongmasa19a74ec2018-03-28 21:09:23 -0700186 -hal_codec2_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700187 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700188 -hal_graphics_allocator_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700189 -hal_omx_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700190 -hal_cas_hwservice
Michael Butlerea331aa2017-12-15 14:16:25 -0800191 -hal_neuralnetworks_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700192 -untrusted_app_visible_hwservice
193}:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700194
Dan Cashman3e307a42017-06-21 10:00:32 -0700195# Make sure that the following services are never accessible by untrusted_apps
196neverallow all_untrusted_apps {
197 default_android_hwservice
198 hal_audio_hwservice
Andrew Scull64f35fa2018-01-10 16:11:46 +0000199 hal_authsecret_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700200 hal_bluetooth_hwservice
201 hal_bootctl_hwservice
202 hal_camera_hwservice
Janis Danisevskis97c56bd2018-01-09 17:42:53 -0500203 hal_confirmationui_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700204 hal_contexthub_hwservice
205 hal_drm_hwservice
206 hal_dumpstate_hwservice
207 hal_fingerprint_hwservice
208 hal_gatekeeper_hwservice
209 hal_gnss_hwservice
210 hal_graphics_composer_hwservice
211 hal_health_hwservice
212 hal_ir_hwservice
213 hal_keymaster_hwservice
214 hal_light_hwservice
215 hal_memtrack_hwservice
216 hal_nfc_hwservice
217 hal_oemlock_hwservice
218 hal_power_hwservice
Ruchi Kandoi8a2b4a72018-01-04 10:33:20 -0800219 hal_secure_element_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700220 hal_sensors_hwservice
221 hal_telephony_hwservice
222 hal_thermal_hwservice
223 hal_tv_cec_hwservice
224 hal_tv_input_hwservice
225 hal_usb_hwservice
226 hal_vibrator_hwservice
227 hal_vr_hwservice
228 hal_weaver_hwservice
229 hal_wifi_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700230 hal_wifi_offload_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700231 hal_wifi_supplicant_hwservice
232 hidl_base_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700233 system_net_netd_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700234}:hwservice_manager find;
235# HwBinder services offered by core components (as opposed to vendor components)
236# are considered somewhat safer due to point #2 above.
237neverallow all_untrusted_apps {
238 coredomain_hwservice
239 -same_process_hwservice
240 -hidl_allocator_hwservice # Designed for use by any domain
241 -hidl_manager_hwservice # Designed for use by any domain
242 -hidl_memory_hwservice # Designed for use by any domain
243 -hidl_token_hwservice # Designed for use by any domain
244}:hwservice_manager find;
245
Dan Cashman91d398d2017-09-26 12:58:29 -0700246# SELinux is not an API for untrusted apps to use
247neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
248
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700249# Restrict *Binder access from apps to HAL domains. We can only do this on full
250# Treble devices where *Binder communications between apps and HALs are tightly
251# restricted.
252full_treble_only(`
253 neverallow all_untrusted_apps {
254 halserverdomain
255 -coredomain
256 -hal_configstore_server
257 -hal_graphics_allocator_server
Dan Cashman91d398d2017-09-26 12:58:29 -0700258 -hal_cas_server
Michael Butlerea331aa2017-12-15 14:16:25 -0800259 -hal_neuralnetworks_server
Steven Moreland7baf7252018-05-25 16:23:37 -0700260 -hal_omx_server
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700261 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
Dan Cashman91d398d2017-09-26 12:58:29 -0700262 -untrusted_app_visible_halserver
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700263 }:binder { call transfer };
264')
Dongwon Kang1134bd02017-11-06 11:19:07 -0800265
266# Untrusted apps are not allowed to find mediaextractor update service.
267neverallow all_untrusted_apps mediaextractor_update_service:service_manager find;
Jeff Vander Stoep4d3ee1a2018-04-16 07:49:49 -0700268
269# Untrusted apps are not allowed to use the signature|privileged|development
270# android.permission.READ_LOGS permission, so they may not read dropbox files.
271# Access to the the dropbox directory is covered by a neverallow for domain.
272neverallow all_untrusted_apps dropbox_data_file:file *;