blob: c4cbfd859586c0843b7a587084b2379f1c50614f [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
39# Do not allow untrusted apps to be assigned mlstrustedsubject.
40# This would undermine the per-user isolation model being
41# enforced via levelFrom=user in seapp_contexts and the mls
42# constraints. As there is no direct way to specify a neverallow
43# on attribute assignment, this relies on the fact that fork
44# permission only makes sense within a domain (hence should
45# never be granted to any other domain within mlstrustedsubject)
46# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080047neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080048
49# Do not allow untrusted apps to hard link to any files.
50# In particular, if an untrusted app links to other app data
51# files, installd will not be able to guarantee the deletion
52# of the linked to file. Hard links also contribute to security
53# bugs, so we want to ensure untrusted apps never have this
54# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080055neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080056
57# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080058neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080059
Jeff Vander Stoep06cef4f2017-10-04 13:12:25 -070060# Do not allow any write access to files in /sys
61neverallow all_untrusted_apps sysfs_type:file no_w_file_perms;
62
Chad Brubaker46e5a062017-01-27 15:53:38 -080063# Restrict socket ioctls. Either 1. disallow privileged ioctls, 2. disallow the
64# ioctl permission, or 3. disallow the socket class.
Chad Brubakera782a812017-02-06 10:31:45 -080065neverallowxperm all_untrusted_apps domain:{ rawip_socket tcp_socket udp_socket } ioctl priv_sock_ioctls;
66neverallow all_untrusted_apps *:{ netlink_route_socket netlink_selinux_socket } ioctl;
67neverallow all_untrusted_apps *:{
Chad Brubaker46e5a062017-01-27 15:53:38 -080068 socket netlink_socket packet_socket key_socket appletalk_socket
Stephen Smalley49210852017-02-06 14:14:58 -050069 netlink_tcpdiag_socket netlink_nflog_socket
70 netlink_xfrm_socket netlink_audit_socket
Chad Brubaker46e5a062017-01-27 15:53:38 -080071 netlink_dnrt_socket netlink_kobject_uevent_socket tun_socket
72 netlink_iscsi_socket netlink_fib_lookup_socket netlink_connector_socket
73 netlink_netfilter_socket netlink_generic_socket netlink_scsitransport_socket
74 netlink_rdma_socket netlink_crypto_socket
75} *;
76
77# Do not allow untrusted apps access to /cache
Jerry Zhang9f152d92017-04-10 16:57:48 -070078neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:dir ~{ r_dir_perms };
79neverallow { all_untrusted_apps -mediaprovider } { cache_file cache_recovery_file }:file ~{ read getattr };
Chad Brubaker46e5a062017-01-27 15:53:38 -080080
81# Do not allow untrusted apps to create/unlink files outside of its sandbox,
82# internal storage or sdcard.
83# World accessible data locations allow application to fill the device
84# with unaccounted for data. This data will not get removed during
85# application un-installation.
Jerry Zhang9f152d92017-04-10 16:57:48 -070086neverallow { all_untrusted_apps -mediaprovider } {
Chad Brubaker46e5a062017-01-27 15:53:38 -080087 fs_type
88 -fuse # sdcard
89 -sdcardfs # sdcard
90 -vfat
91 file_type
92 -app_data_file # The apps sandbox itself
93 -media_rw_data_file # Internal storage. Known that apps can
94 # leave artfacts here after uninstall.
95 -user_profile_data_file # Access to profile files
Chad Brubaker46e5a062017-01-27 15:53:38 -080096 userdebug_or_eng(`
97 -method_trace_data_file # only on ro.debuggable=1
98 -coredump_file # userdebug/eng only
99 ')
100}:dir_file_class_set { create unlink };
101
Nick Kralevich45766d42017-04-26 11:40:48 -0700102# No untrusted component should be touching /dev/fuse
103neverallow all_untrusted_apps fuse_device:chr_file *;
104
Chad Brubaker46e5a062017-01-27 15:53:38 -0800105# Do not allow untrusted apps to directly open tun_device
Chad Brubakera782a812017-02-06 10:31:45 -0800106neverallow all_untrusted_apps tun_device:chr_file open;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800107
108# Only allow appending to /data/anr/traces.txt (b/27853304, b/18340553)
Chad Brubakera782a812017-02-06 10:31:45 -0800109neverallow all_untrusted_apps anr_data_file:file ~{ open append };
110neverallow all_untrusted_apps anr_data_file:dir ~search;
Chad Brubaker46e5a062017-01-27 15:53:38 -0800111
112# Avoid reads from generically labeled /proc files
113# Create a more specific label if needed
Dan Cashman91d398d2017-09-26 12:58:29 -0700114neverallow all_untrusted_apps {
115 proc
Tri Vo464f59a2017-10-06 10:20:53 -0700116 proc_asound
Dan Cashman91d398d2017-09-26 12:58:29 -0700117 proc_filesystems
118 proc_kmsg
119 proc_loadavg
120 proc_mounts
121 proc_pagetypeinfo
122 proc_swaps
123 proc_version
124 proc_vmallocinfo
125}:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700126
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700127# Avoid all access to kernel configuration
128neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
129
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700130# Do not allow untrusted apps access to preloads data files
131neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700132
133# Locking of files on /system could lead to denial of service attacks
134# against privileged system components
135neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700136
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700137# Do not permit untrusted apps to perform actions on HwBinder service_manager
138# other than find actions for services listed below
139neverallow all_untrusted_apps *:hwservice_manager ~find;
140
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700141# Do not permit access from apps which host arbitrary code to HwBinder services,
142# except those considered sufficiently safe for access from such apps.
143# The two main reasons for this are:
144# 1. HwBinder servers do not perform client authentication because HIDL
145# currently does not expose caller UID information and, even if it did, many
146# HwBinder services either operate at a level below that of apps (e.g., HALs)
147# or must not rely on app identity for authorization. Thus, to be safe, the
148# default assumption is that every HwBinder service treats all its clients as
149# equally authorized to perform operations offered by the service.
150# 2. HAL servers (a subset of HwBinder services) contain code with higher
151# incidence rate of security issues than system/core components and have
152# access to lower layes of the stack (all the way down to hardware) thus
153# increasing opportunities for bypassing the Android security model.
Dan Cashman3e307a42017-06-21 10:00:32 -0700154#
155# Safe services include:
156# - same process services: because they by definition run in the process
157# of the client and thus have the same access as the client domain in which
158# the process runs
159# - coredomain_hwservice: are considered safe because they do not pose risks
160# associated with reason #2 above.
161# - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been
162# designed for use by any domain.
163# - hal_graphics_allocator_hwservice: because these operations are also offered
164# by surfaceflinger Binder service, which apps are permitted to access
165# - hal_omx_hwservice: because this is a HwBinder version of the mediacodec
166# Binder service which apps were permitted to access.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700167neverallow all_untrusted_apps {
168 hwservice_manager_type
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700169 -same_process_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700170 -coredomain_hwservice
171 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700172 -hal_graphics_allocator_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700173 -hal_omx_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700174 -hal_cas_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700175 -untrusted_app_visible_hwservice
176}:hwservice_manager find;
Dan Cashman91d398d2017-09-26 12:58:29 -0700177
Dan Cashman3e307a42017-06-21 10:00:32 -0700178# Make sure that the following services are never accessible by untrusted_apps
179neverallow all_untrusted_apps {
180 default_android_hwservice
181 hal_audio_hwservice
182 hal_bluetooth_hwservice
183 hal_bootctl_hwservice
184 hal_camera_hwservice
185 hal_contexthub_hwservice
186 hal_drm_hwservice
187 hal_dumpstate_hwservice
188 hal_fingerprint_hwservice
189 hal_gatekeeper_hwservice
190 hal_gnss_hwservice
191 hal_graphics_composer_hwservice
192 hal_health_hwservice
193 hal_ir_hwservice
194 hal_keymaster_hwservice
195 hal_light_hwservice
196 hal_memtrack_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700197 hal_neuralnetworks_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700198 hal_nfc_hwservice
199 hal_oemlock_hwservice
200 hal_power_hwservice
201 hal_sensors_hwservice
202 hal_telephony_hwservice
203 hal_thermal_hwservice
204 hal_tv_cec_hwservice
205 hal_tv_input_hwservice
206 hal_usb_hwservice
207 hal_vibrator_hwservice
208 hal_vr_hwservice
209 hal_weaver_hwservice
210 hal_wifi_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700211 hal_wifi_offload_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700212 hal_wifi_supplicant_hwservice
213 hidl_base_hwservice
Dan Cashman91d398d2017-09-26 12:58:29 -0700214 system_net_netd_hwservice
215 thermalcallback_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700216}:hwservice_manager find;
217# HwBinder services offered by core components (as opposed to vendor components)
218# are considered somewhat safer due to point #2 above.
219neverallow all_untrusted_apps {
220 coredomain_hwservice
221 -same_process_hwservice
222 -hidl_allocator_hwservice # Designed for use by any domain
223 -hidl_manager_hwservice # Designed for use by any domain
224 -hidl_memory_hwservice # Designed for use by any domain
225 -hidl_token_hwservice # Designed for use by any domain
226}:hwservice_manager find;
227
Dan Cashman91d398d2017-09-26 12:58:29 -0700228# SELinux is not an API for untrusted apps to use
229neverallow all_untrusted_apps selinuxfs:file no_rw_file_perms;
230
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700231# Restrict *Binder access from apps to HAL domains. We can only do this on full
232# Treble devices where *Binder communications between apps and HALs are tightly
233# restricted.
234full_treble_only(`
235 neverallow all_untrusted_apps {
236 halserverdomain
237 -coredomain
238 -hal_configstore_server
239 -hal_graphics_allocator_server
Dan Cashman91d398d2017-09-26 12:58:29 -0700240 -hal_cas_server
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700241 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
Dan Cashman91d398d2017-09-26 12:58:29 -0700242 -untrusted_app_visible_halserver
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700243 }:binder { call transfer };
244')