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