1###
2### Domain for all zygote spawned apps
3###
4### This file is the base policy for all zygote spawned apps.
5### Other policy files, such as isolated_app.te, untrusted_app.te, etc
6### extend from this policy. Only policies which should apply to ALL
7### zygote spawned apps should be added here.
8###
9
10# TODO: deal with tmpfs_domain pub/priv split properly
11# Read system properties managed by zygote.
12allow appdomain zygote_tmpfs:file read;
13
14# WebView and other application-specific JIT compilers
15allow appdomain self:process execmem;
16
17allow appdomain ashmem_device:chr_file execute;
18
19# Receive and use open file descriptors inherited from zygote.
20allow appdomain zygote:fd use;
21
22# gdbserver for ndk-gdb reads the zygote.
23# valgrind needs mmap exec for zygote
24allow appdomain zygote_exec:file rx_file_perms;
25
26# Notify zygote of death;
27allow appdomain zygote:process sigchld;
28
29# Place process into foreground / background
30allow appdomain cgroup:dir { search write };
31allow appdomain cgroup:file rw_file_perms;
32
33# Read /data/dalvik-cache.
34allow appdomain dalvikcache_data_file:dir { search getattr };
35allow appdomain dalvikcache_data_file:file r_file_perms;
36
37# Read the /sdcard and /mnt/sdcard symlinks
38allow { appdomain -isolated_app } rootfs:lnk_file r_file_perms;
39allow { appdomain -isolated_app } tmpfs:lnk_file r_file_perms;
40
41# Search /storage/emulated tmpfs mount.
42allow appdomain tmpfs:dir r_dir_perms;
43
44# Notify zygote of the wrapped process PID when using --invoke-with.
45allow appdomain zygote:fifo_file write;
46
47userdebug_or_eng(`
48  # Allow apps to create and write method traces in /data/misc/trace.
49  allow appdomain method_trace_data_file:dir w_dir_perms;
50  allow appdomain method_trace_data_file:file { create w_file_perms };
51')
52
53# Notify shell and adbd of death when spawned via runas for ndk-gdb.
54allow appdomain shell:process sigchld;
55allow appdomain adbd:process sigchld;
56
57# child shell or gdbserver pty access for runas.
58allow appdomain devpts:chr_file { getattr read write ioctl };
59
60# Use pipes and sockets provided by system_server via binder or local socket.
61allow appdomain system_server:fd use;
62allow appdomain system_server:fifo_file rw_file_perms;
63allow appdomain system_server:unix_stream_socket { read write setopt getattr getopt shutdown };
64allow appdomain system_server:tcp_socket { read write getattr getopt shutdown };
65
66# Communication with other apps via fifos
67allow appdomain appdomain:fifo_file rw_file_perms;
68
69# Communicate with surfaceflinger.
70allow appdomain surfaceflinger:unix_stream_socket { read write setopt getattr getopt shutdown };
71
72# App sandbox file accesses.
73allow { appdomain -isolated_app } app_data_file:dir create_dir_perms;
74allow { appdomain -isolated_app } app_data_file:notdevfile_class_set create_file_perms;
75
76# Traverse into expanded storage
77allow appdomain mnt_expand_file:dir r_dir_perms;
78
79# Keychain and user-trusted credentials
80r_dir_file(appdomain, keychain_data_file)
81allow appdomain misc_user_data_file:dir r_dir_perms;
82allow appdomain misc_user_data_file:file r_file_perms;
83
84# TextClassifier
85r_dir_file({ appdomain -isolated_app }, textclassifier_data_file)
86
87# Access to OEM provided data and apps
88allow appdomain oemfs:dir r_dir_perms;
89allow appdomain oemfs:file rx_file_perms;
90
91# Execute the shell or other system executables.
92allow { appdomain -ephemeral_app -untrusted_v2_app } shell_exec:file rx_file_perms;
93allow { appdomain -ephemeral_app -untrusted_v2_app } toolbox_exec:file rx_file_perms;
94allow { appdomain -ephemeral_app -untrusted_v2_app } system_file:file x_file_perms;
95not_full_treble(`allow { appdomain -ephemeral_app -untrusted_v2_app } vendor_file:file x_file_perms;')
96
97# Renderscript needs the ability to read directories on /system
98allow appdomain system_file:dir r_dir_perms;
99allow appdomain system_file:lnk_file { getattr open read };
100# Renderscript specific permissions to open /system/vendor/lib64.
101not_full_treble(`
102    allow appdomain vendor_file_type:dir r_dir_perms;
103    allow appdomain vendor_file_type:lnk_file { getattr open read };
104')
105
106full_treble_only(`
107    # For looking up Renderscript vendor drivers
108    allow { appdomain -isolated_app } vendor_file:dir { open read };
109')
110
111# Allow apps access to /vendor/app except for privileged
112# apps which cannot be in /vendor.
113r_dir_file({ appdomain -ephemeral_app -untrusted_v2_app }, vendor_app_file)
114allow { appdomain -ephemeral_app -untrusted_v2_app } vendor_app_file:file execute;
115
116# Allow apps access to /vendor/overlay
117r_dir_file(appdomain, vendor_overlay_file)
118
119# Allow apps access to /vendor/framework
120# for vendor provided libraries.
121r_dir_file(appdomain, vendor_framework_file)
122
123# Execute dex2oat when apps call dexclassloader
124allow appdomain dex2oat_exec:file rx_file_perms;
125
126# Read/write wallpaper file (opened by system).
127allow appdomain wallpaper_file:file { getattr read write };
128
129# Read/write cached ringtones (opened by system).
130allow appdomain ringtone_file:file { getattr read write };
131
132# Read ShortcutManager icon files (opened by system).
133allow appdomain shortcut_manager_icons:file { getattr read };
134
135# Read icon file (opened by system).
136allow appdomain icon_file:file { getattr read };
137
138# Old stack dumping scheme : append to a global trace file (/data/anr/traces.txt).
139#
140# TODO: All of these permissions except for anr_data_file:file append can be
141# withdrawn once we've switched to the new stack dumping mechanism, see b/32064548
142# and the rules below.
143allow appdomain anr_data_file:dir search;
144allow appdomain anr_data_file:file { open append };
145
146# New stack dumping scheme : request an output FD from tombstoned via a unix
147# domain socket.
148#
149# Allow apps to connect and write to the tombstoned java trace socket in
150# order to dump their traces. Also allow them to append traces to pipes
151# created by dumptrace. (Also see the rules below where they are given
152# additional permissions to dumpstate pipes for other aspects of bug report
153# creation).
154unix_socket_connect(appdomain, tombstoned_java_trace, tombstoned)
155allow appdomain tombstoned:fd use;
156allow appdomain dumpstate:fifo_file append;
157
158# Allow apps to send dump information to dumpstate
159allow appdomain dumpstate:fd use;
160allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown };
161allow appdomain dumpstate:fifo_file { write getattr };
162allow appdomain shell_data_file:file { write getattr };
163
164# Write profiles /data/misc/profiles
165allow appdomain user_profile_data_file:dir { search write add_name };
166allow appdomain user_profile_data_file:file create_file_perms;
167
168# Send heap dumps to system_server via an already open file descriptor
169# % adb shell am set-watch-heap com.android.systemui 1048576
170# % adb shell dumpsys procstats --start-testing
171# debuggable builds only.
172userdebug_or_eng(`
173  allow appdomain heapdump_data_file:file append;
174')
175
176# Write to /proc/net/xt_qtaguid/ctrl file.
177allow appdomain qtaguid_proc:file rw_file_perms;
178# read /proc/net/xt_qtguid/stats
179r_dir_file({ appdomain -ephemeral_app}, proc_net)
180# Everybody can read the xt_qtaguid resource tracking misc dev.
181# So allow all apps to read from /dev/xt_qtaguid.
182allow appdomain qtaguid_device:chr_file r_file_perms;
183
184# Grant GPU access to all processes started by Zygote.
185# They need that to render the standard UI.
186allow { appdomain -isolated_app } gpu_device:chr_file rw_file_perms;
187
188# Use the Binder.
189binder_use(appdomain)
190# Perform binder IPC to binder services.
191binder_call(appdomain, binderservicedomain)
192# Perform binder IPC to other apps.
193binder_call(appdomain, appdomain)
194# Perform binder IPC to ephemeral apps.
195binder_call(appdomain, ephemeral_app)
196
197# TODO(b/36375899): Replace this with hal_client_domain once mediacodec is properly attributized
198# as OMX HAL
199hwbinder_use({ appdomain  -isolated_app })
200allow { appdomain -isolated_app } hal_omx_hwservice:hwservice_manager find;
201allow { appdomain -isolated_app } hidl_token_hwservice:hwservice_manager find;
202
203# Talk with graphics composer fences
204allow appdomain hal_graphics_composer:fd use;
205
206# Already connected, unnamed sockets being passed over some other IPC
207# hence no sock_file or connectto permission. This appears to be how
208# Chrome works, may need to be updated as more apps using isolated services
209# are examined.
210allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown };
211
212# Backup ability for every app. BMS opens and passes the fd
213# to any app that has backup ability. Hence, no open permissions here.
214allow appdomain backup_data_file:file { read write getattr };
215allow appdomain cache_backup_file:file { read write getattr };
216allow appdomain cache_backup_file:dir getattr;
217# Backup ability using 'adb backup'
218allow appdomain system_data_file:lnk_file r_file_perms;
219allow appdomain system_data_file:file { getattr read };
220
221# Allow read/stat of /data/media files passed by Binder or local socket IPC.
222allow { appdomain -isolated_app } media_rw_data_file:file { read getattr };
223
224# Read and write /data/data/com.android.providers.telephony files passed over Binder.
225allow { appdomain -isolated_app } radio_data_file:file { read write getattr };
226
227# Allow access to external storage; we have several visible mount points under /storage
228# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary
229allow { appdomain -isolated_app -ephemeral_app } storage_file:dir r_dir_perms;
230allow { appdomain -isolated_app -ephemeral_app } storage_file:lnk_file r_file_perms;
231allow { appdomain -isolated_app -ephemeral_app } mnt_user_file:dir r_dir_perms;
232allow { appdomain -isolated_app -ephemeral_app } mnt_user_file:lnk_file r_file_perms;
233
234# Read/write visible storage
235allow { appdomain -isolated_app -ephemeral_app } fuse:dir create_dir_perms;
236allow { appdomain -isolated_app -ephemeral_app } fuse:file create_file_perms;
237allow { appdomain -isolated_app -ephemeral_app } sdcardfs:dir create_dir_perms;
238allow { appdomain -isolated_app -ephemeral_app } sdcardfs:file create_file_perms;
239# This should be removed if sdcardfs is modified to alter the secontext for its
240# accesses to the underlying FS.
241allow { appdomain -isolated_app -ephemeral_app } { media_rw_data_file vfat }:dir create_dir_perms;
242allow { appdomain -isolated_app -ephemeral_app } { media_rw_data_file vfat }:file create_file_perms;
243
244# Access OBBs (vfat images) mounted by vold (b/17633509)
245# File write access allowed for FDs returned through Storage Access Framework
246allow { appdomain -isolated_app -ephemeral_app } vfat:dir r_dir_perms;
247allow { appdomain -isolated_app -ephemeral_app } vfat:file rw_file_perms;
248
249# Allow apps to use the USB Accessory interface.
250# http://developer.android.com/guide/topics/connectivity/usb/accessory.html
251#
252# USB devices are first opened by the system server (USBDeviceManagerService)
253# and the file descriptor is passed to the right Activity via binder.
254allow { appdomain -isolated_app -ephemeral_app } usb_device:chr_file { read write getattr ioctl };
255allow { appdomain -isolated_app -ephemeral_app } usbaccessory_device:chr_file { read write getattr };
256
257# For art.
258allow appdomain dalvikcache_data_file:file execute;
259allow appdomain dalvikcache_data_file:lnk_file r_file_perms;
260
261# Allow any app to read shared RELRO files.
262allow appdomain shared_relro_file:dir search;
263allow appdomain shared_relro_file:file r_file_perms;
264
265# Allow apps to read/execute installed binaries
266allow appdomain apk_data_file:dir r_dir_perms;
267allow appdomain apk_data_file:file rx_file_perms;
268
269# /data/resource-cache
270allow appdomain resourcecache_data_file:file r_file_perms;
271allow appdomain resourcecache_data_file:dir r_dir_perms;
272
273# logd access
274read_logd(appdomain)
275control_logd({ appdomain -ephemeral_app untrusted_v2_app })
276# application inherit logd write socket (urge is to deprecate this long term)
277allow appdomain zygote:unix_dgram_socket write;
278
279allow { appdomain -isolated_app -ephemeral_app } keystore:keystore_key { get_state get insert delete exist list sign verify };
280
281use_keystore({ appdomain -isolated_app -ephemeral_app })
282
283allow appdomain console_device:chr_file { read write };
284
285# only allow unprivileged socket ioctl commands
286allowxperm { appdomain -bluetooth } self:{ rawip_socket tcp_socket udp_socket }
287  ioctl { unpriv_sock_ioctls unpriv_tty_ioctls };
288
289allow { appdomain -isolated_app } ion_device:chr_file rw_file_perms;
290# TODO is write really necessary ?
291auditallow { appdomain userdebug_or_eng(`-su') } ion_device:chr_file { write append };
292
293# TODO(b/36375899) replace with hal_client_domain for mediacodec (hal_omx)
294get_prop({ appdomain -isolated_app }, hwservicemanager_prop);
295
296# Allow app access to mediacodec (IOMX HAL)
297binder_call({ appdomain -isolated_app }, mediacodec)
298
299# Allow AAudio apps to use shared memory file descriptors from the HAL
300allow { appdomain -isolated_app } hal_audio:fd use;
301
302# Allow app to access shared memory created by camera HAL1
303allow { appdomain -isolated_app } hal_camera:fd use;
304
305# RenderScript always-passthrough HAL
306allow { appdomain -isolated_app } hal_renderscript_hwservice:hwservice_manager find;
307
308# TODO: switch to meminfo service
309allow appdomain proc_meminfo:file r_file_perms;
310
311# For app fuse.
312allow appdomain app_fuse_file:file { getattr read append write };
313
314pdx_client({ appdomain -isolated_app -ephemeral_app }, display_client)
315pdx_client({ appdomain -isolated_app -ephemeral_app }, display_manager)
316pdx_client({ appdomain -isolated_app -ephemeral_app }, display_vsync)
317pdx_client({ appdomain -isolated_app -ephemeral_app }, performance_client)
318# Apps do not directly open the IPC socket for bufferhubd.
319pdx_use({ appdomain -isolated_app -ephemeral_app }, bufferhub_client)
320
321###
322### CTS-specific rules
323###
324
325# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java.
326# testRunAsHasCorrectCapabilities
327allow appdomain runas_exec:file getattr;
328# Others are either allowed elsewhere or not desired.
329
330# Apps receive an open tun fd from the framework for
331# device traffic. Do not allow untrusted app to directly open tun_device
332allow { appdomain -isolated_app -ephemeral_app } tun_device:chr_file { read write getattr ioctl append };
333
334# Connect to adbd and use a socket transferred from it.
335# This is used for e.g. adb backup/restore.
336allow appdomain adbd:unix_stream_socket connectto;
337allow appdomain adbd:fd use;
338allow appdomain adbd:unix_stream_socket { getattr getopt ioctl read write shutdown };
339
340allow appdomain cache_file:dir getattr;
341
342# Allow apps to run with asanwrapper.
343with_asan(`allow appdomain asanwrapper_exec:file rx_file_perms;')
344
345###
346### Neverallow rules
347###
348### These are things that Android apps should NEVER be able to do
349###
350
351# Superuser capabilities.
352# bluetooth requires net_admin and wake_alarm.
353neverallow { appdomain -bluetooth } self:capability *;
354neverallow { appdomain -bluetooth } self:capability2 *;
355
356# Block device access.
357neverallow appdomain dev_type:blk_file { read write };
358
359# Access to any of the following character devices.
360neverallow appdomain {
361    audio_device
362    camera_device
363    dm_device
364    radio_device
365    rpmsg_device
366    video_device
367}:chr_file { read write };
368
369# Note: Try expanding list of app domains in the future.
370neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write };
371
372neverallow { appdomain -nfc } nfc_device:chr_file
373    { read write };
374neverallow { appdomain -bluetooth } hci_attach_dev:chr_file
375    { read write };
376neverallow appdomain tee_device:chr_file { read write };
377
378# Privileged netlink socket interfaces.
379neverallow appdomain
380    domain:{
381        netlink_tcpdiag_socket
382        netlink_nflog_socket
383        netlink_xfrm_socket
384        netlink_audit_socket
385        netlink_dnrt_socket
386    } *;
387
388# These messages are broadcast messages from the kernel to userspace.
389# Do not allow the writing of netlink messages, which has been a source
390# of rooting vulns in the past.
391neverallow appdomain domain:netlink_kobject_uevent_socket { write append };
392
393# Sockets under /dev/socket that are not specifically typed.
394neverallow appdomain socket_device:sock_file write;
395
396# Unix domain sockets.
397neverallow appdomain adbd_socket:sock_file write;
398neverallow { appdomain -radio } rild_socket:sock_file write;
399neverallow appdomain vold_socket:sock_file write;
400neverallow appdomain zygote_socket:sock_file write;
401
402# ptrace access to non-app domains.
403neverallow appdomain { domain -appdomain }:process ptrace;
404
405# Write access to /proc/pid entries for any non-app domain.
406neverallow appdomain { domain -appdomain }:file write;
407
408# signal access to non-app domains.
409# sigchld allowed for parent death notification.
410# signull allowed for kill(pid, 0) existence test.
411# All others prohibited.
412neverallow appdomain { domain -appdomain }:process
413    { sigkill sigstop signal };
414
415# Transition to a non-app domain.
416# Exception for the shell and su domains, can transition to runas, etc.
417# Exception for crash_dump.
418neverallow { appdomain -shell userdebug_or_eng(`-su') } { domain -appdomain -crash_dump }:process
419    { transition };
420neverallow { appdomain -shell userdebug_or_eng(`-su') } { domain -appdomain }:process
421    { dyntransition };
422
423# Write to rootfs.
424neverallow appdomain rootfs:dir_file_class_set
425    { create write setattr relabelfrom relabelto append unlink link rename };
426
427# Write to /system.
428neverallow appdomain system_file:dir_file_class_set
429    { create write setattr relabelfrom relabelto append unlink link rename };
430
431# Write to entrypoint executables.
432neverallow appdomain exec_type:file
433    { create write setattr relabelfrom relabelto append unlink link rename };
434
435# Write to system-owned parts of /data.
436# This is the default type for anything under /data not otherwise
437# specified in file_contexts.  Define a different type for portions
438# that should be writable by apps.
439neverallow appdomain system_data_file:dir_file_class_set
440    { create write setattr relabelfrom relabelto append unlink link rename };
441
442# Write to various other parts of /data.
443neverallow appdomain drm_data_file:dir_file_class_set
444    { create write setattr relabelfrom relabelto append unlink link rename };
445neverallow { appdomain -platform_app }
446    apk_data_file:dir_file_class_set
447    { create write setattr relabelfrom relabelto append unlink link rename };
448neverallow { appdomain -platform_app }
449    apk_tmp_file:dir_file_class_set
450    { create write setattr relabelfrom relabelto append unlink link rename };
451neverallow { appdomain -platform_app }
452    apk_private_data_file:dir_file_class_set
453    { create write setattr relabelfrom relabelto append unlink link rename };
454neverallow { appdomain -platform_app }
455    apk_private_tmp_file:dir_file_class_set
456    { create write setattr relabelfrom relabelto append unlink link rename };
457neverallow { appdomain -shell }
458    shell_data_file:dir_file_class_set
459    { create setattr relabelfrom relabelto append unlink link rename };
460neverallow { appdomain -bluetooth }
461    bluetooth_data_file:dir_file_class_set
462    { create write setattr relabelfrom relabelto append unlink link rename };
463neverallow appdomain
464    keystore_data_file:dir_file_class_set
465    { create write setattr relabelfrom relabelto append unlink link rename };
466neverallow appdomain
467    systemkeys_data_file:dir_file_class_set
468    { create write setattr relabelfrom relabelto append unlink link rename };
469neverallow appdomain
470    wifi_data_file:dir_file_class_set
471    { create write setattr relabelfrom relabelto append unlink link rename };
472neverallow appdomain
473    dhcp_data_file:dir_file_class_set
474    { create write setattr relabelfrom relabelto append unlink link rename };
475
476# access tmp apk files
477neverallow { appdomain -untrusted_app_all -platform_app -priv_app }
478    { apk_tmp_file apk_private_tmp_file }:dir_file_class_set *;
479
480neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *;
481neverallow untrusted_app_all { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read };
482
483# Access to factory files.
484neverallow appdomain efs_file:dir_file_class_set write;
485neverallow { appdomain -shell } efs_file:dir_file_class_set read;
486
487# Write to various pseudo file systems.
488neverallow { appdomain -bluetooth -nfc }
489    sysfs:dir_file_class_set write;
490neverallow appdomain
491    proc:dir_file_class_set write;
492
493# Access to syslog(2) or /proc/kmsg.
494neverallow appdomain kernel:system { syslog_read syslog_mod syslog_console };
495
496# SELinux is not an API for apps to use
497neverallow { appdomain -shell } *:security { compute_av check_context };
498neverallow { appdomain -shell } *:netlink_selinux_socket *;
499
500# Ability to perform any filesystem operation other than statfs(2).
501# i.e. no mount(2), unmount(2), etc.
502neverallow appdomain fs_type:filesystem ~getattr;
503
504# prevent creation/manipulation of globally readable symlinks
505neverallow appdomain {
506  apk_data_file
507  cache_file
508  cache_recovery_file
509  dev_type
510  rootfs
511  system_file
512  tmpfs
513}:lnk_file no_w_file_perms;
514
515# Denylist app domains not allowed to execute from /data
516neverallow {
517  bluetooth
518  isolated_app
519  nfc
520  radio
521  shared_relro
522  system_app
523} {
524  data_file_type
525  -dalvikcache_data_file
526  -system_data_file # shared libs in apks
527  -apk_data_file
528}:file no_x_file_perms;
529
530# Applications should use the activity model for receiving events
531neverallow {
532  appdomain
533  -shell # bugreport
534} input_device:chr_file ~getattr;
535
536# Do not allow access to Bluetooth-related system properties except for a few allowlisted domains.
537# neverallow rules for access to Bluetooth-related data files are above.
538neverallow {
539  appdomain
540  -bluetooth
541  -system_app
542} bluetooth_prop:file create_file_perms;
543