RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 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. |
| 5 | r_dir_file({ |
| 6 | appdomain |
| 7 | -ephemeral_app |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 8 | -isolated_app_all |
Maciej Żenczykowski | 81a860e | 2025-01-21 20:32:31 -0800 | [diff] [blame] | 9 | -network_stack |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 10 | -platform_app |
| 11 | -priv_app |
| 12 | -shell |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 13 | -sdk_sandbox_all |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 14 | -system_app |
| 15 | -untrusted_app_all |
| 16 | }, proc_net_type) |
| 17 | # audit access for all these non-core app domains. |
| 18 | userdebug_or_eng(` |
| 19 | auditallow { |
| 20 | appdomain |
| 21 | -ephemeral_app |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 22 | -isolated_app_all |
Maciej Żenczykowski | 81a860e | 2025-01-21 20:32:31 -0800 | [diff] [blame] | 23 | -network_stack |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 24 | -platform_app |
| 25 | -priv_app |
| 26 | -shell |
| 27 | -su |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 28 | -sdk_sandbox_all |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 29 | -system_app |
| 30 | -untrusted_app_all |
| 31 | } proc_net_type:{ dir file lnk_file } { getattr open read }; |
| 32 | ') |
| 33 | |
William Hester | 5f486c7 | 2019-01-15 13:39:30 -0800 | [diff] [blame] | 34 | # Allow apps to read the Test Harness Mode property. This property is used in |
| 35 | # the implementation of ActivityManager.isDeviceInTestHarnessMode() |
| 36 | get_prop(appdomain, test_harness_prop) |
| 37 | |
Inseob Kim | dbcc459 | 2020-05-21 20:12:55 +0900 | [diff] [blame] | 38 | get_prop(appdomain, boot_status_prop) |
Jiakai Zhang | 22fb5c7 | 2023-03-30 15:50:05 +0100 | [diff] [blame] | 39 | get_prop(appdomain, dalvik_config_prop_type) |
Inseob Kim | dddf6f5 | 2020-07-06 22:24:11 +0900 | [diff] [blame] | 40 | get_prop(appdomain, media_config_prop) |
Inseob Kim | 5eacf72 | 2020-07-01 01:27:49 +0900 | [diff] [blame] | 41 | get_prop(appdomain, packagemanager_config_prop) |
Inseob Kim | 4ae7ec1 | 2020-08-03 14:29:47 +0900 | [diff] [blame] | 42 | get_prop(appdomain, radio_control_prop) |
Inseob Kim | dbcc459 | 2020-05-21 20:12:55 +0900 | [diff] [blame] | 43 | get_prop(appdomain, surfaceflinger_color_prop) |
| 44 | get_prop(appdomain, systemsound_config_prop) |
Inseob Kim | 641cffe | 2020-06-05 10:40:16 +0900 | [diff] [blame] | 45 | get_prop(appdomain, telephony_config_prop) |
Inseob Kim | dbcc459 | 2020-05-21 20:12:55 +0900 | [diff] [blame] | 46 | get_prop(appdomain, userspace_reboot_config_prop) |
| 47 | get_prop(appdomain, vold_config_prop) |
Hongguang Chen | 67c3688 | 2020-07-27 15:15:53 -0700 | [diff] [blame] | 48 | get_prop(appdomain, adbd_config_prop) |
Thierry Strudel | f4e3b06 | 2021-12-22 19:13:25 -0800 | [diff] [blame] | 49 | get_prop(appdomain, dck_prop) |
Evan Rosky | 5cfdf2b | 2022-03-02 22:13:58 +0000 | [diff] [blame] | 50 | get_prop(appdomain, persist_wm_debug_prop) |
Alexander Roederer | 829d974 | 2023-03-23 02:19:22 +0000 | [diff] [blame] | 51 | get_prop(appdomain, persist_sysui_builder_extras_prop) |
Alexander Roederer | 584a862 | 2023-05-31 21:25:50 +0000 | [diff] [blame] | 52 | get_prop(appdomain, persist_sysui_ranking_update_prop) |
Inseob Kim | dbcc459 | 2020-05-21 20:12:55 +0900 | [diff] [blame] | 53 | |
Ioannis Ilkos | 8d168e2 | 2023-02-10 17:52:19 +0000 | [diff] [blame] | 54 | # Allow the heap dump ART plugin to the count of sessions waiting for OOME |
| 55 | get_prop(appdomain, traced_oome_heap_session_count_prop) |
| 56 | |
Sandro | 080c579 | 2022-11-03 14:44:35 +0000 | [diff] [blame] | 57 | # Allow to read ro.vendor.camera.extensions.enabled |
| 58 | get_prop(appdomain, camera2_extensions_prop) |
| 59 | |
| 60 | # Allow to ro.camerax.extensions.enabled |
| 61 | get_prop(appdomain, camerax_extensions_prop) |
| 62 | |
Jeff Vander Stoep | 607bc67 | 2019-12-16 10:59:03 +0100 | [diff] [blame] | 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. |
| 70 | dontaudit 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. |
| 77 | dontaudit appdomain system_data_file:dir write; |
Jeff Vander Stoep | 67896ee | 2020-04-02 13:36:17 +0200 | [diff] [blame] | 78 | # Apps should not be reading vendor-defined properties. |
| 79 | dontaudit appdomain vendor_default_prop:file read; |
Jeff Vander Stoep | 607bc67 | 2019-12-16 10:59:03 +0100 | [diff] [blame] | 80 | |
Zim | b61bcc8 | 2021-04-08 12:20:26 +0100 | [diff] [blame] | 81 | # Access to /mnt/media_rw/<vol> (limited by DAC to apps with external_storage gid) |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 82 | allow { appdomain -sdk_sandbox_all } mnt_media_rw_file:dir search; |
Zim | b61bcc8 | 2021-04-08 12:20:26 +0100 | [diff] [blame] | 83 | |
Jeff Vander Stoep | 7295721 | 2022-07-01 10:08:34 +0200 | [diff] [blame] | 84 | # allow apps to use UDP sockets provided by the system server but not |
| 85 | # modify them other than to connect |
| 86 | allow appdomain system_server:udp_socket { |
| 87 | connect getattr read recvfrom sendto write getopt setopt }; |
| 88 | |
Inseob Kim | c80b024 | 2020-07-16 22:25:47 +0900 | [diff] [blame] | 89 | # Allow to read sendbug.preferred.domain |
| 90 | get_prop(appdomain, sendbug_config_prop) |
| 91 | |
Peiyong Lin | 37dea07 | 2020-06-03 12:20:41 -0700 | [diff] [blame] | 92 | # Allow to read graphics related properties. |
| 93 | get_prop(appdomain, graphics_config_prop) |
Inseob Kim | c97a97c | 2020-07-20 20:26:07 +0900 | [diff] [blame] | 94 | |
| 95 | # Allow to read persist.config.calibration_fac |
| 96 | get_prop(appdomain, camera_calibration_prop) |
Inseob Kim | 0cef0fe | 2020-11-17 13:54:52 +0900 | [diff] [blame] | 97 | |
| 98 | # Allow to read db.log.detailed, db.log.slow_query_threshold* |
| 99 | get_prop(appdomain, sqlite_log_prop) |
Orion Hodson | 8f75f76 | 2020-10-16 15:29:55 +0100 | [diff] [blame] | 100 | |
Felipe Leme | b85242c | 2022-04-21 17:49:05 -0700 | [diff] [blame] | 101 | # Allow to read system_user_mode_emulation_prop, which is used by UserManager.java |
| 102 | userdebug_or_eng(`get_prop(appdomain, system_user_mode_emulation_prop)') |
| 103 | |
Seigo Nonaka | 9c3707f | 2021-01-21 13:08:31 -0800 | [diff] [blame] | 104 | # Allow font file read by apps. |
| 105 | allow appdomain font_data_file:file r_file_perms; |
| 106 | allow appdomain font_data_file:dir r_dir_perms; |
| 107 | |
Martijn Coenen | 4825e86 | 2021-03-29 13:51:35 +0200 | [diff] [blame] | 108 | # Enter /data/misc/apexdata/ |
| 109 | allow appdomain apex_module_data_file:dir search; |
Orion Hodson | 13ee653 | 2021-04-27 15:51:33 +0100 | [diff] [blame] | 110 | # Read /data/misc/apexdata/com.android.art, execute signed AOT artifacts. |
Martijn Coenen | 4825e86 | 2021-03-29 13:51:35 +0200 | [diff] [blame] | 111 | allow appdomain apex_art_data_file:dir r_dir_perms; |
Orion Hodson | 13ee653 | 2021-04-27 15:51:33 +0100 | [diff] [blame] | 112 | allow appdomain apex_art_data_file:file rx_file_perms; |
Orion Hodson | 8f75f76 | 2020-10-16 15:29:55 +0100 | [diff] [blame] | 113 | |
Josh Gao | ce1c4a5 | 2021-02-03 18:35:06 -0800 | [diff] [blame] | 114 | # Allow access to tombstones if an fd to one is given to you. |
Florian Mayer | 6c689e8 | 2024-02-14 10:54:58 -0800 | [diff] [blame] | 115 | # An app cannot open the tombstone itself because it lacks `open`. |
Josh Gao | ce1c4a5 | 2021-02-03 18:35:06 -0800 | [diff] [blame] | 116 | allow appdomain tombstone_data_file:file { getattr read }; |
Josh Gao | ce1c4a5 | 2021-02-03 18:35:06 -0800 | [diff] [blame] | 117 | |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 118 | # Execute the shell or other system executables. |
Jeffrey Vander Stoep | b6c262c | 2023-12-07 13:56:15 +0000 | [diff] [blame] | 119 | allow { appdomain -ephemeral_app -sdk_sandbox_all } shell_exec:file rx_file_perms; |
| 120 | allow { appdomain -ephemeral_app -sdk_sandbox_all } toolbox_exec:file rx_file_perms; |
| 121 | not_full_treble(`allow { appdomain -ephemeral_app -sdk_sandbox_all } vendor_file:file x_file_perms;') |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 122 | |
| 123 | # Allow apps access to /vendor/app except for privileged |
| 124 | # apps which cannot be in /vendor. |
Jeffrey Vander Stoep | b6c262c | 2023-12-07 13:56:15 +0000 | [diff] [blame] | 125 | r_dir_file({ appdomain -ephemeral_app -sdk_sandbox_all }, vendor_app_file) |
| 126 | allow { appdomain -ephemeral_app -sdk_sandbox_all } vendor_app_file:file execute; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 127 | |
Seungjae Yoo | 01c4f57 | 2024-02-13 13:47:36 +0900 | [diff] [blame] | 128 | # Allow apps to read microdroid related files in vendor partition for CTS purpose. |
| 129 | r_dir_file({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, vendor_microdroid_file) |
| 130 | |
Nikita Ioffe | e2da633 | 2022-02-21 17:55:59 +0000 | [diff] [blame] | 131 | # Perform binder IPC to sdk sandbox. |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 132 | binder_call(appdomain, sdk_sandbox_all) |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 133 | |
Jan Sebechlebsky | 6e1795c | 2023-12-06 09:31:17 +0100 | [diff] [blame] | 134 | # Allow apps to communicate via binder with virtual camera service. |
| 135 | binder_call(appdomain, virtual_camera) |
| 136 | |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 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 |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 139 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } storage_file:dir r_dir_perms; |
| 140 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } storage_file:lnk_file r_file_perms; |
| 141 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } mnt_user_file:dir r_dir_perms; |
| 142 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } mnt_user_file:lnk_file r_file_perms; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 143 | |
| 144 | # Read/write visible storage |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 145 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } { sdcard_type fuse }:dir create_dir_perms; |
| 146 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } { sdcard_type fuse }:file create_file_perms; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 147 | # This should be removed if sdcardfs is modified to alter the secontext for its |
| 148 | # accesses to the underlying FS. |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 149 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } media_rw_data_file:dir create_dir_perms; |
| 150 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } media_rw_data_file:file create_file_perms; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 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. |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 157 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } usb_device:chr_file { read write getattr ioctl }; |
| 158 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } usbaccessory_device:chr_file { read write getattr }; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 159 | |
| 160 | #logd access |
Jeffrey Vander Stoep | b6c262c | 2023-12-07 13:56:15 +0000 | [diff] [blame] | 161 | control_logd({ appdomain -ephemeral_app -sdk_sandbox_all }) |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 162 | |
| 163 | # application inherit logd write socket (urge is to deprecate this long term) |
Michael Groover | 38deee7 | 2024-10-07 22:12:09 -0500 | [diff] [blame] | 164 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore:keystore2_key { delete use get_info grant rebind update }; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 165 | |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 166 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } keystore_maintenance_service:service_manager find; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 167 | |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 168 | use_keystore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }) |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 169 | |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 170 | use_credstore({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }) |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 171 | |
Shawn Willden | a15e9ce | 2024-09-17 13:12:52 -0600 | [diff] [blame] | 172 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } persistent_data_block_service:service_manager find; |
| 173 | |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 174 | # For app fuse. |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 175 | pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_client) |
| 176 | pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_manager) |
| 177 | pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, display_vsync) |
| 178 | pdx_client({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, performance_client) |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 179 | # Apps do not directly open the IPC socket for bufferhubd. |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 180 | pdx_use({ appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all }, bufferhub_client) |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 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 |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 184 | allow { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } tun_device:chr_file { read write getattr append ioctl }; |
| 185 | allowxperm { appdomain -isolated_app_all -ephemeral_app -sdk_sandbox_all } tun_device:chr_file ioctl TUNGETIFF; |
RafayKamran | eaa18ce | 2021-10-27 14:12:44 +0000 | [diff] [blame] | 186 | |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 187 | |
| 188 | # WebView and other application-specific JIT compilers |
| 189 | allow appdomain self:process execmem; |
| 190 | |
| 191 | allow appdomain { ashmem_device ashmem_libcutils_device }:chr_file execute; |
| 192 | |
| 193 | # Receive and use open file descriptors inherited from zygote. |
| 194 | allow appdomain zygote:fd use; |
| 195 | |
| 196 | # Receive and use open file descriptors inherited from app zygote. |
| 197 | allow appdomain app_zygote:fd use; |
| 198 | |
| 199 | # gdbserver for ndk-gdb reads the zygote. |
| 200 | # valgrind needs mmap exec for zygote |
| 201 | allow appdomain zygote_exec:file rx_file_perms; |
| 202 | |
| 203 | # Notify zygote of death; |
| 204 | allow appdomain zygote:process sigchld; |
| 205 | |
| 206 | # Read /data/dalvik-cache. |
| 207 | allow appdomain dalvikcache_data_file:dir { search getattr }; |
| 208 | allow appdomain dalvikcache_data_file:file r_file_perms; |
| 209 | |
| 210 | # Read the /sdcard and /mnt/sdcard symlinks |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 211 | allow { appdomain -isolated_app_all -sdk_sandbox_all } rootfs:lnk_file r_file_perms; |
| 212 | allow { appdomain -isolated_app_all -sdk_sandbox_all } tmpfs:lnk_file r_file_perms; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 213 | |
| 214 | # Search /storage/emulated tmpfs mount. |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 215 | allow { appdomain -sdk_sandbox_all } tmpfs:dir r_dir_perms; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 216 | |
| 217 | # Notify zygote of the wrapped process PID when using --invoke-with. |
| 218 | allow appdomain zygote:fifo_file write; |
| 219 | |
| 220 | userdebug_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. |
| 227 | allow appdomain shell:process sigchld; |
| 228 | allow appdomain adbd:process sigchld; |
| 229 | |
| 230 | # child shell or gdbserver pty access for runas. |
| 231 | allow appdomain devpts:chr_file { getattr read write ioctl }; |
| 232 | |
| 233 | # Use pipes and sockets provided by system_server via binder or local socket. |
| 234 | allow appdomain system_server:fd use; |
| 235 | allow appdomain system_server:fifo_file rw_file_perms; |
| 236 | allow appdomain system_server:unix_stream_socket { read write setopt getattr getopt shutdown }; |
| 237 | allow appdomain system_server:tcp_socket { read write getattr getopt shutdown }; |
| 238 | |
| 239 | # For AppFuse. |
| 240 | allow appdomain vold:fd use; |
| 241 | |
| 242 | # Communication with other apps via fifos |
| 243 | allow appdomain appdomain:fifo_file rw_file_perms; |
| 244 | |
| 245 | # Communicate with surfaceflinger. |
| 246 | allow appdomain surfaceflinger:unix_stream_socket { read write setopt getattr getopt shutdown }; |
| 247 | |
| 248 | # App sandbox file accesses. |
Ellen Arteca | 27b515e | 2024-04-30 20:26:55 +0000 | [diff] [blame] | 249 | allow { 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; |
| 254 | allow { 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 | |
| 260 | is_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 | |
| 267 | allowxperm { 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 Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 272 | |
| 273 | # Access via already open fds is ok even for mlstrustedsubject. |
Ellen Arteca | 27b515e | 2024-04-30 20:26:55 +0000 | [diff] [blame] | 274 | allow { 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 Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 280 | |
Gavin Corkery | d4d3c01 | 2023-05-10 16:13:53 +0000 | [diff] [blame] | 281 | # Access open fds from SDK sandbox |
| 282 | allow appdomain sdk_sandbox_data_file:file { getattr read }; |
| 283 | |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 284 | # Traverse into expanded storage |
| 285 | allow appdomain mnt_expand_file:dir r_dir_perms; |
| 286 | |
| 287 | # Keychain and user-trusted credentials |
| 288 | r_dir_file(appdomain, keychain_data_file) |
| 289 | allow appdomain misc_user_data_file:dir r_dir_perms; |
| 290 | allow appdomain misc_user_data_file:file r_file_perms; |
| 291 | |
| 292 | # TextClassifier |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 293 | r_dir_file({ appdomain -isolated_app_all }, textclassifier_data_file) |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 294 | |
| 295 | # Access to OEM provided data and apps |
| 296 | allow appdomain oemfs:dir r_dir_perms; |
| 297 | allow appdomain oemfs:file rx_file_perms; |
| 298 | |
| 299 | allow appdomain system_file:file x_file_perms; |
| 300 | |
| 301 | # Renderscript needs the ability to read directories on /system |
| 302 | allow appdomain system_file:dir r_dir_perms; |
| 303 | allow appdomain system_file:lnk_file { getattr open read }; |
| 304 | # Renderscript specific permissions to open /system/vendor/lib64. |
| 305 | not_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 | |
| 310 | full_treble_only(` |
| 311 | # For looking up Renderscript vendor drivers |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 312 | allow { appdomain -isolated_app_all } vendor_file:dir { open read }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 313 | ') |
| 314 | |
| 315 | # Allow apps access to /vendor/overlay |
| 316 | r_dir_file(appdomain, vendor_overlay_file) |
| 317 | |
| 318 | # Allow apps access to /vendor/framework |
| 319 | # for vendor provided libraries. |
| 320 | r_dir_file(appdomain, vendor_framework_file) |
| 321 | |
| 322 | # Allow apps read / execute access to vendor public libraries. |
| 323 | allow appdomain {vendor_public_framework_file vendor_public_lib_file}:dir r_dir_perms; |
| 324 | allow 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 Stoep | b6c262c | 2023-12-07 13:56:15 +0000 | [diff] [blame] | 327 | allow appdomain wallpaper_file:file { getattr read write map }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 328 | |
| 329 | # Read/write cached ringtones (opened by system). |
Jeffrey Vander Stoep | b6c262c | 2023-12-07 13:56:15 +0000 | [diff] [blame] | 330 | allow appdomain ringtone_file:file { getattr read write map }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 331 | |
| 332 | # Read ShortcutManager icon files (opened by system). |
Jeffrey Vander Stoep | b6c262c | 2023-12-07 13:56:15 +0000 | [diff] [blame] | 333 | allow appdomain shortcut_manager_icons:file { getattr read map }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 334 | |
| 335 | # Read icon file (opened by system). |
Jeffrey Vander Stoep | b6c262c | 2023-12-07 13:56:15 +0000 | [diff] [blame] | 336 | allow appdomain icon_file:file { getattr read map }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 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. |
| 343 | allow appdomain anr_data_file:dir search; |
| 344 | allow 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). |
| 354 | unix_socket_connect(appdomain, tombstoned_java_trace, tombstoned) |
| 355 | allow appdomain tombstoned:fd use; |
| 356 | allow appdomain dumpstate:fifo_file append; |
| 357 | allow appdomain incidentd:fifo_file append; |
| 358 | |
| 359 | # Allow apps to send dump information to dumpstate |
| 360 | allow appdomain dumpstate:fd use; |
| 361 | allow appdomain dumpstate:unix_stream_socket { read write getopt getattr shutdown }; |
| 362 | allow appdomain dumpstate:fifo_file { write getattr }; |
| 363 | allow appdomain shell_data_file:file { write getattr }; |
| 364 | |
| 365 | # Allow apps to send dump information to incidentd |
| 366 | allow appdomain incidentd:fd use; |
| 367 | allow appdomain incidentd:fifo_file { write getattr }; |
| 368 | |
| 369 | # Allow apps to send information to statsd socket. |
| 370 | unix_socket_send(appdomain, statsdw, statsd) |
| 371 | |
| 372 | # Write profiles /data/misc/profiles |
| 373 | allow appdomain user_profile_root_file:dir search; |
Jiakai Zhang | 4c3f1b6 | 2025-03-05 06:32:13 -0800 | [diff] [blame] | 374 | allow appdomain user_profile_data_file:dir rw_dir_perms; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 375 | allow appdomain user_profile_data_file:file create_file_perms; |
| 376 | |
Ryan Savitski | 941ba72 | 2023-02-02 14:24:45 +0000 | [diff] [blame] | 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. |
| 381 | perfetto_producer(appdomain) |
| 382 | |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 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. |
| 387 | userdebug_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 Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 393 | allow { appdomain -isolated_app_all } gpu_device:chr_file rw_file_perms; |
| 394 | allow { appdomain -isolated_app_all } gpu_device:dir r_dir_perms; |
| 395 | allow { appdomain -isolated_app_all } sysfs_gpu:file r_file_perms; |
Jason Macnak | 365024e | 2022-02-24 18:32:16 +0000 | [diff] [blame] | 396 | |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 397 | |
| 398 | # Use the Binder. |
| 399 | binder_use(appdomain) |
| 400 | # Perform binder IPC to binder services. |
| 401 | binder_call(appdomain, binderservicedomain) |
| 402 | # Perform binder IPC to other apps. |
| 403 | binder_call(appdomain, appdomain) |
| 404 | # Perform binder IPC to ephemeral apps. |
| 405 | binder_call(appdomain, ephemeral_app) |
| 406 | # Perform binder IPC to gpuservice. |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 407 | binder_call({ appdomain -isolated_app_all }, gpuservice) |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 408 | |
| 409 | # Talk with graphics composer fences |
| 410 | allow 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 Murphy | 29e5730 | 2024-03-20 18:23:46 +0000 | [diff] [blame] | 416 | allow appdomain appdomain:unix_stream_socket { getopt getattr read write shutdown }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 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. |
| 420 | allow appdomain backup_data_file:file { read write getattr map }; |
| 421 | allow appdomain cache_backup_file:file { read write getattr map }; |
| 422 | allow appdomain cache_backup_file:dir getattr; |
| 423 | # Backup ability using 'adb backup' |
| 424 | allow appdomain system_data_file:lnk_file r_file_perms; |
| 425 | allow 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 Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 428 | allow { appdomain -isolated_app_all -sdk_sandbox_all } media_rw_data_file:file { read getattr }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 429 | |
| 430 | # Read and write /data/data/com.android.providers.telephony files passed over Binder. |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 431 | allow { appdomain -isolated_app_all } radio_data_file:file { read write getattr }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 432 | |
| 433 | # For art. |
| 434 | allow appdomain dalvikcache_data_file:file execute; |
| 435 | allow appdomain dalvikcache_data_file:lnk_file r_file_perms; |
| 436 | |
| 437 | # Allow any app to read shared RELRO files. |
| 438 | allow appdomain shared_relro_file:dir search; |
| 439 | allow appdomain shared_relro_file:file r_file_perms; |
| 440 | |
| 441 | # Allow apps to read/execute installed binaries |
Jeff Vander Stoep | 3fbb177 | 2023-03-27 10:03:46 +0200 | [diff] [blame] | 442 | allow appdomain apk_data_file:dir { open getattr read search ioctl lock }; |
| 443 | allow appdomain apk_data_file:file { getattr open read ioctl lock map x_file_perms }; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 444 | |
| 445 | # /data/resource-cache |
| 446 | allow appdomain resourcecache_data_file:file r_file_perms; |
| 447 | allow appdomain resourcecache_data_file:dir r_dir_perms; |
| 448 | |
| 449 | # logd access |
| 450 | read_logd(appdomain) |
| 451 | |
| 452 | allow appdomain zygote:unix_dgram_socket write; |
| 453 | |
| 454 | allow appdomain console_device:chr_file { read write }; |
| 455 | |
| 456 | # only allow unprivileged socket ioctl commands |
| 457 | allowxperm { appdomain -bluetooth } self:{ rawip_socket tcp_socket udp_socket } |
| 458 | ioctl { unpriv_sock_ioctls unpriv_tty_ioctls }; |
| 459 | |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 460 | allow { appdomain -isolated_app_all } ion_device:chr_file r_file_perms; |
| 461 | allow { appdomain -isolated_app_all } dmabuf_system_heap_device:chr_file r_file_perms; |
| 462 | allow { appdomain -isolated_app_all } dmabuf_system_secure_heap_device:chr_file r_file_perms; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 463 | |
| 464 | # Allow AAudio apps to use shared memory file descriptors from the HAL |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 465 | allow { appdomain -isolated_app_all } hal_audio:fd use; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 466 | |
| 467 | # Allow app to access shared memory created by camera HAL1 |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 468 | allow { appdomain -isolated_app_all } hal_camera:fd use; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 469 | |
| 470 | # Allow apps to access shared memory file descriptor from the tuner HAL |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 471 | allow {appdomain -isolated_app_all} hal_tv_tuner_server:fd use; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 472 | |
Matt Buckley | 52c9b3b | 2024-02-26 16:38:17 -0800 | [diff] [blame] | 473 | # Allow app to access shared memory created by PowerHAL for FMQ use |
| 474 | allow { appdomain -isolated_app_all } hal_power_server:fd use; |
| 475 | |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 476 | # RenderScript always-passthrough HAL |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 477 | allow { appdomain -isolated_app_all } hal_renderscript_hwservice:hwservice_manager find; |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 478 | allow appdomain same_process_hal_file:file { execute read open getattr map }; |
| 479 | |
| 480 | # TODO: switch to meminfo service |
| 481 | allow appdomain proc_meminfo:file r_file_perms; |
| 482 | |
| 483 | # For app fuse. |
| 484 | allow 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 |
| 492 | allow appdomain runas_exec:file getattr; |
| 493 | # Others are either allowed elsewhere or not desired. |
| 494 | |
Miranda Huang | d07ee24 | 2024-08-16 22:42:40 +0000 | [diff] [blame] | 495 | get_prop(appdomain, high_barometer_quality_prop) |
| 496 | |
Nikita Ioffe | eb833f0 | 2022-01-07 03:12:53 +0000 | [diff] [blame] | 497 | # Connect to adbd and use a socket transferred from it. |
| 498 | # This is used for e.g. adb backup/restore. |
| 499 | allow appdomain adbd:unix_stream_socket connectto; |
| 500 | allow appdomain adbd:fd use; |
| 501 | allow appdomain adbd:unix_stream_socket { getattr getopt ioctl read write shutdown }; |
| 502 | |
| 503 | allow appdomain cache_file:dir getattr; |
| 504 | |
| 505 | # Allow apps to run with asanwrapper. |
| 506 | with_asan(`allow appdomain asanwrapper_exec:file rx_file_perms;') |
| 507 | |
| 508 | # Read access to FDs from the DropboxManagerService. |
| 509 | allow appdomain dropbox_data_file:file { getattr read }; |
| 510 | |
| 511 | # Read tmpfs types from these processes. |
| 512 | allow appdomain audioserver_tmpfs:file { getattr map read write }; |
| 513 | allow appdomain system_server_tmpfs:file { getattr map read write }; |
| 514 | allow appdomain zygote_tmpfs:file { map read }; |
| 515 | |
Inseob Kim | 75806ef | 2024-03-27 17:18:41 +0900 | [diff] [blame] | 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. |
| 524 | neverallow { appdomain -bluetooth -network_stack } self:capability_class_set *; |
| 525 | |
| 526 | # Block device access. |
| 527 | neverallow appdomain dev_type:blk_file { read write }; |
| 528 | |
| 529 | # Note: Try expanding list of app domains in the future. |
| 530 | neverallow { untrusted_app isolated_app shell } graphics_device:chr_file { read write }; |
| 531 | |
| 532 | neverallow { appdomain -nfc } nfc_device:chr_file |
| 533 | { read write }; |
| 534 | neverallow { appdomain -bluetooth } hci_attach_dev:chr_file |
| 535 | { read write }; |
| 536 | neverallow appdomain tee_device:chr_file { read write }; |
| 537 | |
| 538 | # Privileged netlink socket interfaces. |
| 539 | neverallow { 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. |
| 551 | neverallow { appdomain -network_stack } |
| 552 | domain:netlink_kobject_uevent_socket { write append }; |
| 553 | |
| 554 | # Sockets under /dev/socket that are not specifically typed. |
| 555 | neverallow appdomain socket_device:sock_file write; |
| 556 | |
| 557 | # Unix domain sockets. |
| 558 | neverallow appdomain adbd_socket:sock_file write; |
| 559 | neverallow { appdomain -radio } rild_socket:sock_file write; |
| 560 | |
| 561 | # ptrace access to non-app domains. |
| 562 | neverallow 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 | |
| 571 | neverallow { |
| 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 |
| 580 | neverallow appdomain { domain -appdomain }:file no_w_file_perms; |
| 581 | neverallow { 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). |
| 589 | neverallow appdomain { domain -appdomain -perfetto }:process |
| 590 | { sigkill sigstop signal }; |
| 591 | |
| 592 | # Write to rootfs. |
| 593 | neverallow appdomain rootfs:dir_file_class_set |
| 594 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 595 | |
| 596 | # Write to /system. |
| 597 | neverallow appdomain system_file_type:dir_file_class_set |
| 598 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 599 | |
| 600 | # Write to entrypoint executables. |
| 601 | neverallow 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. |
| 608 | neverallow 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 Laine | 967f718 | 2025-03-17 10:28:50 +0000 | [diff] [blame] | 612 | neverallow appdomain mediadrm_system_data_file:dir_file_class_set |
| 613 | { create write setattr relabelfrom relabelto append unlink link rename }; |
Inseob Kim | 75806ef | 2024-03-27 17:18:41 +0900 | [diff] [blame] | 614 | neverallow appdomain drm_data_file:dir_file_class_set |
| 615 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 616 | neverallow { appdomain -platform_app } |
| 617 | apk_data_file:dir_file_class_set |
| 618 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 619 | neverallow { appdomain -platform_app } |
| 620 | apk_private_data_file:dir_file_class_set |
| 621 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 622 | neverallow { appdomain -platform_app } |
| 623 | apk_private_tmp_file:dir_file_class_set |
| 624 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 625 | neverallow { appdomain -shell } |
| 626 | shell_data_file:dir_file_class_set |
| 627 | { create setattr relabelfrom relabelto append unlink link rename }; |
| 628 | neverallow { appdomain -bluetooth } |
| 629 | bluetooth_data_file:dir_file_class_set |
| 630 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 631 | neverallow { domain -credstore -init } credstore_data_file:dir_file_class_set *; |
| 632 | neverallow appdomain |
| 633 | keystore_data_file:dir_file_class_set |
| 634 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 635 | neverallow appdomain |
| 636 | systemkeys_data_file:dir_file_class_set |
| 637 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 638 | neverallow appdomain |
| 639 | wifi_data_file:dir_file_class_set |
| 640 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 641 | neverallow 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 |
| 646 | neverallow { appdomain -platform_app } |
| 647 | apk_tmp_file:dir_file_class_set |
| 648 | { create write setattr relabelfrom relabelto append unlink link rename }; |
| 649 | |
Inseob Kim | 75806ef | 2024-03-27 17:18:41 +0900 | [diff] [blame] | 650 | # Access to factory files. |
| 651 | neverallow appdomain efs_file:dir_file_class_set write; |
| 652 | neverallow { appdomain -shell } efs_file:dir_file_class_set read; |
| 653 | |
| 654 | # Write to various pseudo file systems. |
| 655 | neverallow { appdomain -bluetooth -nfc } |
| 656 | sysfs:dir_file_class_set write; |
| 657 | neverallow appdomain |
| 658 | proc:dir_file_class_set write; |
| 659 | |
| 660 | # Access to syslog(2) or /proc/kmsg. |
Marko Man | 1b2f74f | 2020-10-12 16:05:12 +0200 | [diff] [blame] | 661 | neverallow { appdomain -system_app -shell -platform_app -priv_app } |
| 662 | kernel:system { syslog_read syslog_mod syslog_console }; |
Inseob Kim | 75806ef | 2024-03-27 17:18:41 +0900 | [diff] [blame] | 663 | |
| 664 | # SELinux is not an API for apps to use |
| 665 | neverallow { appdomain -shell } *:security { compute_av check_context }; |
| 666 | neverallow { 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. |
| 670 | neverallow appdomain fs_type:filesystem ~getattr; |
| 671 | |
| 672 | # prevent creation/manipulation of globally readable symlinks |
| 673 | neverallow 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 |
| 684 | neverallow { |
| 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. |
| 691 | neverallow { |
| 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. |
| 698 | set_prop(system_app, nfc_prop) |
| 699 | |
| 700 | # allow system_app to access radio_config system properties. |
| 701 | set_prop(system_app, radio_control_prop) |
| 702 | |
| 703 | # Apps cannot access proc_uid_time_in_state |
| 704 | neverallow appdomain proc_uid_time_in_state:file *; |
| 705 | |
| 706 | # Apps cannot access proc_uid_concurrent_active_time |
| 707 | neverallow appdomain proc_uid_concurrent_active_time:file *; |
| 708 | |
| 709 | # Apps cannot access proc_uid_concurrent_policy_time |
| 710 | neverallow appdomain proc_uid_concurrent_policy_time:file *; |
| 711 | |
| 712 | # Apps cannot access proc_uid_cpupower |
| 713 | neverallow 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. |
| 718 | neverallow { 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. |
| 725 | neverallow appdomain system_bootstrap_lib_file:file |
| 726 | { open read write append execute execute_no_trans map }; |
| 727 | neverallow appdomain system_bootstrap_lib_file:dir |
| 728 | { open read getattr search }; |
| 729 | |
Orion Hodson | 8f75f76 | 2020-10-16 15:29:55 +0100 | [diff] [blame] | 730 | # 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. |
| 733 | neverallow { |
| 734 | bluetooth |
Charles Chen | ccf8014 | 2023-01-20 03:34:19 +0000 | [diff] [blame] | 735 | isolated_app_all |
Orion Hodson | 8f75f76 | 2020-10-16 15:29:55 +0100 | [diff] [blame] | 736 | nfc |
| 737 | radio |
| 738 | shared_relro |
Mugdha Lakhani | 2ae45c5 | 2023-04-28 09:22:15 +0000 | [diff] [blame] | 739 | sdk_sandbox_all |
Orion Hodson | 8f75f76 | 2020-10-16 15:29:55 +0100 | [diff] [blame] | 740 | 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 Rakesh | e092924 | 2023-01-23 23:49:50 -0800 | [diff] [blame] | 747 | }:file no_x_file_perms; |
| 748 | |
| 749 | # Don't allow apps access to any of the following character devices. |
| 750 | neverallow 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 |
| 760 | neverallow { |
| 761 | appdomain |
| 762 | -device_as_webcam |
| 763 | } video_device:chr_file { read write }; |
Jeff Vander Stoep | f9a774f | 2023-03-27 12:30:23 +0200 | [diff] [blame] | 764 | |
| 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. |
| 768 | neverallow { |
| 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 }; |
| 776 | neverallow { |
| 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 Kim | 75806ef | 2024-03-27 17:18:41 +0900 | [diff] [blame] | 784 | |
| 785 | neverallow 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. |
| 795 | neverallow { appdomain -shell userdebug_or_eng(`-su') } |
| 796 | { domain -appdomain -crash_dump -rs -virtualizationmanager }:process { transition }; |
| 797 | neverallow { appdomain -shell userdebug_or_eng(`-su') } |
| 798 | { domain -appdomain }:process { dyntransition }; |
| 799 | |
| 800 | # Don't allow regular apps access to storage configuration properties. |
| 801 | neverallow { appdomain -mediaprovider_app } storage_config_prop:file no_rw_file_perms; |
| 802 | |
| 803 | # Don't allow apps reading /system/etc/font_fallback.xml |
| 804 | dontaudit appdomain system_font_fallback_file:file no_rw_file_perms; |
| 805 | neverallow appdomain system_font_fallback_file:file no_rw_file_perms; |
| 806 | |
| 807 | neverallow { appdomain -shell } tombstone_data_file:file ~{ getattr read }; |
Ellen Arteca | 27b515e | 2024-04-30 20:26:55 +0000 | [diff] [blame] | 808 | is_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 | ') |