blob: 898182ced317fce776dd122002f6d57ef8be1e51 [file] [log] [blame]
RafayKamraneaa18ce2021-10-27 14:12:44 +00001# /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
Charles Chenccf80142023-01-20 03:34:19 +00008 -isolated_app_all
Maciej Żenczykowski81a860e2025-01-21 20:32:31 -08009 -network_stack
RafayKamraneaa18ce2021-10-27 14:12:44 +000010 -platform_app
11 -priv_app
12 -shell
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +000013 -sdk_sandbox_all
RafayKamraneaa18ce2021-10-27 14:12:44 +000014 -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
Charles Chenccf80142023-01-20 03:34:19 +000022 -isolated_app_all
Maciej Żenczykowski81a860e2025-01-21 20:32:31 -080023 -network_stack
RafayKamraneaa18ce2021-10-27 14:12:44 +000024 -platform_app
25 -priv_app
26 -shell
27 -su
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +000028 -sdk_sandbox_all
RafayKamraneaa18ce2021-10-27 14:12:44 +000029 -system_app
30 -untrusted_app_all
31 } proc_net_type:{ dir file lnk_file } { getattr open read };
32')
33
William Hester5f486c72019-01-15 13:39:30 -080034# 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
Inseob Kimdbcc4592020-05-21 20:12:55 +090038get_prop(appdomain, boot_status_prop)
Jiakai Zhang22fb5c72023-03-30 15:50:05 +010039get_prop(appdomain, dalvik_config_prop_type)
Inseob Kimdddf6f52020-07-06 22:24:11 +090040get_prop(appdomain, media_config_prop)
Inseob Kim5eacf722020-07-01 01:27:49 +090041get_prop(appdomain, packagemanager_config_prop)
Inseob Kim4ae7ec12020-08-03 14:29:47 +090042get_prop(appdomain, radio_control_prop)
Inseob Kimdbcc4592020-05-21 20:12:55 +090043get_prop(appdomain, surfaceflinger_color_prop)
44get_prop(appdomain, systemsound_config_prop)
Inseob Kim641cffe2020-06-05 10:40:16 +090045get_prop(appdomain, telephony_config_prop)
Inseob Kimdbcc4592020-05-21 20:12:55 +090046get_prop(appdomain, userspace_reboot_config_prop)
47get_prop(appdomain, vold_config_prop)
Hongguang Chen67c36882020-07-27 15:15:53 -070048get_prop(appdomain, adbd_config_prop)
Thierry Strudelf4e3b062021-12-22 19:13:25 -080049get_prop(appdomain, dck_prop)
Evan Rosky5cfdf2b2022-03-02 22:13:58 +000050get_prop(appdomain, persist_wm_debug_prop)
Alexander Roederer829d9742023-03-23 02:19:22 +000051get_prop(appdomain, persist_sysui_builder_extras_prop)
Alexander Roederer584a8622023-05-31 21:25:50 +000052get_prop(appdomain, persist_sysui_ranking_update_prop)
Inseob Kimdbcc4592020-05-21 20:12:55 +090053
Ioannis Ilkos8d168e22023-02-10 17:52:19 +000054# Allow the heap dump ART plugin to the count of sessions waiting for OOME
55get_prop(appdomain, traced_oome_heap_session_count_prop)
56
Sandro080c5792022-11-03 14:44:35 +000057# 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
Jeff Vander Stoep607bc672019-12-16 10:59:03 +010063# 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;
Jeff Vander Stoep67896ee2020-04-02 13:36:17 +020078# Apps should not be reading vendor-defined properties.
79dontaudit appdomain vendor_default_prop:file read;
Jeff Vander Stoep607bc672019-12-16 10:59:03 +010080
Zimb61bcc82021-04-08 12:20:26 +010081# Access to /mnt/media_rw/<vol> (limited by DAC to apps with external_storage gid)
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +000082allow { appdomain -sdk_sandbox_all } mnt_media_rw_file:dir search;
Zimb61bcc82021-04-08 12:20:26 +010083
Jeff Vander Stoep72957212022-07-01 10:08:34 +020084# 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
Inseob Kimc80b0242020-07-16 22:25:47 +090089# Allow to read sendbug.preferred.domain
90get_prop(appdomain, sendbug_config_prop)
91
Peiyong Lin37dea072020-06-03 12:20:41 -070092# Allow to read graphics related properties.
93get_prop(appdomain, graphics_config_prop)
Inseob Kimc97a97c2020-07-20 20:26:07 +090094
95# Allow to read persist.config.calibration_fac
96get_prop(appdomain, camera_calibration_prop)
Inseob Kim0cef0fe2020-11-17 13:54:52 +090097
98# Allow to read db.log.detailed, db.log.slow_query_threshold*
99get_prop(appdomain, sqlite_log_prop)
Orion Hodson8f75f762020-10-16 15:29:55 +0100100
Felipe Lemeb85242c2022-04-21 17:49:05 -0700101# 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
Seigo Nonaka9c3707f2021-01-21 13:08:31 -0800104# 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
Martijn Coenen4825e862021-03-29 13:51:35 +0200108# Enter /data/misc/apexdata/
109allow appdomain apex_module_data_file:dir search;
Orion Hodson13ee6532021-04-27 15:51:33 +0100110# Read /data/misc/apexdata/com.android.art, execute signed AOT artifacts.
Martijn Coenen4825e862021-03-29 13:51:35 +0200111allow appdomain apex_art_data_file:dir r_dir_perms;
Orion Hodson13ee6532021-04-27 15:51:33 +0100112allow appdomain apex_art_data_file:file rx_file_perms;
Orion Hodson8f75f762020-10-16 15:29:55 +0100113
Josh Gaoce1c4a52021-02-03 18:35:06 -0800114# Allow access to tombstones if an fd to one is given to you.
Florian Mayer6c689e82024-02-14 10:54:58 -0800115# An app cannot open the tombstone itself because it lacks `open`.
Josh Gaoce1c4a52021-02-03 18:35:06 -0800116allow appdomain tombstone_data_file:file { getattr read };
Josh Gaoce1c4a52021-02-03 18:35:06 -0800117
RafayKamraneaa18ce2021-10-27 14:12:44 +0000118# Execute the shell or other system executables.
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000119allow { 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;')
RafayKamraneaa18ce2021-10-27 14:12:44 +0000122
123# Allow apps access to /vendor/app except for privileged
124# apps which cannot be in /vendor.
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000125r_dir_file({ appdomain -ephemeral_app -sdk_sandbox_all }, vendor_app_file)
126allow { appdomain -ephemeral_app -sdk_sandbox_all } vendor_app_file:file execute;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000127
Seungjae Yoo01c4f572024-02-13 13:47:36 +0900128# 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
Nikita Ioffee2da6332022-02-21 17:55:59 +0000131# Perform binder IPC to sdk sandbox.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000132binder_call(appdomain, sdk_sandbox_all)
RafayKamraneaa18ce2021-10-27 14:12:44 +0000133
Jan Sebechlebsky6e1795c2023-12-06 09:31:17 +0100134# Allow apps to communicate via binder with virtual camera service.
135binder_call(appdomain, virtual_camera)
136
RafayKamraneaa18ce2021-10-27 14:12:44 +0000137# 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
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000139allow { 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;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000143
144# Read/write visible storage
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000145allow { 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;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000147# This should be removed if sdcardfs is modified to alter the secontext for its
148# accesses to the underlying FS.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000149allow { 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;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000151
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.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000157allow { 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 };
RafayKamraneaa18ce2021-10-27 14:12:44 +0000159
160#logd access
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000161control_logd({ appdomain -ephemeral_app -sdk_sandbox_all })
RafayKamraneaa18ce2021-10-27 14:12:44 +0000162
163# application inherit logd write socket (urge is to deprecate this long term)
Michael Groover38deee72024-10-07 22:12:09 -0500164allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore:keystore2_key { delete use get_info grant rebind update };
RafayKamraneaa18ce2021-10-27 14:12:44 +0000165
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000166allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore_maintenance_service:service_manager find;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000167
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000168use_keystore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all })
RafayKamraneaa18ce2021-10-27 14:12:44 +0000169
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000170use_credstore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all })
RafayKamraneaa18ce2021-10-27 14:12:44 +0000171
Shawn Willdena15e9ce2024-09-17 13:12:52 -0600172allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } persistent_data_block_service:service_manager find;
173
RafayKamraneaa18ce2021-10-27 14:12:44 +0000174# For app fuse.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000175pdx_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)
RafayKamraneaa18ce2021-10-27 14:12:44 +0000179# Apps do not directly open the IPC socket for bufferhubd.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000180pdx_use({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, bufferhub_client)
RafayKamraneaa18ce2021-10-27 14:12:44 +0000181
182# Apps receive an open tun fd from the framework for
183# device traffic. Do not allow untrusted app to directly open tun_device
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000184allow { 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;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000186
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000187
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
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000211allow { 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;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000213
214# Search /storage/emulated tmpfs mount.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000215allow { appdomain -sdk_sandbox_all } tmpfs:dir r_dir_perms;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000216
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.
Ellen Arteca27b515e2024-04-30 20:26:55 +0000249allow { 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;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000272
273# Access via already open fds is ok even for mlstrustedsubject.
Ellen Arteca27b515e2024-04-30 20:26:55 +0000274allow { 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 };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000280
Gavin Corkeryd4d3c012023-05-10 16:13:53 +0000281# Access open fds from SDK sandbox
282allow appdomain sdk_sandbox_data_file:file { getattr read };
283
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000284# 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
Charles Chenccf80142023-01-20 03:34:19 +0000293r_dir_file({ appdomain -isolated_app_all }, textclassifier_data_file)
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000294
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
Charles Chenccf80142023-01-20 03:34:19 +0000312 allow { appdomain -isolated_app_all } vendor_file:dir { open read };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000313')
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).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000327allow appdomain wallpaper_file:file { getattr read write map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000328
329# Read/write cached ringtones (opened by system).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000330allow appdomain ringtone_file:file { getattr read write map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000331
332# Read ShortcutManager icon files (opened by system).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000333allow appdomain shortcut_manager_icons:file { getattr read map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000334
335# Read icon file (opened by system).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000336allow appdomain icon_file:file { getattr read map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000337
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;
Jiakai Zhang4c3f1b62025-03-05 06:32:13 -0800374allow appdomain user_profile_data_file:dir rw_dir_perms;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000375allow appdomain user_profile_data_file:file create_file_perms;
376
Ryan Savitski941ba722023-02-02 14:24:45 +0000377# 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
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000383# 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.
Charles Chenccf80142023-01-20 03:34:19 +0000393allow { 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;
Jason Macnak365024e2022-02-24 18:32:16 +0000396
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000397
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.
Charles Chenccf80142023-01-20 03:34:19 +0000407binder_call({ appdomain -isolated_app_all }, gpuservice)
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000408
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.
Joseph Murphy29e57302024-03-20 18:23:46 +0000416allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000417
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.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000428allow { appdomain -isolated_app_all -sdk_sandbox_all } media_rw_data_file:file { read getattr };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000429
430# Read and write /data/data/com.android.providers.telephony files passed over Binder.
Charles Chenccf80142023-01-20 03:34:19 +0000431allow { appdomain -isolated_app_all } radio_data_file:file { read write getattr };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000432
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
Jeff Vander Stoep3fbb1772023-03-27 10:03:46 +0200442allow 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 };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000444
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
Charles Chenccf80142023-01-20 03:34:19 +0000460allow { 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;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000463
464# Allow AAudio apps to use shared memory file descriptors from the HAL
Charles Chenccf80142023-01-20 03:34:19 +0000465allow { appdomain -isolated_app_all } hal_audio:fd use;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000466
467# Allow app to access shared memory created by camera HAL1
Charles Chenccf80142023-01-20 03:34:19 +0000468allow { appdomain -isolated_app_all } hal_camera:fd use;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000469
470# Allow apps to access shared memory file descriptor from the tuner HAL
Charles Chenccf80142023-01-20 03:34:19 +0000471allow {appdomain -isolated_app_all} hal_tv_tuner_server:fd use;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000472
Matt Buckley52c9b3b2024-02-26 16:38:17 -0800473# Allow app to access shared memory created by PowerHAL for FMQ use
474allow { appdomain -isolated_app_all } hal_power_server:fd use;
475
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000476# RenderScript always-passthrough HAL
Charles Chenccf80142023-01-20 03:34:19 +0000477allow { appdomain -isolated_app_all } hal_renderscript_hwservice:hwservice_manager find;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000478allow 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
Miranda Huangd07ee242024-08-16 22:42:40 +0000495get_prop(appdomain, high_barometer_quality_prop)
496
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000497# 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
Inseob Kim75806ef2024-03-27 17:18:41 +0900516###
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.
Armelle Laine967f7182025-03-17 10:28:50 +0000612neverallow appdomain mediadrm_system_data_file:dir_file_class_set
613 { create write setattr relabelfrom relabelto append unlink link rename };
Inseob Kim75806ef2024-03-27 17:18:41 +0900614neverallow appdomain drm_data_file:dir_file_class_set
615 { create write setattr relabelfrom relabelto append unlink link rename };
616neverallow { appdomain -platform_app }
617 apk_data_file:dir_file_class_set
618 { create write setattr relabelfrom relabelto append unlink link rename };
619neverallow { appdomain -platform_app }
620 apk_private_data_file:dir_file_class_set
621 { create write setattr relabelfrom relabelto append unlink link rename };
622neverallow { appdomain -platform_app }
623 apk_private_tmp_file:dir_file_class_set
624 { create write setattr relabelfrom relabelto append unlink link rename };
625neverallow { appdomain -shell }
626 shell_data_file:dir_file_class_set
627 { create setattr relabelfrom relabelto append unlink link rename };
628neverallow { appdomain -bluetooth }
629 bluetooth_data_file:dir_file_class_set
630 { create write setattr relabelfrom relabelto append unlink link rename };
631neverallow { domain -credstore -init } credstore_data_file:dir_file_class_set *;
632neverallow appdomain
633 keystore_data_file:dir_file_class_set
634 { create write setattr relabelfrom relabelto append unlink link rename };
635neverallow appdomain
636 systemkeys_data_file:dir_file_class_set
637 { create write setattr relabelfrom relabelto append unlink link rename };
638neverallow appdomain
639 wifi_data_file:dir_file_class_set
640 { create write setattr relabelfrom relabelto append unlink link rename };
641neverallow appdomain
642 dhcp_data_file:dir_file_class_set
643 { create write setattr relabelfrom relabelto append unlink link rename };
644
645# access tmp apk files
646neverallow { appdomain -platform_app }
647 apk_tmp_file:dir_file_class_set
648 { create write setattr relabelfrom relabelto append unlink link rename };
649
Inseob Kim75806ef2024-03-27 17:18:41 +0900650# Access to factory files.
651neverallow appdomain efs_file:dir_file_class_set write;
652neverallow { appdomain -shell } efs_file:dir_file_class_set read;
653
654# Write to various pseudo file systems.
655neverallow { appdomain -bluetooth -nfc }
656 sysfs:dir_file_class_set write;
657neverallow appdomain
658 proc:dir_file_class_set write;
659
660# Access to syslog(2) or /proc/kmsg.
Marko Man1b2f74f2020-10-12 16:05:12 +0200661neverallow { appdomain -system_app -shell -platform_app -priv_app }
662 kernel:system { syslog_read syslog_mod syslog_console };
Inseob Kim75806ef2024-03-27 17:18:41 +0900663
664# SELinux is not an API for apps to use
665neverallow { appdomain -shell } *:security { compute_av check_context };
666neverallow { appdomain -shell } *:netlink_selinux_socket *;
667
668# Ability to perform any filesystem operation other than statfs(2).
669# i.e. no mount(2), unmount(2), etc.
670neverallow appdomain fs_type:filesystem ~getattr;
671
672# prevent creation/manipulation of globally readable symlinks
673neverallow appdomain {
674 apk_data_file
675 cache_file
676 cache_recovery_file
677 dev_type
678 rootfs
679 system_file
680 tmpfs
681}:lnk_file no_w_file_perms;
682
683# Applications should use the activity model for receiving events
684neverallow {
685 appdomain
686 -shell # bugreport
687} input_device:chr_file ~getattr;
688
689# Do not allow access to Bluetooth-related system properties except for a few allowed domains.
690# neverallow rules for access to Bluetooth-related data files are above.
691neverallow {
692 appdomain
693 -bluetooth
694 -system_app
695} { bluetooth_audio_hal_prop bluetooth_a2dp_offload_prop bluetooth_prop exported_bluetooth_prop }:file create_file_perms;
696
697# allow system_app to access Nfc-related system properties.
698set_prop(system_app, nfc_prop)
699
700# allow system_app to access radio_config system properties.
701set_prop(system_app, radio_control_prop)
702
703# Apps cannot access proc_uid_time_in_state
704neverallow appdomain proc_uid_time_in_state:file *;
705
706# Apps cannot access proc_uid_concurrent_active_time
707neverallow appdomain proc_uid_concurrent_active_time:file *;
708
709# Apps cannot access proc_uid_concurrent_policy_time
710neverallow appdomain proc_uid_concurrent_policy_time:file *;
711
712# Apps cannot access proc_uid_cpupower
713neverallow appdomain proc_uid_cpupower:file *;
714
715# Apps may not read /proc/net/{tcp,tcp6,udp,udp6}. These files leak information across the
716# application boundary. VPN apps may use the ConnectivityManager.getConnectionOwnerUid() API to
717# perform UID lookups.
718neverallow { appdomain -shell } proc_net_tcp_udp:file *;
719
720# Apps cannot access bootstrap files. The bootstrap files are only for
721# extremely early processes (like init, etc.) which are started before
722# the runtime APEX is activated and Bionic libs are provided from there.
723# If app process accesses (or even load/execute) the bootstrap files,
724# it might cause problems such as ODR violation, etc.
725neverallow appdomain system_bootstrap_lib_file:file
726 { open read write append execute execute_no_trans map };
727neverallow appdomain system_bootstrap_lib_file:dir
728 { open read getattr search };
729
Orion Hodson8f75f762020-10-16 15:29:55 +0100730# Sensitive app domains are not allowed to execute from /data
731# to prevent persistence attacks and ensure all code is executed
732# from read-only locations.
733neverallow {
734 bluetooth
Charles Chenccf80142023-01-20 03:34:19 +0000735 isolated_app_all
Orion Hodson8f75f762020-10-16 15:29:55 +0100736 nfc
737 radio
738 shared_relro
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000739 sdk_sandbox_all
Orion Hodson8f75f762020-10-16 15:29:55 +0100740 system_app
741} {
742 data_file_type
743 -apex_art_data_file
744 -dalvikcache_data_file
745 -system_data_file # shared libs in apks
746 -apk_data_file
Avichal Rakeshe0929242023-01-23 23:49:50 -0800747}:file no_x_file_perms;
748
749# Don't allow apps access to any of the following character devices.
750neverallow appdomain {
751 audio_device
752 camera_device
753 dm_device
754 radio_device
755 rpmsg_device
756}:chr_file { read write };
757
758# Block video device access for all apps except the DeviceAsWebcam Service which
759# needs access to /dev/video* for interfacing with the host
760neverallow {
761 appdomain
762 -device_as_webcam
763} video_device:chr_file { read write };
Jeff Vander Stoepf9a774f2023-03-27 12:30:23 +0200764
765# Prevent calling inotify on APKs. This can be used as a side channel
766# to observer app launches, so it must be disallowed. b/231587164
767# Gate by targetSdkVersion to avoid breaking existing apps.
768neverallow {
769 appdomain
770 -untrusted_app_25
771 -untrusted_app_27
772 -untrusted_app_29
773 -untrusted_app_30
774 -untrusted_app_32
775} apk_data_file:dir { watch watch_reads };
776neverallow {
777 appdomain
778 -untrusted_app_25
779 -untrusted_app_27
780 -untrusted_app_29
781 -untrusted_app_30
782 -untrusted_app_32
783} apk_data_file:file { watch watch_reads };
Inseob Kim75806ef2024-03-27 17:18:41 +0900784
785neverallow appdomain system_server:udp_socket {
786 accept append bind create ioctl listen lock name_bind
787 relabelfrom relabelto setattr shutdown };
788
789# Transition to a non-app domain.
790# Exception for the shell and su domains, can transition to runas, etc.
791# Exception for crash_dump to allow for app crash reporting.
792# Exception for renderscript binaries (/system/bin/bcc, /system/bin/ld.mc)
793# to allow renderscript to create privileged executable files.
794# Exception for virtualizationmanager to allow running VMs as child processes.
795neverallow { appdomain -shell userdebug_or_eng(`-su') }
796 { domain -appdomain -crash_dump -rs -virtualizationmanager }:process { transition };
797neverallow { appdomain -shell userdebug_or_eng(`-su') }
798 { domain -appdomain }:process { dyntransition };
799
800# Don't allow regular apps access to storage configuration properties.
801neverallow { appdomain -mediaprovider_app } storage_config_prop:file no_rw_file_perms;
802
803# Don't allow apps reading /system/etc/font_fallback.xml
804dontaudit appdomain system_font_fallback_file:file no_rw_file_perms;
805neverallow appdomain system_font_fallback_file:file no_rw_file_perms;
806
807neverallow { appdomain -shell } tombstone_data_file:file ~{ getattr read };
Ellen Arteca27b515e2024-04-30 20:26:55 +0000808is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
809 # Files and directories that apps write to their storage areas
810 # should have type storage_area_content_file
811 type_transition {
812 appdomain
813 -isolated_app_all
814 -ephemeral_app
815 -sdk_sandbox_all
816 } storage_area_dir:{ notdevfile_class_set dir } storage_area_content_file;
817')