blob: f998e550448194d8f964dcdfdcca1f0f10ce084c [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
11 untrusted_app_all
12 untrusted_v2_app
13}')
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.
Chad Brubakera782a812017-02-06 10:31:45 -080022neverallow all_untrusted_apps debugfs_type:file read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080023
24# Do not allow untrusted apps to register services.
25# Only trusted components of Android should be registering
26# services.
Chad Brubakera782a812017-02-06 10:31:45 -080027neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080028
Alex Klyubin00657832017-04-25 09:27:54 -070029# Do not allow untrusted apps to use VendorBinder
30neverallow all_untrusted_apps vndbinder_device:chr_file *;
31neverallow all_untrusted_apps vndservice_manager_type:service_manager *;
32
Chad Brubaker46e5a062017-01-27 15:53:38 -080033# Do not allow untrusted apps to connect to the property service
34# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070035neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
36neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
37neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080038
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070039# net.dns properties are not a public API. Temporarily exempt pre-Oreo apps,
40# but otherwise disallow untrusted apps from reading this property.
41neverallow { all_untrusted_apps -untrusted_app_25 } net_dns_prop:file read;
42
Chad Brubaker46e5a062017-01-27 15:53:38 -080043# Do not allow untrusted apps to be assigned mlstrustedsubject.
44# This would undermine the per-user isolation model being
45# enforced via levelFrom=user in seapp_contexts and the mls
46# constraints. As there is no direct way to specify a neverallow
47# on attribute assignment, this relies on the fact that fork
48# permission only makes sense within a domain (hence should
49# never be granted to any other domain within mlstrustedsubject)
50# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080051neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080052
53# Do not allow untrusted apps to hard link to any files.
54# In particular, if an untrusted app links to other app data
55# files, installd will not be able to guarantee the deletion
56# of the linked to file. Hard links also contribute to security
57# bugs, so we want to ensure untrusted apps never have this
58# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080059neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080060
61# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080062neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080063
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070064# Do not allow any write access to files in /sys
Jeff Vander Stoep886aa542018-03-28 15:34:37 -070065neverallow all_untrusted_apps sysfs_type:file { no_w_file_perms no_x_file_perms };
66
67# Apps may never access the default sysfs label.
68neverallow all_untrusted_apps sysfs:file no_rw_file_perms;
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070069
Chad Brubaker46e5a062017-01-27 15:53:38 -080070# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
71# ioctl permission, or 3. disallow the socket class.
Chad Brubakera782a812017-02-06 10:31:45 -080072neverallowxperm all_untrusted_apps domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
73neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
74neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080075 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050076 netlink_tcpdiag_socket netlink_nflog_socket
77 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080078 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
79 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
80 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
81 netlink_rdma_socket netlink_crypto_socket
82} *;
83
84# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -070085neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
86neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -080087
88# Do not allow untrusted apps to create/unlink files outside of its sandbox,
89# internal storage or sdcard.
90# World accessible data locations allow application to fill the device
91# with unaccounted for data. This data will not get removed during
92# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -070093neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -080094 fs_type
95 -fuse # sdcard
96 -sdcardfs # sdcard
97 -vfat
98 file_type
99 -app_data_file # The apps sandbox itself
100 -media_rw_data_file # Internal storage. Known that apps can
101 # leave artfacts here after uninstall.
102 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -0800103 userdebug_or_eng(`
104 -method_trace_data_file # only on ro.debuggable=1
105 -coredump_file # userdebug/eng only
106 ')
107}:dir_file_class_set { create unlink };
108
Nick Kralevich45766d42017-04-26 11:40:48 -0700109# No untrusted component should be touching /dev/fuse
110neverallow all_untrusted_apps fuse_device:chr_file *;
111
Chad Brubaker46e5a062017-01-27 15:53:38 -0800112# Do not allow untrusted apps to directly open tun_device
Chad Brubakera782a812017-02-06 10:31:45 -0800113neverallow all_untrusted_apps tun_device:chr_file open;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800114
115# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800116neverallow all_untrusted_apps anr_data_file:file ~{ open append };
117neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800118
119# Avoid reads from generically labeled /proc files
120# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700121neverallow all_untrusted_apps {
122 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700123 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700124 proc_filesystems
125 proc_kmsg
126 proc_loadavg
127 proc_mounts
128 proc_pagetypeinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700129 proc_stat
Dan Cashman91d398d2017-09-26 12:58:29 -0700130 proc_swaps
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700131 proc_uptime
Dan Cashman91d398d2017-09-26 12:58:29 -0700132 proc_version
133 proc_vmallocinfo
Jeff Vander Stoep886aa542018-03-28 15:34:37 -0700134 proc_vmstat
Dan Cashman91d398d2017-09-26 12:58:29 -0700135}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700136
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700137# Avoid all access to kernel configuration
138neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
139
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700140# Do not allow untrusted apps access to preloads data files
141neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700142
143# Locking of files on /system could lead to denial of service attacks
144# against privileged system components
145neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700146
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700147# Do not permit untrusted apps to perform actions on HwBinder service_manager
148# other than find actions for services listed below
149neverallow all_untrusted_apps *:hwservice_manager ~find;
150
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700151# Do not permit access from apps which host arbitrary code to HwBinder services,
152# except those considered sufficiently safe for access from such apps.
153# The two main reasons for this are:
154# 1. HwBinder servers do not perform client authentication because HIDL
155# currently does not expose caller UID information and, even if it did, many
156# HwBinder services either operate at a level below that of apps (e.g., HALs)
157# or must not rely on app identity for authorization. Thus, to be safe, the
158# default assumption is that every HwBinder service treats all its clients as
159# equally authorized to perform operations offered by the service.
160# 2. HAL servers (a subset of HwBinder services) contain code with higher
161# incidence rate of security issues than system/core components and have
162# access to lower layes of the stack (all the way down to hardware) thus
163# increasing opportunities for bypassing the Android security model.
Dan Cashman3e307a42017-06-21 10:00:32 -0700164#
165# Safe services include:
166# - same process services: because they by definition run in the process
167# of the client and thus have the same access as the client domain in which
168# the process runs
169# - coredomain_hwservice: are considered safe because they do not pose risks
170# associated with reason #2 above.
171# - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been
172# designed for use by any domain.
173# - hal_graphics_allocator_hwservice: because these operations are also offered
174# by surfaceflinger Binder service, which apps are permitted to access
175# - hal_omx_hwservice: because this is a HwBinder version of the mediacodec
176# Binder service which apps were permitted to access.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700177neverallow all_untrusted_apps {
178 hwservice_manager_type
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700179 -same_process_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700180 -coredomain_hwservice
181 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700182 -hal_graphics_allocator_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700183 -hal_omx_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700184 -hal_cas_hwservice
Michael Butlerea331aa2017-12-15 14:16:25 -0800185 -hal_neuralnetworks_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700186 -untrusted_app_visible_hwservice
187}:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700188
Dan Cashman3e307a42017-06-21 10:00:32 -0700189# Make sure that the following services are never accessible by untrusted_apps
190neverallow all_untrusted_apps {
191 default_android_hwservice
192 hal_audio_hwservice
Andrew Scull64f35fa2018-01-10 16:11:46 +0000193 hal_authsecret_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700194 hal_bluetooth_hwservice
195 hal_bootctl_hwservice
196 hal_camera_hwservice
Janis Danisevskis97c56bd2018-01-09 17:42:53 -0500197 hal_confirmationui_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700198 hal_contexthub_hwservice
199 hal_drm_hwservice
200 hal_dumpstate_hwservice
201 hal_fingerprint_hwservice
202 hal_gatekeeper_hwservice
203 hal_gnss_hwservice
204 hal_graphics_composer_hwservice
205 hal_health_hwservice
206 hal_ir_hwservice
207 hal_keymaster_hwservice
208 hal_light_hwservice
209 hal_memtrack_hwservice
210 hal_nfc_hwservice
211 hal_oemlock_hwservice
212 hal_power_hwservice
Ruchi Kandoi8a2b4a72018-01-04 10:33:20 -0800213 hal_secure_element_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700214 hal_sensors_hwservice
215 hal_telephony_hwservice
216 hal_thermal_hwservice
217 hal_tv_cec_hwservice
218 hal_tv_input_hwservice
219 hal_usb_hwservice
220 hal_vibrator_hwservice
221 hal_vr_hwservice
222 hal_weaver_hwservice
223 hal_wifi_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700224 hal_wifi_offload_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700225 hal_wifi_supplicant_hwservice
226 hidl_base_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700227 system_net_netd_hwservice
228 thermalcallback_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700229}:hwservice_manager find;
230# HwBinder services offered by core components (as opposed to vendor components)
231# are considered somewhat safer due to point #2 above.
232neverallow all_untrusted_apps {
233 coredomain_hwservice
234 -same_process_hwservice
235 -hidl_allocator_hwservice # Designed for use by any domain
236 -hidl_manager_hwservice # Designed for use by any domain
237 -hidl_memory_hwservice # Designed for use by any domain
238 -hidl_token_hwservice # Designed for use by any domain
239}:hwservice_manager find;
240
Dan Cashman91d398d2017-09-26 12:58:29 -0700241# SELinux is not an API for untrusted apps to use
242neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
243
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700244# Restrict *Binder access from apps to HAL domains. We can only do this on full
245# Treble devices where *Binder communications between apps and HALs are tightly
246# restricted.
247full_treble_only(`
248 neverallow all_untrusted_apps {
249 halserverdomain
250 -coredomain
251 -hal_configstore_server
252 -hal_graphics_allocator_server
Dan Cashman91d398d2017-09-26 12:58:29 -0700253 -hal_cas_server
Michael Butlerea331aa2017-12-15 14:16:25 -0800254 -hal_neuralnetworks_server
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700255 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
Dan Cashman91d398d2017-09-26 12:58:29 -0700256 -untrusted_app_visible_halserver
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700257 }:binder { call transfer };
258')
Dongwon Kang1134bd02017-11-06 11:19:07 -0800259
260# Untrusted apps are not allowed to find mediaextractor update service.
261neverallow all_untrusted_apps mediaextractor_update_service:service_manager find;