blob: 847d92c80231acc1e1b65dbc7b209f6562cbfd5b [file] [log] [blame]
Chad Brubaker46e5a062017-01-27 15:53:38 -08001###
2### neverallow rules for untrusted app domains
3###
4
Jeff Vander Stoepbacb6d72017-02-13 13:33:27 -08005# Only allow domains in AOSP to use the untrusted_app_all attribute.
6neverallow { untrusted_app_all -untrusted_app -untrusted_app_25 } domain:process fork;
7
Nick Kralevichdb5962c2017-04-26 16:14:40 -07008define(`all_untrusted_apps',`{
9 ephemeral_app
10 isolated_app
11 mediaprovider
12 untrusted_app
13 untrusted_app_25
14 untrusted_app_all
15 untrusted_v2_app
16}')
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
23# Too much leaky information in debugfs. It's a security
24# best practice to ensure these files aren't readable.
Chad Brubakera782a812017-02-06 10:31:45 -080025neverallow all_untrusted_apps debugfs_type:file read;
Chad Brubaker46e5a062017-01-27 15:53:38 -080026
27# Do not allow untrusted apps to register services.
28# Only trusted components of Android should be registering
29# services.
Chad Brubakera782a812017-02-06 10:31:45 -080030neverallow all_untrusted_apps service_manager_type:service_manager add;
Chad Brubaker46e5a062017-01-27 15:53:38 -080031
Alex Klyubin00657832017-04-25 09:27:54 -070032# Do not allow untrusted apps to use VendorBinder
33neverallow all_untrusted_apps vndbinder_device:chr_file *;
34neverallow all_untrusted_apps vndservice_manager_type:service_manager *;
35
Chad Brubaker46e5a062017-01-27 15:53:38 -080036# Do not allow untrusted apps to connect to the property service
37# or set properties. b/10243159
Jerry Zhang9f152d92017-04-10 16:57:48 -070038neverallow { all_untrusted_apps -mediaprovider } property_socket:sock_file write;
39neverallow { all_untrusted_apps -mediaprovider } init:unix_stream_socket connectto;
40neverallow { all_untrusted_apps -mediaprovider } property_type:property_service set;
Chad Brubaker46e5a062017-01-27 15:53:38 -080041
42# Do not allow untrusted apps to be assigned mlstrustedsubject.
43# This would undermine the per-user isolation model being
44# enforced via levelFrom=user in seapp_contexts and the mls
45# constraints. As there is no direct way to specify a neverallow
46# on attribute assignment, this relies on the fact that fork
47# permission only makes sense within a domain (hence should
48# never be granted to any other domain within mlstrustedsubject)
49# and an untrusted app is allowed fork permission to itself.
Chad Brubakera782a812017-02-06 10:31:45 -080050neverallow all_untrusted_apps mlstrustedsubject:process fork;
Chad Brubaker46e5a062017-01-27 15:53:38 -080051
52# Do not allow untrusted apps to hard link to any files.
53# In particular, if an untrusted app links to other app data
54# files, installd will not be able to guarantee the deletion
55# of the linked to file. Hard links also contribute to security
56# bugs, so we want to ensure untrusted apps never have this
57# capability.
Chad Brubakera782a812017-02-06 10:31:45 -080058neverallow all_untrusted_apps file_type:file link;
Chad Brubaker46e5a062017-01-27 15:53:38 -080059
60# Do not allow untrusted apps to access network MAC address file
Chad Brubakera782a812017-02-06 10:31:45 -080061neverallow all_untrusted_apps sysfs_mac_address:file no_rw_file_perms;
Chad Brubaker46e5a062017-01-27 15:53:38 -080062
63# 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
Chad Brubakera782a812017-02-06 10:31:45 -0800114neverallow all_untrusted_apps proc:file { no_rw_file_perms no_x_file_perms };
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700115
Sandeep Patil2da9cfd2017-04-21 11:25:29 -0700116# Avoid all access to kernel configuration
117neverallow all_untrusted_apps config_gz:file { no_rw_file_perms no_x_file_perms };
118
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700119# Do not allow untrusted apps access to preloads data files
120neverallow all_untrusted_apps preloads_data_file:file no_rw_file_perms;
Nick Kralevich92c44a52017-03-22 10:35:24 -0700121
122# Locking of files on /system could lead to denial of service attacks
123# against privileged system components
124neverallow all_untrusted_apps system_file:file lock;
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700125
Alex Klyubin5c5b6262017-04-24 15:09:19 -0700126# Do not permit untrusted apps to perform actions on HwBinder service_manager
127# other than find actions for services listed below
128neverallow all_untrusted_apps *:hwservice_manager ~find;
129
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700130# Do not permit access from apps which host arbitrary code to HwBinder services,
131# except those considered sufficiently safe for access from such apps.
132# The two main reasons for this are:
133# 1. HwBinder servers do not perform client authentication because HIDL
134# currently does not expose caller UID information and, even if it did, many
135# HwBinder services either operate at a level below that of apps (e.g., HALs)
136# or must not rely on app identity for authorization. Thus, to be safe, the
137# default assumption is that every HwBinder service treats all its clients as
138# equally authorized to perform operations offered by the service.
139# 2. HAL servers (a subset of HwBinder services) contain code with higher
140# incidence rate of security issues than system/core components and have
141# access to lower layes of the stack (all the way down to hardware) thus
142# increasing opportunities for bypassing the Android security model.
Dan Cashman3e307a42017-06-21 10:00:32 -0700143#
144# Safe services include:
145# - same process services: because they by definition run in the process
146# of the client and thus have the same access as the client domain in which
147# the process runs
148# - coredomain_hwservice: are considered safe because they do not pose risks
149# associated with reason #2 above.
150# - hal_configstore_ISurfaceFlingerConfigs: becuase it has specifically been
151# designed for use by any domain.
152# - hal_graphics_allocator_hwservice: because these operations are also offered
153# by surfaceflinger Binder service, which apps are permitted to access
154# - hal_omx_hwservice: because this is a HwBinder version of the mediacodec
155# Binder service which apps were permitted to access.
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700156neverallow all_untrusted_apps {
157 hwservice_manager_type
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700158 -same_process_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700159 -coredomain_hwservice
160 -hal_configstore_ISurfaceFlingerConfigs
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700161 -hal_graphics_allocator_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700162 -hal_omx_hwservice
Dan Cashman3e307a42017-06-21 10:00:32 -0700163 -untrusted_app_visible_hwservice
164}:hwservice_manager find;
165neverallow untrusted_app_visible_hwservice unlabeled:service_manager list; #TODO: b/62658302
166# Make sure that the following services are never accessible by untrusted_apps
167neverallow all_untrusted_apps {
168 default_android_hwservice
169 hal_audio_hwservice
170 hal_bluetooth_hwservice
171 hal_bootctl_hwservice
172 hal_camera_hwservice
173 hal_contexthub_hwservice
174 hal_drm_hwservice
175 hal_dumpstate_hwservice
176 hal_fingerprint_hwservice
177 hal_gatekeeper_hwservice
178 hal_gnss_hwservice
179 hal_graphics_composer_hwservice
180 hal_health_hwservice
181 hal_ir_hwservice
182 hal_keymaster_hwservice
183 hal_light_hwservice
184 hal_memtrack_hwservice
185 hal_nfc_hwservice
186 hal_oemlock_hwservice
187 hal_power_hwservice
188 hal_sensors_hwservice
189 hal_telephony_hwservice
190 hal_thermal_hwservice
191 hal_tv_cec_hwservice
192 hal_tv_input_hwservice
193 hal_usb_hwservice
194 hal_vibrator_hwservice
195 hal_vr_hwservice
196 hal_weaver_hwservice
197 hal_wifi_hwservice
198 hal_wifi_supplicant_hwservice
199 hidl_base_hwservice
Alex Klyubin2a7f4fb2017-04-21 17:06:43 -0700200}:hwservice_manager find;
201# HwBinder services offered by core components (as opposed to vendor components)
202# are considered somewhat safer due to point #2 above.
203neverallow all_untrusted_apps {
204 coredomain_hwservice
205 -same_process_hwservice
206 -hidl_allocator_hwservice # Designed for use by any domain
207 -hidl_manager_hwservice # Designed for use by any domain
208 -hidl_memory_hwservice # Designed for use by any domain
209 -hidl_token_hwservice # Designed for use by any domain
210}:hwservice_manager find;
211
212# Restrict *Binder access from apps to HAL domains. We can only do this on full
213# Treble devices where *Binder communications between apps and HALs are tightly
214# restricted.
215full_treble_only(`
216 neverallow all_untrusted_apps {
217 halserverdomain
218 -coredomain
219 -hal_configstore_server
220 -hal_graphics_allocator_server
221 -binder_in_vendor_violators # TODO(b/35870313): Remove once all violations are gone
222 }:binder { call transfer };
223')