• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# /proc/net access.
2# TODO(b/9496886) Audit access for removal.
3# proc_net access for the negated domains below is granted (or not) in their
4# individual .te files.
5r_dir_file({
6  appdomain
7  -ephemeral_app
8  -isolated_app_all
9  -network_stack
10  -platform_app
11  -priv_app
12  -shell
13  -sdk_sandbox_all
14  -system_app
15  -untrusted_app_all
16}, proc_net_type)
17# audit access for all these non-core app domains.
18userdebug_or_eng(`
19  auditallow {
20    appdomain
21    -ephemeral_app
22    -isolated_app_all
23    -network_stack
24    -platform_app
25    -priv_app
26    -shell
27    -su
28    -sdk_sandbox_all
29    -system_app
30    -untrusted_app_all
31  } proc_net_type:{ dir file lnk_file } { getattr open read };
32')
33
34# Allow apps to read the Test Harness Mode property. This property is used in
35# the implementation of ActivityManager.isDeviceInTestHarnessMode()
36get_prop(appdomain, test_harness_prop)
37
38get_prop(appdomain, boot_status_prop)
39get_prop(appdomain, dalvik_config_prop_type)
40get_prop(appdomain, media_config_prop)
41get_prop(appdomain, packagemanager_config_prop)
42get_prop(appdomain, radio_control_prop)
43get_prop(appdomain, surfaceflinger_color_prop)
44get_prop(appdomain, systemsound_config_prop)
45get_prop(appdomain, telephony_config_prop)
46get_prop(appdomain, userspace_reboot_config_prop)
47get_prop(appdomain, vold_config_prop)
48get_prop(appdomain, adbd_config_prop)
49get_prop(appdomain, dck_prop)
50get_prop(appdomain, persist_wm_debug_prop)
51get_prop(appdomain, persist_sysui_builder_extras_prop)
52get_prop(appdomain, persist_sysui_ranking_update_prop)
53
54# Allow the heap dump ART plugin to the count of sessions waiting for OOME
55get_prop(appdomain, traced_oome_heap_session_count_prop)
56
57# Allow to read ro.vendor.camera.extensions.enabled
58get_prop(appdomain, camera2_extensions_prop)
59
60# Allow to ro.camerax.extensions.enabled
61get_prop(appdomain, camerax_extensions_prop)
62
63# Prevent apps from causing presubmit failures.
64# Apps can cause selinux denials by accessing CE storage
65# and/or external storage. In either case, the selinux denial is
66# not the cause of the failure, but just a symptom that
67# storage isn't ready. Many apps handle the failure appropriately.
68#
69# Apps cannot access external storage before it becomes available.
70dontaudit appdomain storage_stub_file:dir getattr;
71# Attempts to write to system_data_file is generally a sign
72# that apps are attempting to access encrypted storage before
73# the ACTION_USER_UNLOCKED intent is delivered. Apps are not
74# allowed to write to CE storage before it's available.
75# Attempting to do so will be blocked by both selinux and unix
76# permissions.
77dontaudit appdomain system_data_file:dir write;
78# Apps should not be reading vendor-defined properties.
79dontaudit appdomain vendor_default_prop:file read;
80
81# Access to /mnt/media_rw/<vol> (limited by DAC to apps with external_storage gid)
82allow { appdomain -sdk_sandbox_all } mnt_media_rw_file:dir search;
83
84# allow apps to use UDP sockets provided by the system server but not
85# modify them other than to connect
86allow appdomain system_server:udp_socket {
87        connect getattr read recvfrom sendto write getopt setopt };
88
89# Allow to read sendbug.preferred.domain
90get_prop(appdomain, sendbug_config_prop)
91
92# Allow to read graphics related properties.
93get_prop(appdomain, graphics_config_prop)
94
95# Allow to read persist.config.calibration_fac
96get_prop(appdomain, camera_calibration_prop)
97
98# Allow to read db.log.detailed, db.log.slow_query_threshold*
99get_prop(appdomain, sqlite_log_prop)
100
101# Allow to read system_user_mode_emulation_prop, which is used by UserManager.java
102userdebug_or_eng(`get_prop(appdomain, system_user_mode_emulation_prop)')
103
104# Allow font file read by apps.
105allow appdomain font_data_file:file r_file_perms;
106allow appdomain font_data_file:dir r_dir_perms;
107
108# Enter /data/misc/apexdata/
109allow appdomain apex_module_data_file:dir search;
110# Read /data/misc/apexdata/com.android.art, execute signed AOT artifacts.
111allow appdomain apex_art_data_file:dir r_dir_perms;
112allow appdomain apex_art_data_file:file rx_file_perms;
113
114# Allow access to tombstones if an fd to one is given to you.
115# An app cannot open the tombstone itself because it lacks `open`.
116allow appdomain tombstone_data_file:file { getattr read };
117
118# Execute the shell or other system executables.
119allow { appdomain -ephemeral_app -sdk_sandbox_all } shell_exec:file rx_file_perms;
120allow { appdomain -ephemeral_app -sdk_sandbox_all } toolbox_exec:file rx_file_perms;
121not_full_treble(`allow { appdomain -ephemeral_app -sdk_sandbox_all } vendor_file:file x_file_perms;')
122
123# Allow apps access to /vendor/app except for privileged
124# apps which cannot be in /vendor.
125r_dir_file({ appdomain -ephemeral_app -sdk_sandbox_all }, vendor_app_file)
126allow { appdomain -ephemeral_app -sdk_sandbox_all } vendor_app_file:file execute;
127
128# Allow apps to read microdroid related files in vendor partition for CTS purpose.
129r_dir_file({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, vendor_microdroid_file)
130
131# Perform binder IPC to sdk sandbox.
132binder_call(appdomain, sdk_sandbox_all)
133
134# Allow apps to communicate via binder with virtual camera service.
135binder_call(appdomain, virtual_camera)
136
137# Allow access to external storage; we have several visible mount points under /storage
138# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary
139allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } storage_file:dir r_dir_perms;
140allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } storage_file:lnk_file r_file_perms;
141allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } mnt_user_file:dir r_dir_perms;
142allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } mnt_user_file:lnk_file r_file_perms;
143
144# Read/write visible storage
145allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } { sdcard_type fuse }:dir create_dir_perms;
146allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } { sdcard_type fuse }:file create_file_perms;
147# This should be removed if sdcardfs is modified to alter the secontext for its
148# accesses to the underlying FS.
149allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } media_rw_data_file:dir create_dir_perms;
150allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } media_rw_data_file:file create_file_perms;
151
152# Allow apps to use the USB Accessory interface.
153# http://developer.android.com/guide/topics/connectivity/usb/accessory.html
154#
155# USB devices are first opened by the system server (USBDeviceManagerService)
156# and the file descriptor is passed to the right Activity via binder.
157allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } usb_device:chr_file { read write getattr ioctl };
158allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } usbaccessory_device:chr_file { read write getattr };
159
160#logd access
161control_logd({ appdomain -ephemeral_app -sdk_sandbox_all })
162
163# application inherit logd write socket (urge is to deprecate this long term)
164allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore:keystore2_key { delete use get_info grant rebind update };
165
166allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore_maintenance_service:service_manager find;
167
168use_keystore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all })
169
170use_credstore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all })
171
172allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } persistent_data_block_service:service_manager find;
173
174# For app fuse.
175pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_client)
176pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_manager)
177pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_vsync)
178pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, performance_client)
179# Apps do not directly open the IPC socket for bufferhubd.
180pdx_use({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, bufferhub_client)
181
182# Apps receive an open tun fd from the framework for
183# device traffic. Do not allow untrusted app to directly open tun_device
184allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } tun_device:chr_file { read write getattr append ioctl };
185allowxperm { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } tun_device:chr_file ioctl TUNGETIFF;
186
187
188# WebView and other application-specific JIT compilers
189allow appdomain self:process execmem;
190
191allow appdomain { ashmem_device ashmem_libcutils_device }:chr_file execute;
192
193# Receive and use open file descriptors inherited from zygote.
194allow appdomain zygote:fd use;
195
196# Receive and use open file descriptors inherited from app zygote.
197allow appdomain app_zygote:fd use;
198
199# gdbserver for ndk-gdb reads the zygote.
200# valgrind needs mmap exec for zygote
201allow appdomain zygote_exec:file rx_file_perms;
202
203# Notify zygote of death;
204allow appdomain zygote:process sigchld;
205
206# Read /data/dalvik-cache.
207allow appdomain dalvikcache_data_file:dir { search getattr };
208allow appdomain dalvikcache_data_file:file r_file_perms;
209
210# Read the /sdcard and /mnt/sdcard symlinks
211allow { appdomain -isolated_app_all -sdk_sandbox_all } rootfs:lnk_file r_file_perms;
212allow { appdomain -isolated_app_all -sdk_sandbox_all } tmpfs:lnk_file r_file_perms;
213
214# Search /storage/emulated tmpfs mount.
215allow { appdomain -sdk_sandbox_all } tmpfs:dir r_dir_perms;
216
217# Notify zygote of the wrapped process PID when using --invoke-with.
218allow appdomain zygote:fifo_file write;
219
220userdebug_or_eng(`
221  # Allow apps to create and write method traces in /data/misc/trace.
222  allow appdomain method_trace_data_file:dir w_dir_perms;
223  allow appdomain method_trace_data_file:file { create w_file_perms };
224')
225
226# Notify shell and adbd of death when spawned via runas for ndk-gdb.
227allow appdomain shell:process sigchld;
228allow appdomain adbd:process sigchld;
229
230# child shell or gdbserver pty access for runas.
231allow appdomain devpts:chr_file { getattr read write ioctl };
232
233# Use pipes and sockets provided by system_server via binder or local socket.
234allow appdomain system_server:fd use;
235allow appdomain system_server:fifo_file rw_file_perms;
236allow appdomain system_server:unix_stream_socket { read write setopt getattr getopt shutdown };
237allow appdomain system_server:tcp_socket { read write getattr getopt shutdown };
238
239# For AppFuse.
240allow appdomain vold:fd use;
241
242# Communication with other apps via fifos
243allow appdomain appdomain:fifo_file rw_file_perms;
244
245# Communicate with surfaceflinger.
246allow appdomain surfaceflinger:unix_stream_socket { read write setopt getattr getopt shutdown };
247
248# App sandbox file accesses.
249allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } {
250  app_data_file
251  privapp_data_file
252  is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
253}:dir create_dir_perms;
254allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } {
255  app_data_file
256  privapp_data_file
257  is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
258}:file create_file_perms;
259
260is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
261  # an app can read but cannot write to its own directory of storage areas
262  allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } storage_area_app_dir:dir r_dir_perms;
263  # an app can write to its storage areas
264  allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } storage_area_dir:dir rw_dir_perms;
265')
266
267allowxperm { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } {
268  app_data_file
269  privapp_data_file
270  is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
271}:file ioctl FS_IOC_MEASURE_VERITY;
272
273# Access via already open fds is ok even for mlstrustedsubject.
274allow { appdomain -isolated_app_all -sdk_sandbox_all } {
275  app_data_file
276  privapp_data_file
277  system_app_data_file
278  is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
279}:file { getattr map read write };
280
281# Access open fds from SDK sandbox
282allow appdomain sdk_sandbox_data_file:file { getattr read };
283
284# Traverse into expanded storage
285allow appdomain mnt_expand_file:dir r_dir_perms;
286
287# Keychain and user-trusted credentials
288r_dir_file(appdomain, keychain_data_file)
289allow appdomain misc_user_data_file:dir r_dir_perms;
290allow appdomain misc_user_data_file:file r_file_perms;
291
292# TextClassifier
293r_dir_file({ appdomain -isolated_app_all }, textclassifier_data_file)
294
295# Access to OEM provided data and apps
296allow appdomain oemfs:dir r_dir_perms;
297allow appdomain oemfs:file rx_file_perms;
298
299allow appdomain system_file:file x_file_perms;
300
301# Renderscript needs the ability to read directories on /system
302allow appdomain system_file:dir r_dir_perms;
303allow appdomain system_file:lnk_file { getattr open read };
304# Renderscript specific permissions to open /system/vendor/lib64.
305not_full_treble(`
306    allow appdomain vendor_file_type:dir r_dir_perms;
307    allow appdomain vendor_file_type:lnk_file { getattr open read };
308')
309
310full_treble_only(`
311    # For looking up Renderscript vendor drivers
312    allow { appdomain -isolated_app_all } vendor_file:dir { open read };
313')
314
315# Allow apps access to /vendor/overlay
316r_dir_file(appdomain, vendor_overlay_file)
317
318# Allow apps access to /vendor/framework
319# for vendor provided libraries.
320r_dir_file(appdomain, vendor_framework_file)
321
322# Allow apps read / execute access to vendor public libraries.
323allow appdomain {vendor_public_framework_file vendor_public_lib_file}:dir r_dir_perms;
324allow appdomain {vendor_public_framework_file vendor_public_lib_file}:file { execute read open getattr map };
325
326# Read/write wallpaper file (opened by system).
327allow appdomain wallpaper_file:file { getattr read write map };
328
329# Read/write cached ringtones (opened by system).
330allow appdomain ringtone_file:file { getattr read write map };
331
332# Read ShortcutManager icon files (opened by system).
333allow appdomain shortcut_manager_icons:file { getattr read map };
334
335# Read icon file (opened by system).
336allow appdomain icon_file:file { getattr read map };
337
338# Old stack dumping scheme : append to a global trace file (/data/anr/traces.txt).
339#
340# TODO: All of these permissions except for anr_data_file:file append can be
341# withdrawn once we've switched to the new stack dumping mechanism, see b/32064548
342# and the rules below.
343allow appdomain anr_data_file:dir search;
344allow appdomain anr_data_file:file { open append };
345
346# New stack dumping scheme : request an output FD from tombstoned via a unix
347# domain socket.
348#
349# Allow apps to connect and write to the tombstoned java trace socket in
350# order to dump their traces. Also allow them to append traces to pipes
351# created by dumptrace. (Also see the rules below where they are given
352# additional permissions to dumpstate pipes for other aspects of bug report
353# creation).
354unix_socket_connect(appdomain, tombstoned_java_trace, tombstoned)
355allow appdomain tombstoned:fd use;
356allow appdomain dumpstate:fifo_file append;
357allow appdomain incidentd:fifo_file append;
358
359# Allow apps to send dump information to dumpstate
360allow appdomain dumpstate:fd use;
361allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown };
362allow appdomain dumpstate:fifo_file { write getattr };
363allow appdomain shell_data_file:file { write getattr };
364
365# Allow apps to send dump information to incidentd
366allow appdomain incidentd:fd use;
367allow appdomain incidentd:fifo_file { write getattr };
368
369# Allow apps to send information to statsd socket.
370unix_socket_send(appdomain, statsdw, statsd)
371
372# Write profiles /data/misc/profiles
373allow appdomain user_profile_root_file:dir search;
374allow appdomain user_profile_data_file:dir w_dir_perms;
375allow appdomain user_profile_data_file:file create_file_perms;
376
377# Allow writing performance tracing data into the perfetto traced daemon.
378# Needed for java heap graph ART plugin (perfetto_hprof).
379# The perfetto profiling daemon will check for the specific application's
380# opt-in/opt-out.
381perfetto_producer(appdomain)
382
383# Send heap dumps to system_server via an already open file descriptor
384# % adb shell am set-watch-heap com.android.systemui 1048576
385# % adb shell dumpsys procstats --start-testing
386# debuggable builds only.
387userdebug_or_eng(`
388  allow appdomain heapdump_data_file:file append;
389')
390
391# Grant GPU access to all processes started by Zygote.
392# They need that to render the standard UI.
393allow { appdomain -isolated_app_all } gpu_device:chr_file rw_file_perms;
394allow { appdomain -isolated_app_all } gpu_device:dir r_dir_perms;
395allow { appdomain -isolated_app_all } sysfs_gpu:file r_file_perms;
396
397
398# Use the Binder.
399binder_use(appdomain)
400# Perform binder IPC to binder services.
401binder_call(appdomain, binderservicedomain)
402# Perform binder IPC to other apps.
403binder_call(appdomain, appdomain)
404# Perform binder IPC to ephemeral apps.
405binder_call(appdomain, ephemeral_app)
406# Perform binder IPC to gpuservice.
407binder_call({ appdomain -isolated_app_all }, gpuservice)
408
409# Talk with graphics composer fences
410allow appdomain hal_graphics_composer:fd use;
411
412# Already connected, unnamed sockets being passed over some other IPC
413# hence no sock_file or connectto permission. This appears to be how
414# Chrome works, may need to be updated as more apps using isolated services
415# are examined.
416allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown };
417
418# Backup ability for every app. BMS opens and passes the fd
419# to any app that has backup ability. Hence, no open permissions here.
420allow appdomain backup_data_file:file { read write getattr map };
421allow appdomain cache_backup_file:file { read write getattr map };
422allow appdomain cache_backup_file:dir getattr;
423# Backup ability using 'adb backup'
424allow appdomain system_data_file:lnk_file r_file_perms;
425allow appdomain system_data_file:file { getattr read map };
426
427# Allow read/stat of /data/media files passed by Binder or local socket IPC.
428allow { appdomain -isolated_app_all -sdk_sandbox_all } media_rw_data_file:file { read getattr };
429
430# Read and write /data/data/com.android.providers.telephony files passed over Binder.
431allow { appdomain -isolated_app_all } radio_data_file:file { read write getattr };
432
433# For art.
434allow appdomain dalvikcache_data_file:file execute;
435allow appdomain dalvikcache_data_file:lnk_file r_file_perms;
436
437# Allow any app to read shared RELRO files.
438allow appdomain shared_relro_file:dir search;
439allow appdomain shared_relro_file:file r_file_perms;
440
441# Allow apps to read/execute installed binaries
442allow appdomain apk_data_file:dir { open getattr read search ioctl lock };
443allow appdomain apk_data_file:file { getattr open read ioctl lock map x_file_perms };
444
445# /data/resource-cache
446allow appdomain resourcecache_data_file:file r_file_perms;
447allow appdomain resourcecache_data_file:dir r_dir_perms;
448
449# logd access
450read_logd(appdomain)
451
452allow appdomain zygote:unix_dgram_socket write;
453
454allow appdomain console_device:chr_file { read write };
455
456# only allow unprivileged socket ioctl commands
457allowxperm { appdomain -bluetooth } self:{ rawip_socket tcp_socket udp_socket }
458  ioctl { unpriv_sock_ioctls unpriv_tty_ioctls };
459
460allow { appdomain -isolated_app_all } ion_device:chr_file r_file_perms;
461allow { appdomain -isolated_app_all } dmabuf_system_heap_device:chr_file r_file_perms;
462allow { appdomain -isolated_app_all } dmabuf_system_secure_heap_device:chr_file r_file_perms;
463
464# Allow AAudio apps to use shared memory file descriptors from the HAL
465allow { appdomain -isolated_app_all } hal_audio:fd use;
466
467# Allow app to access shared memory created by camera HAL1
468allow { appdomain -isolated_app_all } hal_camera:fd use;
469
470# Allow apps to access shared memory file descriptor from the tuner HAL
471allow {appdomain -isolated_app_all} hal_tv_tuner_server:fd use;
472
473# Allow app to access shared memory created by PowerHAL for FMQ use
474allow { appdomain -isolated_app_all } hal_power_server:fd use;
475
476# RenderScript always-passthrough HAL
477allow { appdomain -isolated_app_all } hal_renderscript_hwservice:hwservice_manager find;
478allow appdomain same_process_hal_file:file { execute read open getattr map };
479
480# TODO: switch to meminfo service
481allow appdomain proc_meminfo:file r_file_perms;
482
483# For app fuse.
484allow appdomain app_fuse_file:file { getattr read append write map };
485
486###
487### CTS-specific rules
488###
489
490# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java.
491# testRunAsHasCorrectCapabilities
492allow appdomain runas_exec:file getattr;
493# Others are either allowed elsewhere or not desired.
494
495get_prop(appdomain, high_barometer_quality_prop)
496
497# Connect to adbd and use a socket transferred from it.
498# This is used for e.g. adb backup/restore.
499allow appdomain adbd:unix_stream_socket connectto;
500allow appdomain adbd:fd use;
501allow appdomain adbd:unix_stream_socket { getattr getopt ioctl read write shutdown };
502
503allow appdomain cache_file:dir getattr;
504
505# Allow apps to run with asanwrapper.
506with_asan(`allow appdomain asanwrapper_exec:file rx_file_perms;')
507
508# Read access to FDs from the DropboxManagerService.
509allow appdomain dropbox_data_file:file { getattr read };
510
511# Read tmpfs types from these processes.
512allow appdomain audioserver_tmpfs:file { getattr map read write };
513allow appdomain system_server_tmpfs:file { getattr map read write };
514allow appdomain zygote_tmpfs:file { map read };
515
516###
517### Neverallow rules
518###
519### These are things that Android apps should NEVER be able to do
520###
521
522# Superuser capabilities.
523# bluetooth requires net_admin and wake_alarm. network stack app requires net_admin.
524neverallow { appdomain -bluetooth -network_stack } self:capability_class_set *;
525
526# Block device access.
527neverallow appdomain dev_type:blk_file { read write };
528
529# Note: Try expanding list of app domains in the future.
530neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write };
531
532neverallow { appdomain -nfc } nfc_device:chr_file
533    { read write };
534neverallow { appdomain -bluetooth } hci_attach_dev:chr_file
535    { read write };
536neverallow appdomain tee_device:chr_file { read write };
537
538# Privileged netlink socket interfaces.
539neverallow { appdomain -network_stack }
540    domain:{
541        netlink_tcpdiag_socket
542        netlink_nflog_socket
543        netlink_xfrm_socket
544        netlink_audit_socket
545        netlink_dnrt_socket
546    } *;
547
548# These messages are broadcast messages from the kernel to userspace.
549# Do not allow the writing of netlink messages, which has been a source
550# of rooting vulns in the past.
551neverallow { appdomain -network_stack }
552    domain:netlink_kobject_uevent_socket { write append };
553
554# Sockets under /dev/socket that are not specifically typed.
555neverallow appdomain socket_device:sock_file write;
556
557# Unix domain sockets.
558neverallow appdomain adbd_socket:sock_file write;
559neverallow { appdomain -radio } rild_socket:sock_file write;
560
561# ptrace access to non-app domains.
562neverallow appdomain { domain -appdomain }:process ptrace;
563
564# The Android security model guarantees the confidentiality and integrity
565# of application data and execution state. Ptrace bypasses those
566# confidentiality guarantees. Disallow ptrace access from system components
567# to apps. Crash_dump is excluded, as it needs ptrace access to
568# produce stack traces.  llkd is excluded, as it needs ptrace access to
569# inspect stack traces for live lock conditions.
570
571neverallow {
572  domain
573  -appdomain
574  -crash_dump
575  userdebug_or_eng(`-llkd')
576} appdomain:process ptrace;
577
578# Read or write access to /proc/pid entries for any non-app domain.
579# A different form of hidepid=2 like protections
580neverallow appdomain { domain -appdomain }:file no_w_file_perms;
581neverallow { appdomain -shell } { domain -appdomain }:file no_rw_file_perms;
582
583# signal access to non-app domains.
584# sigchld allowed for parent death notification.
585# signull allowed for kill(pid, 0) existence test.
586# All others prohibited.
587# -perfetto is to allow shell (which is an appdomain) to kill perfetto
588# (see private/shell.te).
589neverallow appdomain { domain -appdomain -perfetto }:process
590    { sigkill sigstop signal };
591
592# Write to rootfs.
593neverallow appdomain rootfs:dir_file_class_set
594    { create write setattr relabelfrom relabelto append unlink link rename };
595
596# Write to /system.
597neverallow appdomain system_file_type:dir_file_class_set
598    { create write setattr relabelfrom relabelto append unlink link rename };
599
600# Write to entrypoint executables.
601neverallow appdomain exec_type:file
602    { create write setattr relabelfrom relabelto append unlink link rename };
603
604# Write to system-owned parts of /data.
605# This is the default type for anything under /data not otherwise
606# specified in file_contexts.  Define a different type for portions
607# that should be writable by apps.
608neverallow appdomain system_data_file:dir_file_class_set
609    { create write setattr relabelfrom relabelto append unlink link rename };
610
611# Write to various other parts of /data.
612neverallow appdomain drm_data_file:dir_file_class_set
613    { create write setattr relabelfrom relabelto append unlink link rename };
614neverallow { appdomain -platform_app }
615    apk_data_file:dir_file_class_set
616    { create write setattr relabelfrom relabelto append unlink link rename };
617neverallow { appdomain -platform_app }
618    apk_private_data_file:dir_file_class_set
619    { create write setattr relabelfrom relabelto append unlink link rename };
620neverallow { appdomain -platform_app }
621    apk_private_tmp_file:dir_file_class_set
622    { create write setattr relabelfrom relabelto append unlink link rename };
623neverallow { appdomain -shell }
624    shell_data_file:dir_file_class_set
625    { create setattr relabelfrom relabelto append unlink link rename };
626neverallow { appdomain -bluetooth }
627    bluetooth_data_file:dir_file_class_set
628    { create write setattr relabelfrom relabelto append unlink link rename };
629neverallow { domain -credstore -init } credstore_data_file:dir_file_class_set *;
630neverallow appdomain
631    keystore_data_file:dir_file_class_set
632    { create write setattr relabelfrom relabelto append unlink link rename };
633neverallow appdomain
634    systemkeys_data_file:dir_file_class_set
635    { create write setattr relabelfrom relabelto append unlink link rename };
636neverallow appdomain
637    wifi_data_file:dir_file_class_set
638    { create write setattr relabelfrom relabelto append unlink link rename };
639neverallow appdomain
640    dhcp_data_file:dir_file_class_set
641    { create write setattr relabelfrom relabelto append unlink link rename };
642
643# access tmp apk files
644neverallow { appdomain -platform_app }
645    apk_tmp_file:dir_file_class_set
646    { create write setattr relabelfrom relabelto append unlink link rename };
647
648# Access to factory files.
649neverallow appdomain efs_file:dir_file_class_set write;
650neverallow { appdomain -shell } efs_file:dir_file_class_set read;
651
652# Write to various pseudo file systems.
653neverallow { appdomain -bluetooth -nfc }
654    sysfs:dir_file_class_set write;
655neverallow appdomain
656    proc:dir_file_class_set write;
657
658# Access to syslog(2) or /proc/kmsg.
659neverallow appdomain kernel:system { syslog_read syslog_mod syslog_console };
660
661# SELinux is not an API for apps to use
662neverallow { appdomain -shell } *:security { compute_av check_context };
663neverallow { appdomain -shell } *:netlink_selinux_socket *;
664
665# Ability to perform any filesystem operation other than statfs(2).
666# i.e. no mount(2), unmount(2), etc.
667neverallow appdomain fs_type:filesystem ~getattr;
668
669# prevent creation/manipulation of globally readable symlinks
670neverallow appdomain {
671  apk_data_file
672  cache_file
673  cache_recovery_file
674  dev_type
675  rootfs
676  system_file
677  tmpfs
678}:lnk_file no_w_file_perms;
679
680# Applications should use the activity model for receiving events
681neverallow {
682  appdomain
683  -shell # bugreport
684} input_device:chr_file ~getattr;
685
686# Do not allow access to Bluetooth-related system properties except for a few allowed domains.
687# neverallow rules for access to Bluetooth-related data files are above.
688neverallow {
689  appdomain
690  -bluetooth
691  -system_app
692} { bluetooth_audio_hal_prop bluetooth_a2dp_offload_prop bluetooth_prop exported_bluetooth_prop }:file create_file_perms;
693
694# allow system_app to access Nfc-related system properties.
695set_prop(system_app, nfc_prop)
696
697# allow system_app to access radio_config system properties.
698set_prop(system_app, radio_control_prop)
699
700# Apps cannot access proc_uid_time_in_state
701neverallow appdomain proc_uid_time_in_state:file *;
702
703# Apps cannot access proc_uid_concurrent_active_time
704neverallow appdomain proc_uid_concurrent_active_time:file *;
705
706# Apps cannot access proc_uid_concurrent_policy_time
707neverallow appdomain proc_uid_concurrent_policy_time:file *;
708
709# Apps cannot access proc_uid_cpupower
710neverallow appdomain proc_uid_cpupower:file *;
711
712# Apps may not read /proc/net/{tcp,tcp6,udp,udp6}. These files leak information across the
713# application boundary. VPN apps may use the ConnectivityManager.getConnectionOwnerUid() API to
714# perform UID lookups.
715neverallow { appdomain -shell } proc_net_tcp_udp:file *;
716
717# Apps cannot access bootstrap files. The bootstrap files are only for
718# extremely early processes (like init, etc.) which are started before
719# the runtime APEX is activated and Bionic libs are provided from there.
720# If app process accesses (or even load/execute) the bootstrap files,
721# it might cause problems such as ODR violation, etc.
722neverallow appdomain system_bootstrap_lib_file:file
723    { open read write append execute execute_no_trans map };
724neverallow appdomain system_bootstrap_lib_file:dir
725    { open read getattr search };
726
727# Sensitive app domains are not allowed to execute from /data
728# to prevent persistence attacks and ensure all code is executed
729# from read-only locations.
730neverallow {
731  bluetooth
732  isolated_app_all
733  nfc
734  radio
735  shared_relro
736  sdk_sandbox_all
737  system_app
738} {
739  data_file_type
740  -apex_art_data_file
741  -dalvikcache_data_file
742  -system_data_file # shared libs in apks
743  -apk_data_file
744}:file no_x_file_perms;
745
746# Don't allow apps access to any of the following character devices.
747neverallow appdomain {
748    audio_device
749    camera_device
750    dm_device
751    radio_device
752    rpmsg_device
753}:chr_file { read write };
754
755# Block video device access for all apps except the DeviceAsWebcam Service which
756# needs access to /dev/video* for interfacing with the host
757neverallow {
758    appdomain
759    -device_as_webcam
760} video_device:chr_file { read write };
761
762# Prevent calling inotify on APKs. This can be used as a side channel
763# to observer app launches, so it must be disallowed. b/231587164
764# Gate by targetSdkVersion to avoid breaking existing apps.
765neverallow {
766  appdomain
767  -untrusted_app_25
768  -untrusted_app_27
769  -untrusted_app_29
770  -untrusted_app_30
771  -untrusted_app_32
772} apk_data_file:dir { watch watch_reads };
773neverallow {
774  appdomain
775  -untrusted_app_25
776  -untrusted_app_27
777  -untrusted_app_29
778  -untrusted_app_30
779  -untrusted_app_32
780} apk_data_file:file { watch watch_reads };
781
782neverallow appdomain system_server:udp_socket {
783        accept append bind create ioctl listen lock name_bind
784        relabelfrom relabelto setattr shutdown };
785
786# Transition to a non-app domain.
787# Exception for the shell and su domains, can transition to runas, etc.
788# Exception for crash_dump to allow for app crash reporting.
789# Exception for renderscript binaries (/system/bin/bcc, /system/bin/ld.mc)
790# to allow renderscript to create privileged executable files.
791# Exception for virtualizationmanager to allow running VMs as child processes.
792neverallow { appdomain -shell userdebug_or_eng(`-su') }
793    { domain -appdomain -crash_dump -rs -virtualizationmanager }:process { transition };
794neverallow { appdomain -shell userdebug_or_eng(`-su') }
795    { domain -appdomain }:process { dyntransition };
796
797# Don't allow regular apps access to storage configuration properties.
798neverallow { appdomain -mediaprovider_app } storage_config_prop:file no_rw_file_perms;
799
800# Don't allow apps reading /system/etc/font_fallback.xml
801dontaudit appdomain system_font_fallback_file:file no_rw_file_perms;
802neverallow appdomain system_font_fallback_file:file no_rw_file_perms;
803
804neverallow { appdomain -shell } tombstone_data_file:file ~{ getattr read };
805is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
806  # Files and directories that apps write to their storage areas
807  # should have type storage_area_content_file
808  type_transition {
809    appdomain
810    -isolated_app_all
811    -ephemeral_app
812    -sdk_sandbox_all
813  } storage_area_dir:{ notdevfile_class_set dir } storage_area_content_file;
814')
815