blob: c776907e36286e5fcde1c128c46f348a04cc8d68 [file] [log] [blame]
Alex Klyubin92295ef2017-01-05 15:44:32 -08001###
2### A domain for further sandboxing privileged apps.
3###
4
Alex Klyubinf5446eb2017-03-23 14:27:32 -07005typeattribute priv_app coredomain;
dcashman3e8dbf02016-12-08 11:23:34 -08006app_domain(priv_app)
dcashman2e00e632016-10-12 14:58:09 -07007
Alex Klyubin92295ef2017-01-05 15:44:32 -08008# Access the network.
9net_domain(priv_app)
10# Access bluetooth.
11bluetooth_domain(priv_app)
12
dcashman2e00e632016-10-12 14:58:09 -070013# Allow the allocation and use of ptys
14# Used by: https://play.privileged.com/store/apps/details?id=jackpal.androidterm
15create_pty(priv_app)
Alex Klyubin92295ef2017-01-05 15:44:32 -080016
17# webview crash handling depends on self ptrace (b/27697529, b/20150694, b/19277529#comment7)
18allow priv_app self:process ptrace;
19
Nick Kraleviche1ddd742018-10-27 15:20:38 -070020# Allow loading executable code from writable priv-app home
21# directories. This is a W^X violation, however, it needs
22# to be supported for now for the following reasons.
23# * /data/user_*/0/*/code_cache/* POSSIBLE uses (b/117841367)
24# 1) com.android.opengl.shaders_cache
25# 2) com.android.skia.shaders_cache
26# 3) com.android.renderscript.cache
27# * /data/user_de/0/com.google.android.gms/app_chimera
28# TODO: Tighten (b/112357170)
29allow priv_app privapp_data_file:file execute;
Ashwini Orugantie6ed1272019-11-26 11:02:31 -080030# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
31userdebug_or_eng(`
32 auditallow priv_app privapp_data_file:file execute;
33')
Alex Klyubin92295ef2017-01-05 15:44:32 -080034
Nick Kralevich87e91232019-01-24 13:05:03 -080035allow priv_app privapp_data_file:lnk_file create_file_perms;
36
Alan Stokes5c378a52019-03-21 23:52:30 +000037# Priv apps can find services that expose both @SystemAPI and normal APIs.
yro31b11d82018-01-09 11:27:36 -080038allow priv_app app_api_service:service_manager find;
Alan Stokes5c378a52019-03-21 23:52:30 +000039allow priv_app system_api_service:service_manager find;
40
Alex Klyubin92295ef2017-01-05 15:44:32 -080041allow priv_app audioserver_service:service_manager find;
42allow priv_app cameraserver_service:service_manager find;
43allow priv_app drmserver_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080044allow priv_app mediadrmserver_service:service_manager find;
45allow priv_app mediaextractor_service:service_manager find;
yro31b11d82018-01-09 11:27:36 -080046allow priv_app mediametrics_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080047allow priv_app mediaserver_service:service_manager find;
Ricky Waic6352972017-11-13 17:52:05 +000048allow priv_app network_watchlist_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080049allow priv_app nfc_service:service_manager find;
Andrew Scull37174242017-02-17 13:51:32 +000050allow priv_app oem_lock_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080051allow priv_app persistent_data_block_service:service_manager find;
yro31b11d82018-01-09 11:27:36 -080052allow priv_app radio_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080053allow priv_app recovery_service:service_manager find;
yro31b11d82018-01-09 11:27:36 -080054allow priv_app stats_service:service_manager find;
Mark Chien9dfaa7d2019-11-11 21:30:23 +090055allow priv_app tethering_service:service_manager find;
Yiwei Zhang544d6b32019-02-07 15:00:55 -080056
57# Allow privileged apps to interact with gpuservice
58binder_call(priv_app, gpuservice)
Alan Stokes5c378a52019-03-21 23:52:30 +000059allow priv_app gpu_service:service_manager find;
Alex Klyubin92295ef2017-01-05 15:44:32 -080060
61# Write to /cache.
62allow priv_app { cache_file cache_recovery_file }:dir create_dir_perms;
63allow priv_app { cache_file cache_recovery_file }:file create_file_perms;
Nick Kralevich21cb0452017-01-23 22:19:06 -080064# /cache is a symlink to /data/cache on some devices. Allow reading the link.
65allow priv_app cache_file:lnk_file r_file_perms;
Alex Klyubin92295ef2017-01-05 15:44:32 -080066
67# Write to /data/ota_package for OTA packages.
68allow priv_app ota_package_file:dir rw_dir_perms;
69allow priv_app ota_package_file:file create_file_perms;
70
71# Access to /data/media.
72allow priv_app media_rw_data_file:dir create_dir_perms;
73allow priv_app media_rw_data_file:file create_file_perms;
74
75# Used by Finsky / Android "Verify Apps" functionality when
76# running "adb install foo.apk".
77allow priv_app shell_data_file:file r_file_perms;
78allow priv_app shell_data_file:dir r_dir_perms;
79
Max Bires715e2ae2018-03-13 09:56:27 -070080# Allow traceur to pass file descriptors through a content provider to betterbug
81allow priv_app trace_data_file:file { getattr read };
82
Alex Klyubin92295ef2017-01-05 15:44:32 -080083# Allow verifier to access staged apks.
84allow priv_app { apk_tmp_file apk_private_tmp_file }:dir r_dir_perms;
85allow priv_app { apk_tmp_file apk_private_tmp_file }:file r_file_perms;
86
87# b/18504118: Allow reads from /data/anr/traces.txt
88allow priv_app anr_data_file:file r_file_perms;
89
Alex Klyubin92295ef2017-01-05 15:44:32 -080090# For AppFuse.
91allow priv_app vold:fd use;
92allow priv_app fuse_device:chr_file { read write };
93
Tri Vof92cfb92017-12-08 15:37:01 -080094# /proc access
95allow priv_app {
96 proc_vmstat
97}:file r_file_perms;
98
99allow priv_app sysfs_type:dir search;
100# Read access to /sys/class/net/wlan*/address
101r_dir_file(priv_app, sysfs_net)
102# Read access to /sys/block/zram*/mm_stat
103r_dir_file(priv_app, sysfs_zram)
104
Alex Klyubin92295ef2017-01-05 15:44:32 -0800105r_dir_file(priv_app, rootfs)
106
Sandeep Patil04654422017-04-19 11:35:15 -0700107# Allow GMS core to open kernel config for OTA matching through libvintf
108allow priv_app config_gz:file { open read getattr };
Ashwini Orugantie6ed1272019-11-26 11:02:31 -0800109# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
110userdebug_or_eng(`
111 auditallow priv_app config_gz:file { open read getattr };
112')
Sandeep Patil04654422017-04-19 11:35:15 -0700113
Alex Klyubin92295ef2017-01-05 15:44:32 -0800114# access the mac address
115allowxperm priv_app self:udp_socket ioctl SIOCGIFHWADDR;
116
117# Allow GMS core to communicate with update_engine for A/B update.
118binder_call(priv_app, update_engine)
119allow priv_app update_engine_service:service_manager find;
Ashwini Orugantie6ed1272019-11-26 11:02:31 -0800120# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
121userdebug_or_eng(`
122 auditallow priv_app update_engine:binder { call transfer };
123 auditallow update_engine priv_app:binder transfer;
124 auditallow priv_app update_engine:fd use;
125 auditallow priv_app update_engine_service:service_manager find;
126')
Alex Klyubin92295ef2017-01-05 15:44:32 -0800127
Jin Qian00a17892017-04-12 17:38:11 -0700128# Allow GMS core to communicate with dumpsys storaged.
129binder_call(priv_app, storaged)
130allow priv_app storaged_service:service_manager find;
Ashwini Orugantie6ed1272019-11-26 11:02:31 -0800131# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
132userdebug_or_eng(`
133 auditallow priv_app storaged:binder { call transfer };
134 auditallow storaged priv_app:binder transfer;
135 auditallow priv_app storaged:fd use;
136 auditallow priv_app storaged_service:service_manager find;
137')
138
Jin Qian00a17892017-04-12 17:38:11 -0700139
Tao Baod7d9cfc2017-10-16 21:57:12 -0700140# Allow GMS core to access system_update_service (e.g. to publish pending
141# system update info).
142allow priv_app system_update_service:service_manager find;
Ashwini Orugantie6ed1272019-11-26 11:02:31 -0800143# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
144userdebug_or_eng(`
145 auditallow priv_app system_update_service:service_manager find;
146')
Tao Baod7d9cfc2017-10-16 21:57:12 -0700147
yro31b11d82018-01-09 11:27:36 -0800148# Allow GMS core to communicate with statsd.
149binder_call(priv_app, statsd)
Ashwini Orugantie6ed1272019-11-26 11:02:31 -0800150# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
151userdebug_or_eng(`
152 auditallow priv_app statsd:binder { call transfer };
153 auditallow statsd priv_app:binder transfer;
154 auditallow priv_app statsd:fd use;
155')
yro31b11d82018-01-09 11:27:36 -0800156
Alex Klyubin92295ef2017-01-05 15:44:32 -0800157# Allow Phone to read/write cached ringtones (opened by system).
158allow priv_app ringtone_file:file { getattr read write };
159
160# Access to /data/preloads
161allow priv_app preloads_data_file:file r_file_perms;
162allow priv_app preloads_data_file:dir r_dir_perms;
Fyodor Kupolovb238fe62017-03-14 11:42:03 -0700163allow priv_app preloads_media_file:file r_file_perms;
164allow priv_app preloads_media_file:dir r_dir_perms;
Alex Klyubin92295ef2017-01-05 15:44:32 -0800165
Shawn Willdena0c7f012017-04-11 09:41:25 -0600166# Allow privileged apps (e.g. GMS core) to generate unique hardware IDs
167allow priv_app keystore:keystore_key gen_unique_id;
Ashwini Orugantie6ed1272019-11-26 11:02:31 -0800168# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
169userdebug_or_eng(`
170 auditallow priv_app keystore:keystore_key gen_unique_id;
171')
Shawn Willdena0c7f012017-04-11 09:41:25 -0600172
Dan Cashman91d398d2017-09-26 12:58:29 -0700173# Allow GMS core to access /sys/fs/selinux/policyvers for compatibility check
174allow priv_app selinuxfs:file r_file_perms;
Ashwini Orugantie6ed1272019-11-26 11:02:31 -0800175# b/142672293: No other priv-app should need this allow rule now that GMS core runs in its own domain.
176userdebug_or_eng(`
177 auditallow priv_app selinuxfs:file r_file_perms;
178')
Dan Cashman91d398d2017-09-26 12:58:29 -0700179
Mark Salyzynd33a9a12016-11-07 15:11:39 -0800180read_runtime_log_tags(priv_app)
181
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100182# Write app-specific trace data to the Perfetto traced damon. This requires
183# connecting to its producer socket and obtaining a (per-process) tmpfs fd.
Florian Mayer5e522812019-10-08 16:15:14 +0100184perfetto_producer(priv_app)
Primiano Tuccic80f9e02017-12-21 03:51:15 +0100185
Joe Onorato9cc5c092019-03-16 15:45:45 -0700186# Allow priv_apps to request and collect incident reports.
187# (Also requires DUMP and PACKAGE_USAGE_STATS permissions)
188allow priv_app incident_service:service_manager find;
189binder_call(priv_app, incidentd)
190allow priv_app incidentd:fifo_file { read write };
191
Ryan Savitskica0690e2019-01-16 16:29:43 +0000192# Allow heap profiling if the app opts in by being marked
193# profileable/debuggable.
194can_profile_heap(priv_app)
195
Hung-ying Tyan565384d2019-04-26 16:14:52 +0800196# Allow priv_apps to check whether Dynamic System Update is enabled
197get_prop(priv_app, dynamic_system_prop)
198
Jeff Vander Stoep6d8a8762018-01-18 08:55:02 -0800199# suppress denials for non-API accesses.
Dan Cashman91d398d2017-09-26 12:58:29 -0700200dontaudit priv_app exec_type:file getattr;
Jeff Vander Stoep62338482017-10-20 13:35:42 -0700201dontaudit priv_app device:dir read;
Joel Galenson9ec59f62018-04-20 15:27:21 -0700202dontaudit priv_app fs_bpf:dir search;
Jeff Vander Stoep9dc1d532018-04-04 14:36:13 -0700203dontaudit priv_app net_dns_prop:file read;
Tri Vof92cfb92017-12-08 15:37:01 -0800204dontaudit priv_app proc:file read;
Jeff Vander Stoep62338482017-10-20 13:35:42 -0700205dontaudit priv_app proc_interrupts:file read;
206dontaudit priv_app proc_modules:file read;
Tri Voe319c032019-05-09 16:14:04 -0700207dontaudit priv_app proc_net:file read;
Jeff Vander Stoepe88d6492018-01-29 20:50:59 -0800208dontaudit priv_app proc_stat:file read;
Jeff Vander Stoep6d8a8762018-01-18 08:55:02 -0800209dontaudit priv_app proc_version:file read;
Jeff Vander Stoep9dc1d532018-04-04 14:36:13 -0700210dontaudit priv_app sysfs:dir read;
Jeff Vander Stoep4894d9f2018-06-29 11:04:24 -0700211dontaudit priv_app sysfs:file read;
Jeff Vander Stoep9dc1d532018-04-04 14:36:13 -0700212dontaudit priv_app sysfs_android_usb:file read;
Jeff Vander Stoep90bd1de2019-10-25 11:01:40 +0200213dontaudit priv_app sysfs_dm:file r_file_perms;
Jeff Vander Stoep6d8a8762018-01-18 08:55:02 -0800214dontaudit priv_app wifi_prop:file read;
Jaekyun Seok224921d2018-04-09 12:07:32 +0900215dontaudit priv_app { wifi_prop exported_wifi_prop }:file read;
Dan Cashman91d398d2017-09-26 12:58:29 -0700216
Nathan Haroldee268642017-12-14 18:20:30 -0800217# allow privileged apps to use UDP sockets provided by the system server but not
218# modify them other than to connect
Nathan Harold252b0152018-03-27 06:34:54 -0700219allow priv_app system_server:udp_socket {
220 connect getattr read recvfrom sendto write getopt setopt };
Nathan Haroldee268642017-12-14 18:20:30 -0800221
Jeff Vander Stoep9c7396d2018-06-01 12:12:11 -0700222# Attempts to write to system_data_file is generally a sign
223# that apps are attempting to access encrypted storage before
224# the ACTION_USER_UNLOCKED intent is delivered. Suppress this
225# denial to prevent apps from spamming the logs.
226dontaudit priv_app system_data_file:dir write;
227
Alex Klyubin92295ef2017-01-05 15:44:32 -0800228###
229### neverallow rules
230###
231
232# Receive or send uevent messages.
233neverallow priv_app domain:netlink_kobject_uevent_socket *;
234
235# Receive or send generic netlink messages
236neverallow priv_app domain:netlink_socket *;
237
238# Too much leaky information in debugfs. It's a security
239# best practice to ensure these files aren't readable.
240neverallow priv_app debugfs:file read;
241
242# Do not allow privileged apps to register services.
243# Only trusted components of Android should be registering
244# services.
245neverallow priv_app service_manager_type:service_manager add;
246
247# Do not allow privileged apps to connect to the property service
248# or set properties. b/10243159
249neverallow priv_app property_socket:sock_file write;
250neverallow priv_app init:unix_stream_socket connectto;
251neverallow priv_app property_type:property_service set;
252
253# Do not allow priv_app to be assigned mlstrustedsubject.
254# This would undermine the per-user isolation model being
255# enforced via levelFrom=user in seapp_contexts and the mls
256# constraints. As there is no direct way to specify a neverallow
257# on attribute assignment, this relies on the fact that fork
258# permission only makes sense within a domain (hence should
259# never be granted to any other domain within mlstrustedsubject)
260# and priv_app is allowed fork permission to itself.
261neverallow priv_app mlstrustedsubject:process fork;
262
263# Do not allow priv_app to hard link to any files.
264# In particular, if priv_app links to other app data
265# files, installd will not be able to guarantee the deletion
266# of the linked to file. Hard links also contribute to security
267# bugs, so we want to ensure priv_app never has this
268# capability.
269neverallow priv_app file_type:file link;
Max Bires715e2ae2018-03-13 09:56:27 -0700270
271# priv apps should not be able to open trace data files, they should depend
272# upon traceur to pass a file descriptor which they can then read
273neverallow priv_app trace_data_file:dir *;
274neverallow priv_app trace_data_file:file { no_w_file_perms open };
Tri Vof55c9892018-10-10 22:48:15 +0000275
276# Do not allow priv_app access to cgroups.
277neverallow priv_app cgroup:file *;
Nick Kraleviche1ddd742018-10-27 15:20:38 -0700278
279# Do not allow loading executable code from non-privileged
280# application home directories. Code loading across a security boundary
281# is dangerous and allows a full compromise of a privileged process
282# by an unprivileged process. b/112357170
283neverallow priv_app app_data_file:file no_x_file_perms;
Nick Kralevich87e91232019-01-24 13:05:03 -0800284
285# Do not follow untrusted app provided symlinks
286neverallow priv_app app_data_file:lnk_file { open read getattr };