blob: 1dd7fda424805dff59f235e0e3af4fd087602f71 [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
RafayKamraneaa18ce2021-10-27 14:12:44 +00009 -platform_app
10 -priv_app
11 -shell
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +000012 -sdk_sandbox_all
RafayKamraneaa18ce2021-10-27 14:12:44 +000013 -system_app
14 -untrusted_app_all
15}, proc_net_type)
16# audit access for all these non-core app domains.
17userdebug_or_eng(`
18 auditallow {
19 appdomain
20 -ephemeral_app
Charles Chenccf80142023-01-20 03:34:19 +000021 -isolated_app_all
RafayKamraneaa18ce2021-10-27 14:12:44 +000022 -platform_app
23 -priv_app
24 -shell
25 -su
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +000026 -sdk_sandbox_all
RafayKamraneaa18ce2021-10-27 14:12:44 +000027 -system_app
28 -untrusted_app_all
29 } proc_net_type:{ dir file lnk_file } { getattr open read };
30')
31
William Hester5f486c72019-01-15 13:39:30 -080032# Allow apps to read the Test Harness Mode property. This property is used in
33# the implementation of ActivityManager.isDeviceInTestHarnessMode()
34get_prop(appdomain, test_harness_prop)
35
Inseob Kimdbcc4592020-05-21 20:12:55 +090036get_prop(appdomain, boot_status_prop)
Jiakai Zhang22fb5c72023-03-30 15:50:05 +010037get_prop(appdomain, dalvik_config_prop_type)
Inseob Kimdddf6f52020-07-06 22:24:11 +090038get_prop(appdomain, media_config_prop)
Inseob Kim5eacf722020-07-01 01:27:49 +090039get_prop(appdomain, packagemanager_config_prop)
Inseob Kim4ae7ec12020-08-03 14:29:47 +090040get_prop(appdomain, radio_control_prop)
Inseob Kimdbcc4592020-05-21 20:12:55 +090041get_prop(appdomain, surfaceflinger_color_prop)
42get_prop(appdomain, systemsound_config_prop)
Inseob Kim641cffe2020-06-05 10:40:16 +090043get_prop(appdomain, telephony_config_prop)
Inseob Kimdbcc4592020-05-21 20:12:55 +090044get_prop(appdomain, userspace_reboot_config_prop)
45get_prop(appdomain, vold_config_prop)
Hongguang Chen67c36882020-07-27 15:15:53 -070046get_prop(appdomain, adbd_config_prop)
Thierry Strudelf4e3b062021-12-22 19:13:25 -080047get_prop(appdomain, dck_prop)
Evan Rosky5cfdf2b2022-03-02 22:13:58 +000048get_prop(appdomain, persist_wm_debug_prop)
Alexander Roederer829d9742023-03-23 02:19:22 +000049get_prop(appdomain, persist_sysui_builder_extras_prop)
Alexander Roederer584a8622023-05-31 21:25:50 +000050get_prop(appdomain, persist_sysui_ranking_update_prop)
Inseob Kimdbcc4592020-05-21 20:12:55 +090051
Ioannis Ilkos8d168e22023-02-10 17:52:19 +000052# Allow the heap dump ART plugin to the count of sessions waiting for OOME
53get_prop(appdomain, traced_oome_heap_session_count_prop)
54
Sandro080c5792022-11-03 14:44:35 +000055# Allow to read ro.vendor.camera.extensions.enabled
56get_prop(appdomain, camera2_extensions_prop)
57
58# Allow to ro.camerax.extensions.enabled
59get_prop(appdomain, camerax_extensions_prop)
60
Jeff Vander Stoep607bc672019-12-16 10:59:03 +010061# Prevent apps from causing presubmit failures.
62# Apps can cause selinux denials by accessing CE storage
63# and/or external storage. In either case, the selinux denial is
64# not the cause of the failure, but just a symptom that
65# storage isn't ready. Many apps handle the failure appropriately.
66#
67# Apps cannot access external storage before it becomes available.
68dontaudit appdomain storage_stub_file:dir getattr;
69# Attempts to write to system_data_file is generally a sign
70# that apps are attempting to access encrypted storage before
71# the ACTION_USER_UNLOCKED intent is delivered. Apps are not
72# allowed to write to CE storage before it's available.
73# Attempting to do so will be blocked by both selinux and unix
74# permissions.
75dontaudit appdomain system_data_file:dir write;
Jeff Vander Stoep67896ee2020-04-02 13:36:17 +020076# Apps should not be reading vendor-defined properties.
77dontaudit appdomain vendor_default_prop:file read;
Jeff Vander Stoep607bc672019-12-16 10:59:03 +010078
Zimb61bcc82021-04-08 12:20:26 +010079# Access to /mnt/media_rw/<vol> (limited by DAC to apps with external_storage gid)
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +000080allow { appdomain -sdk_sandbox_all } mnt_media_rw_file:dir search;
Zimb61bcc82021-04-08 12:20:26 +010081
Jeff Vander Stoep72957212022-07-01 10:08:34 +020082# allow apps to use UDP sockets provided by the system server but not
83# modify them other than to connect
84allow appdomain system_server:udp_socket {
85 connect getattr read recvfrom sendto write getopt setopt };
86
Inseob Kimc80b0242020-07-16 22:25:47 +090087# Allow to read sendbug.preferred.domain
88get_prop(appdomain, sendbug_config_prop)
89
Peiyong Lin37dea072020-06-03 12:20:41 -070090# Allow to read graphics related properties.
91get_prop(appdomain, graphics_config_prop)
Inseob Kimc97a97c2020-07-20 20:26:07 +090092
93# Allow to read persist.config.calibration_fac
94get_prop(appdomain, camera_calibration_prop)
Inseob Kim0cef0fe2020-11-17 13:54:52 +090095
96# Allow to read db.log.detailed, db.log.slow_query_threshold*
97get_prop(appdomain, sqlite_log_prop)
Orion Hodson8f75f762020-10-16 15:29:55 +010098
Felipe Lemeb85242c2022-04-21 17:49:05 -070099# Allow to read system_user_mode_emulation_prop, which is used by UserManager.java
100userdebug_or_eng(`get_prop(appdomain, system_user_mode_emulation_prop)')
101
Seigo Nonaka9c3707f2021-01-21 13:08:31 -0800102# Allow font file read by apps.
103allow appdomain font_data_file:file r_file_perms;
104allow appdomain font_data_file:dir r_dir_perms;
105
Martijn Coenen4825e862021-03-29 13:51:35 +0200106# Enter /data/misc/apexdata/
107allow appdomain apex_module_data_file:dir search;
Orion Hodson13ee6532021-04-27 15:51:33 +0100108# Read /data/misc/apexdata/com.android.art, execute signed AOT artifacts.
Martijn Coenen4825e862021-03-29 13:51:35 +0200109allow appdomain apex_art_data_file:dir r_dir_perms;
Orion Hodson13ee6532021-04-27 15:51:33 +0100110allow appdomain apex_art_data_file:file rx_file_perms;
Orion Hodson8f75f762020-10-16 15:29:55 +0100111
Josh Gaoce1c4a52021-02-03 18:35:06 -0800112# Allow access to tombstones if an fd to one is given to you.
Florian Mayer6c689e82024-02-14 10:54:58 -0800113# An app cannot open the tombstone itself because it lacks `open`.
Josh Gaoce1c4a52021-02-03 18:35:06 -0800114allow appdomain tombstone_data_file:file { getattr read };
Josh Gaoce1c4a52021-02-03 18:35:06 -0800115
RafayKamraneaa18ce2021-10-27 14:12:44 +0000116# Execute the shell or other system executables.
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000117allow { appdomain -ephemeral_app -sdk_sandbox_all } shell_exec:file rx_file_perms;
118allow { appdomain -ephemeral_app -sdk_sandbox_all } toolbox_exec:file rx_file_perms;
119not_full_treble(`allow { appdomain -ephemeral_app -sdk_sandbox_all } vendor_file:file x_file_perms;')
RafayKamraneaa18ce2021-10-27 14:12:44 +0000120
121# Allow apps access to /vendor/app except for privileged
122# apps which cannot be in /vendor.
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000123r_dir_file({ appdomain -ephemeral_app -sdk_sandbox_all }, vendor_app_file)
124allow { appdomain -ephemeral_app -sdk_sandbox_all } vendor_app_file:file execute;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000125
Seungjae Yoo01c4f572024-02-13 13:47:36 +0900126# Allow apps to read microdroid related files in vendor partition for CTS purpose.
127r_dir_file({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, vendor_microdroid_file)
128
Nikita Ioffee2da6332022-02-21 17:55:59 +0000129# Perform binder IPC to sdk sandbox.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000130binder_call(appdomain, sdk_sandbox_all)
RafayKamraneaa18ce2021-10-27 14:12:44 +0000131
Jan Sebechlebsky6e1795c2023-12-06 09:31:17 +0100132# Allow apps to communicate via binder with virtual camera service.
133binder_call(appdomain, virtual_camera)
134
RafayKamraneaa18ce2021-10-27 14:12:44 +0000135# Allow access to external storage; we have several visible mount points under /storage
136# and symlinks to primary storage at places like /storage/sdcard0 and /mnt/user/0/primary
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000137allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } storage_file:dir r_dir_perms;
138allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } storage_file:lnk_file r_file_perms;
139allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } mnt_user_file:dir r_dir_perms;
140allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } mnt_user_file:lnk_file r_file_perms;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000141
142# Read/write visible storage
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000143allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } { sdcard_type fuse }:dir create_dir_perms;
144allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } { sdcard_type fuse }:file create_file_perms;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000145# This should be removed if sdcardfs is modified to alter the secontext for its
146# accesses to the underlying FS.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000147allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } media_rw_data_file:dir create_dir_perms;
148allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } media_rw_data_file:file create_file_perms;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000149
150# Allow apps to use the USB Accessory interface.
151# http://developer.android.com/guide/topics/connectivity/usb/accessory.html
152#
153# USB devices are first opened by the system server (USBDeviceManagerService)
154# and the file descriptor is passed to the right Activity via binder.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000155allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } usb_device:chr_file { read write getattr ioctl };
156allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } usbaccessory_device:chr_file { read write getattr };
RafayKamraneaa18ce2021-10-27 14:12:44 +0000157
158#logd access
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000159control_logd({ appdomain -ephemeral_app -sdk_sandbox_all })
RafayKamraneaa18ce2021-10-27 14:12:44 +0000160
161# application inherit logd write socket (urge is to deprecate this long term)
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000162allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore:keystore2_key { delete use get_info rebind update };
RafayKamraneaa18ce2021-10-27 14:12:44 +0000163
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000164allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore_maintenance_service:service_manager find;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000165
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000166use_keystore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all })
RafayKamraneaa18ce2021-10-27 14:12:44 +0000167
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000168use_credstore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all })
RafayKamraneaa18ce2021-10-27 14:12:44 +0000169
170# For app fuse.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000171pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_client)
172pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_manager)
173pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_vsync)
174pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, performance_client)
RafayKamraneaa18ce2021-10-27 14:12:44 +0000175# Apps do not directly open the IPC socket for bufferhubd.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000176pdx_use({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, bufferhub_client)
RafayKamraneaa18ce2021-10-27 14:12:44 +0000177
178# Apps receive an open tun fd from the framework for
179# device traffic. Do not allow untrusted app to directly open tun_device
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000180allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } tun_device:chr_file { read write getattr append ioctl };
181allowxperm { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } tun_device:chr_file ioctl TUNGETIFF;
RafayKamraneaa18ce2021-10-27 14:12:44 +0000182
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000183
184# WebView and other application-specific JIT compilers
185allow appdomain self:process execmem;
186
187allow appdomain { ashmem_device ashmem_libcutils_device }:chr_file execute;
188
189# Receive and use open file descriptors inherited from zygote.
190allow appdomain zygote:fd use;
191
192# Receive and use open file descriptors inherited from app zygote.
193allow appdomain app_zygote:fd use;
194
195# gdbserver for ndk-gdb reads the zygote.
196# valgrind needs mmap exec for zygote
197allow appdomain zygote_exec:file rx_file_perms;
198
199# Notify zygote of death;
200allow appdomain zygote:process sigchld;
201
202# Read /data/dalvik-cache.
203allow appdomain dalvikcache_data_file:dir { search getattr };
204allow appdomain dalvikcache_data_file:file r_file_perms;
205
206# Read the /sdcard and /mnt/sdcard symlinks
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000207allow { appdomain -isolated_app_all -sdk_sandbox_all } rootfs:lnk_file r_file_perms;
208allow { appdomain -isolated_app_all -sdk_sandbox_all } tmpfs:lnk_file r_file_perms;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000209
210# Search /storage/emulated tmpfs mount.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000211allow { appdomain -sdk_sandbox_all } tmpfs:dir r_dir_perms;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000212
213# Notify zygote of the wrapped process PID when using --invoke-with.
214allow appdomain zygote:fifo_file write;
215
216userdebug_or_eng(`
217 # Allow apps to create and write method traces in /data/misc/trace.
218 allow appdomain method_trace_data_file:dir w_dir_perms;
219 allow appdomain method_trace_data_file:file { create w_file_perms };
220')
221
222# Notify shell and adbd of death when spawned via runas for ndk-gdb.
223allow appdomain shell:process sigchld;
224allow appdomain adbd:process sigchld;
225
226# child shell or gdbserver pty access for runas.
227allow appdomain devpts:chr_file { getattr read write ioctl };
228
229# Use pipes and sockets provided by system_server via binder or local socket.
230allow appdomain system_server:fd use;
231allow appdomain system_server:fifo_file rw_file_perms;
232allow appdomain system_server:unix_stream_socket { read write setopt getattr getopt shutdown };
233allow appdomain system_server:tcp_socket { read write getattr getopt shutdown };
234
235# For AppFuse.
236allow appdomain vold:fd use;
237
238# Communication with other apps via fifos
239allow appdomain appdomain:fifo_file rw_file_perms;
240
241# Communicate with surfaceflinger.
242allow appdomain surfaceflinger:unix_stream_socket { read write setopt getattr getopt shutdown };
243
244# App sandbox file accesses.
Ellen Arteca27b515e2024-04-30 20:26:55 +0000245allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } {
246 app_data_file
247 privapp_data_file
248 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
249}:dir create_dir_perms;
250allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } {
251 app_data_file
252 privapp_data_file
253 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
254}:file create_file_perms;
255
256is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `
257 # an app can read but cannot write to its own directory of storage areas
258 allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } storage_area_app_dir:dir r_dir_perms;
259 # an app can write to its storage areas
260 allow { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } storage_area_dir:dir rw_dir_perms;
261')
262
263allowxperm { appdomain -isolated_app_all -mlstrustedsubject -sdk_sandbox_all } {
264 app_data_file
265 privapp_data_file
266 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
267}:file ioctl FS_IOC_MEASURE_VERITY;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000268
269# Access via already open fds is ok even for mlstrustedsubject.
Ellen Arteca27b515e2024-04-30 20:26:55 +0000270allow { appdomain -isolated_app_all -sdk_sandbox_all } {
271 app_data_file
272 privapp_data_file
273 system_app_data_file
274 is_flag_enabled(RELEASE_UNLOCKED_STORAGE_API, `storage_area_content_file')
275}:file { getattr map read write };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000276
Gavin Corkeryd4d3c012023-05-10 16:13:53 +0000277# Access open fds from SDK sandbox
278allow appdomain sdk_sandbox_data_file:file { getattr read };
279
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000280# Traverse into expanded storage
281allow appdomain mnt_expand_file:dir r_dir_perms;
282
283# Keychain and user-trusted credentials
284r_dir_file(appdomain, keychain_data_file)
285allow appdomain misc_user_data_file:dir r_dir_perms;
286allow appdomain misc_user_data_file:file r_file_perms;
287
288# TextClassifier
Charles Chenccf80142023-01-20 03:34:19 +0000289r_dir_file({ appdomain -isolated_app_all }, textclassifier_data_file)
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000290
291# Access to OEM provided data and apps
292allow appdomain oemfs:dir r_dir_perms;
293allow appdomain oemfs:file rx_file_perms;
294
295allow appdomain system_file:file x_file_perms;
296
297# Renderscript needs the ability to read directories on /system
298allow appdomain system_file:dir r_dir_perms;
299allow appdomain system_file:lnk_file { getattr open read };
300# Renderscript specific permissions to open /system/vendor/lib64.
301not_full_treble(`
302 allow appdomain vendor_file_type:dir r_dir_perms;
303 allow appdomain vendor_file_type:lnk_file { getattr open read };
304')
305
306full_treble_only(`
307 # For looking up Renderscript vendor drivers
Charles Chenccf80142023-01-20 03:34:19 +0000308 allow { appdomain -isolated_app_all } vendor_file:dir { open read };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000309')
310
311# Allow apps access to /vendor/overlay
312r_dir_file(appdomain, vendor_overlay_file)
313
314# Allow apps access to /vendor/framework
315# for vendor provided libraries.
316r_dir_file(appdomain, vendor_framework_file)
317
318# Allow apps read / execute access to vendor public libraries.
319allow appdomain {vendor_public_framework_file vendor_public_lib_file}:dir r_dir_perms;
320allow appdomain {vendor_public_framework_file vendor_public_lib_file}:file { execute read open getattr map };
321
322# Read/write wallpaper file (opened by system).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000323allow appdomain wallpaper_file:file { getattr read write map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000324
325# Read/write cached ringtones (opened by system).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000326allow appdomain ringtone_file:file { getattr read write map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000327
328# Read ShortcutManager icon files (opened by system).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000329allow appdomain shortcut_manager_icons:file { getattr read map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000330
331# Read icon file (opened by system).
Jeffrey Vander Stoepb6c262c2023-12-07 13:56:15 +0000332allow appdomain icon_file:file { getattr read map };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000333
334# Old stack dumping scheme : append to a global trace file (/data/anr/traces.txt).
335#
336# TODO: All of these permissions except for anr_data_file:file append can be
337# withdrawn once we've switched to the new stack dumping mechanism, see b/32064548
338# and the rules below.
339allow appdomain anr_data_file:dir search;
340allow appdomain anr_data_file:file { open append };
341
342# New stack dumping scheme : request an output FD from tombstoned via a unix
343# domain socket.
344#
345# Allow apps to connect and write to the tombstoned java trace socket in
346# order to dump their traces. Also allow them to append traces to pipes
347# created by dumptrace. (Also see the rules below where they are given
348# additional permissions to dumpstate pipes for other aspects of bug report
349# creation).
350unix_socket_connect(appdomain, tombstoned_java_trace, tombstoned)
351allow appdomain tombstoned:fd use;
352allow appdomain dumpstate:fifo_file append;
353allow appdomain incidentd:fifo_file append;
354
355# Allow apps to send dump information to dumpstate
356allow appdomain dumpstate:fd use;
357allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown };
358allow appdomain dumpstate:fifo_file { write getattr };
359allow appdomain shell_data_file:file { write getattr };
360
361# Allow apps to send dump information to incidentd
362allow appdomain incidentd:fd use;
363allow appdomain incidentd:fifo_file { write getattr };
364
365# Allow apps to send information to statsd socket.
366unix_socket_send(appdomain, statsdw, statsd)
367
368# Write profiles /data/misc/profiles
369allow appdomain user_profile_root_file:dir search;
Jiakai Zhang3c614b22022-09-28 16:29:28 +0000370allow appdomain user_profile_data_file:dir w_dir_perms;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000371allow appdomain user_profile_data_file:file create_file_perms;
372
Ryan Savitski941ba722023-02-02 14:24:45 +0000373# Allow writing performance tracing data into the perfetto traced daemon.
374# Needed for java heap graph ART plugin (perfetto_hprof).
375# The perfetto profiling daemon will check for the specific application's
376# opt-in/opt-out.
377perfetto_producer(appdomain)
378
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000379# Send heap dumps to system_server via an already open file descriptor
380# % adb shell am set-watch-heap com.android.systemui 1048576
381# % adb shell dumpsys procstats --start-testing
382# debuggable builds only.
383userdebug_or_eng(`
384 allow appdomain heapdump_data_file:file append;
385')
386
387# Grant GPU access to all processes started by Zygote.
388# They need that to render the standard UI.
Charles Chenccf80142023-01-20 03:34:19 +0000389allow { appdomain -isolated_app_all } gpu_device:chr_file rw_file_perms;
390allow { appdomain -isolated_app_all } gpu_device:dir r_dir_perms;
391allow { appdomain -isolated_app_all } sysfs_gpu:file r_file_perms;
Jason Macnak365024e2022-02-24 18:32:16 +0000392
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000393
394# Use the Binder.
395binder_use(appdomain)
396# Perform binder IPC to binder services.
397binder_call(appdomain, binderservicedomain)
398# Perform binder IPC to other apps.
399binder_call(appdomain, appdomain)
400# Perform binder IPC to ephemeral apps.
401binder_call(appdomain, ephemeral_app)
402# Perform binder IPC to gpuservice.
Charles Chenccf80142023-01-20 03:34:19 +0000403binder_call({ appdomain -isolated_app_all }, gpuservice)
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000404
405# Talk with graphics composer fences
406allow appdomain hal_graphics_composer:fd use;
407
408# Already connected, unnamed sockets being passed over some other IPC
409# hence no sock_file or connectto permission. This appears to be how
410# Chrome works, may need to be updated as more apps using isolated services
411# are examined.
Joseph Murphy29e57302024-03-20 18:23:46 +0000412allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000413
414# Backup ability for every app. BMS opens and passes the fd
415# to any app that has backup ability. Hence, no open permissions here.
416allow appdomain backup_data_file:file { read write getattr map };
417allow appdomain cache_backup_file:file { read write getattr map };
418allow appdomain cache_backup_file:dir getattr;
419# Backup ability using 'adb backup'
420allow appdomain system_data_file:lnk_file r_file_perms;
421allow appdomain system_data_file:file { getattr read map };
422
423# Allow read/stat of /data/media files passed by Binder or local socket IPC.
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000424allow { appdomain -isolated_app_all -sdk_sandbox_all } media_rw_data_file:file { read getattr };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000425
426# Read and write /data/data/com.android.providers.telephony files passed over Binder.
Charles Chenccf80142023-01-20 03:34:19 +0000427allow { appdomain -isolated_app_all } radio_data_file:file { read write getattr };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000428
429# For art.
430allow appdomain dalvikcache_data_file:file execute;
431allow appdomain dalvikcache_data_file:lnk_file r_file_perms;
432
433# Allow any app to read shared RELRO files.
434allow appdomain shared_relro_file:dir search;
435allow appdomain shared_relro_file:file r_file_perms;
436
437# Allow apps to read/execute installed binaries
Jeff Vander Stoep3fbb1772023-03-27 10:03:46 +0200438allow appdomain apk_data_file:dir { open getattr read search ioctl lock };
439allow appdomain apk_data_file:file { getattr open read ioctl lock map x_file_perms };
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000440
441# /data/resource-cache
442allow appdomain resourcecache_data_file:file r_file_perms;
443allow appdomain resourcecache_data_file:dir r_dir_perms;
444
445# logd access
446read_logd(appdomain)
447
448allow appdomain zygote:unix_dgram_socket write;
449
450allow appdomain console_device:chr_file { read write };
451
452# only allow unprivileged socket ioctl commands
453allowxperm { appdomain -bluetooth } self:{ rawip_socket tcp_socket udp_socket }
454 ioctl { unpriv_sock_ioctls unpriv_tty_ioctls };
455
Charles Chenccf80142023-01-20 03:34:19 +0000456allow { appdomain -isolated_app_all } ion_device:chr_file r_file_perms;
457allow { appdomain -isolated_app_all } dmabuf_system_heap_device:chr_file r_file_perms;
458allow { appdomain -isolated_app_all } dmabuf_system_secure_heap_device:chr_file r_file_perms;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000459
460# Allow AAudio apps to use shared memory file descriptors from the HAL
Charles Chenccf80142023-01-20 03:34:19 +0000461allow { appdomain -isolated_app_all } hal_audio:fd use;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000462
463# Allow app to access shared memory created by camera HAL1
Charles Chenccf80142023-01-20 03:34:19 +0000464allow { appdomain -isolated_app_all } hal_camera:fd use;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000465
466# Allow apps to access shared memory file descriptor from the tuner HAL
Charles Chenccf80142023-01-20 03:34:19 +0000467allow {appdomain -isolated_app_all} hal_tv_tuner_server:fd use;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000468
Matt Buckley52c9b3b2024-02-26 16:38:17 -0800469# Allow app to access shared memory created by PowerHAL for FMQ use
470allow { appdomain -isolated_app_all } hal_power_server:fd use;
471
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000472# RenderScript always-passthrough HAL
Charles Chenccf80142023-01-20 03:34:19 +0000473allow { appdomain -isolated_app_all } hal_renderscript_hwservice:hwservice_manager find;
Nikita Ioffeeb833f02022-01-07 03:12:53 +0000474allow appdomain same_process_hal_file:file { execute read open getattr map };
475
476# TODO: switch to meminfo service
477allow appdomain proc_meminfo:file r_file_perms;
478
479# For app fuse.
480allow appdomain app_fuse_file:file { getattr read append write map };
481
482###
483### CTS-specific rules
484###
485
486# For cts/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java.
487# testRunAsHasCorrectCapabilities
488allow appdomain runas_exec:file getattr;
489# Others are either allowed elsewhere or not desired.
490
491# Connect to adbd and use a socket transferred from it.
492# This is used for e.g. adb backup/restore.
493allow appdomain adbd:unix_stream_socket connectto;
494allow appdomain adbd:fd use;
495allow appdomain adbd:unix_stream_socket { getattr getopt ioctl read write shutdown };
496
497allow appdomain cache_file:dir getattr;
498
499# Allow apps to run with asanwrapper.
500with_asan(`allow appdomain asanwrapper_exec:file rx_file_perms;')
501
502# Read access to FDs from the DropboxManagerService.
503allow appdomain dropbox_data_file:file { getattr read };
504
505# Read tmpfs types from these processes.
506allow appdomain audioserver_tmpfs:file { getattr map read write };
507allow appdomain system_server_tmpfs:file { getattr map read write };
508allow appdomain zygote_tmpfs:file { map read };
509
Inseob Kim75806ef2024-03-27 17:18:41 +0900510###
511### Neverallow rules
512###
513### These are things that Android apps should NEVER be able to do
514###
515
516# Superuser capabilities.
517# bluetooth requires net_admin and wake_alarm. network stack app requires net_admin.
518neverallow { appdomain -bluetooth -network_stack } self:capability_class_set *;
519
520# Block device access.
521neverallow appdomain dev_type:blk_file { read write };
522
523# Note: Try expanding list of app domains in the future.
524neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write };
525
526neverallow { appdomain -nfc } nfc_device:chr_file
527 { read write };
528neverallow { appdomain -bluetooth } hci_attach_dev:chr_file
529 { read write };
530neverallow appdomain tee_device:chr_file { read write };
531
532# Privileged netlink socket interfaces.
533neverallow { appdomain -network_stack }
534 domain:{
535 netlink_tcpdiag_socket
536 netlink_nflog_socket
537 netlink_xfrm_socket
538 netlink_audit_socket
539 netlink_dnrt_socket
540 } *;
541
542# These messages are broadcast messages from the kernel to userspace.
543# Do not allow the writing of netlink messages, which has been a source
544# of rooting vulns in the past.
545neverallow { appdomain -network_stack }
546 domain:netlink_kobject_uevent_socket { write append };
547
548# Sockets under /dev/socket that are not specifically typed.
549neverallow appdomain socket_device:sock_file write;
550
551# Unix domain sockets.
552neverallow appdomain adbd_socket:sock_file write;
553neverallow { appdomain -radio } rild_socket:sock_file write;
554
555# ptrace access to non-app domains.
556neverallow appdomain { domain -appdomain }:process ptrace;
557
558# The Android security model guarantees the confidentiality and integrity
559# of application data and execution state. Ptrace bypasses those
560# confidentiality guarantees. Disallow ptrace access from system components
561# to apps. Crash_dump is excluded, as it needs ptrace access to
562# produce stack traces. llkd is excluded, as it needs ptrace access to
563# inspect stack traces for live lock conditions.
564
565neverallow {
566 domain
567 -appdomain
568 -crash_dump
569 userdebug_or_eng(`-llkd')
570} appdomain:process ptrace;
571
572# Read or write access to /proc/pid entries for any non-app domain.
573# A different form of hidepid=2 like protections
574neverallow appdomain { domain -appdomain }:file no_w_file_perms;
575neverallow { appdomain -shell } { domain -appdomain }:file no_rw_file_perms;
576
577# signal access to non-app domains.
578# sigchld allowed for parent death notification.
579# signull allowed for kill(pid, 0) existence test.
580# All others prohibited.
581# -perfetto is to allow shell (which is an appdomain) to kill perfetto
582# (see private/shell.te).
583neverallow appdomain { domain -appdomain -perfetto }:process
584 { sigkill sigstop signal };
585
586# Write to rootfs.
587neverallow appdomain rootfs:dir_file_class_set
588 { create write setattr relabelfrom relabelto append unlink link rename };
589
590# Write to /system.
591neverallow appdomain system_file_type:dir_file_class_set
592 { create write setattr relabelfrom relabelto append unlink link rename };
593
594# Write to entrypoint executables.
595neverallow appdomain exec_type:file
596 { create write setattr relabelfrom relabelto append unlink link rename };
597
598# Write to system-owned parts of /data.
599# This is the default type for anything under /data not otherwise
600# specified in file_contexts. Define a different type for portions
601# that should be writable by apps.
602neverallow appdomain system_data_file:dir_file_class_set
603 { create write setattr relabelfrom relabelto append unlink link rename };
604
605# Write to various other parts of /data.
606neverallow appdomain drm_data_file:dir_file_class_set
607 { create write setattr relabelfrom relabelto append unlink link rename };
608neverallow { appdomain -platform_app }
609 apk_data_file:dir_file_class_set
610 { create write setattr relabelfrom relabelto append unlink link rename };
611neverallow { appdomain -platform_app }
612 apk_private_data_file:dir_file_class_set
613 { create write setattr relabelfrom relabelto append unlink link rename };
614neverallow { appdomain -platform_app }
615 apk_private_tmp_file:dir_file_class_set
616 { create write setattr relabelfrom relabelto append unlink link rename };
617neverallow { appdomain -shell }
618 shell_data_file:dir_file_class_set
619 { create setattr relabelfrom relabelto append unlink link rename };
620neverallow { appdomain -bluetooth }
621 bluetooth_data_file:dir_file_class_set
622 { create write setattr relabelfrom relabelto append unlink link rename };
623neverallow { domain -credstore -init } credstore_data_file:dir_file_class_set *;
624neverallow appdomain
625 keystore_data_file:dir_file_class_set
626 { create write setattr relabelfrom relabelto append unlink link rename };
627neverallow appdomain
628 systemkeys_data_file:dir_file_class_set
629 { create write setattr relabelfrom relabelto append unlink link rename };
630neverallow appdomain
631 wifi_data_file:dir_file_class_set
632 { create write setattr relabelfrom relabelto append unlink link rename };
633neverallow appdomain
634 dhcp_data_file:dir_file_class_set
635 { create write setattr relabelfrom relabelto append unlink link rename };
636
637# access tmp apk files
638neverallow { appdomain -platform_app }
639 apk_tmp_file:dir_file_class_set
640 { create write setattr relabelfrom relabelto append unlink link rename };
641
642neverallow { appdomain -untrusted_app_all -platform_app -priv_app -isolated_app_all }
643 { apk_tmp_file apk_private_tmp_file }:dir_file_class_set *;
644
645neverallow { untrusted_app_all isolated_app_all } { apk_tmp_file apk_private_tmp_file }:{ devfile_class_set dir fifo_file lnk_file sock_file } *;
William Luh2eff31b2024-06-28 20:44:06 +0000646neverallow { untrusted_app_all isolated_app_all } { apk_tmp_file apk_private_tmp_file }:file ~{ getattr read map };
Inseob Kim75806ef2024-03-27 17:18:41 +0900647
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
Orion Hodson8f75f762020-10-16 15:29:55 +0100727# 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
Charles Chenccf80142023-01-20 03:34:19 +0000732 isolated_app_all
Orion Hodson8f75f762020-10-16 15:29:55 +0100733 nfc
734 radio
735 shared_relro
Mugdha Lakhani2ae45c52023-04-28 09:22:15 +0000736 sdk_sandbox_all
Orion Hodson8f75f762020-10-16 15:29:55 +0100737 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
Avichal Rakeshe0929242023-01-23 23:49:50 -0800744}: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 };
Jeff Vander Stoepf9a774f2023-03-27 12:30:23 +0200761
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 };
Inseob Kim75806ef2024-03-27 17:18:41 +0900781
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 };
Ellen Arteca27b515e2024-04-30 20:26:55 +0000805is_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')