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