Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 1 | ### |
| 2 | ### A domain for further sandboxing privileged apps. |
| 3 | ### |
| 4 | |
Alex Klyubin | f5446eb | 2017-03-23 14:27:32 -0700 | [diff] [blame] | 5 | typeattribute priv_app coredomain; |
dcashman | 3e8dbf0 | 2016-12-08 11:23:34 -0800 | [diff] [blame] | 6 | app_domain(priv_app) |
dcashman | 2e00e63 | 2016-10-12 14:58:09 -0700 | [diff] [blame] | 7 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 8 | # Access the network. |
| 9 | net_domain(priv_app) |
| 10 | # Access bluetooth. |
| 11 | bluetooth_domain(priv_app) |
| 12 | |
dcashman | 2e00e63 | 2016-10-12 14:58:09 -0700 | [diff] [blame] | 13 | # Allow the allocation and use of ptys |
| 14 | # Used by: https://play.privileged.com/store/apps/details?id=jackpal.androidterm |
| 15 | create_pty(priv_app) |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 16 | |
| 17 | # webview crash handling depends on self ptrace (b/27697529, b/20150694, b/19277529#comment7) |
| 18 | allow priv_app self:process ptrace; |
| 19 | |
| 20 | # Some apps ship with shared libraries that they write out |
| 21 | # to their sandbox directory and then dlopen(). |
Nick Kralevich | 23c9d91 | 2018-08-02 15:54:23 -0700 | [diff] [blame] | 22 | allow priv_app { app_data_file privapp_data_file }:file execute; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 23 | |
yro | 31b11d8 | 2018-01-09 11:27:36 -0800 | [diff] [blame] | 24 | allow priv_app app_api_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 25 | allow priv_app audioserver_service:service_manager find; |
| 26 | allow priv_app cameraserver_service:service_manager find; |
| 27 | allow priv_app drmserver_service:service_manager find; |
| 28 | allow priv_app mediacodec_service:service_manager find; |
| 29 | allow priv_app mediadrmserver_service:service_manager find; |
| 30 | allow priv_app mediaextractor_service:service_manager find; |
yro | 31b11d8 | 2018-01-09 11:27:36 -0800 | [diff] [blame] | 31 | allow priv_app mediametrics_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 32 | allow priv_app mediaserver_service:service_manager find; |
Ricky Wai | c635297 | 2017-11-13 17:52:05 +0000 | [diff] [blame] | 33 | allow priv_app network_watchlist_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 34 | allow priv_app nfc_service:service_manager find; |
Andrew Scull | 3717424 | 2017-02-17 13:51:32 +0000 | [diff] [blame] | 35 | allow priv_app oem_lock_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 36 | allow priv_app persistent_data_block_service:service_manager find; |
yro | 31b11d8 | 2018-01-09 11:27:36 -0800 | [diff] [blame] | 37 | allow priv_app radio_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 38 | allow priv_app recovery_service:service_manager find; |
yro | 31b11d8 | 2018-01-09 11:27:36 -0800 | [diff] [blame] | 39 | allow priv_app stats_service:service_manager find; |
| 40 | allow priv_app system_api_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 41 | |
| 42 | # Write to /cache. |
| 43 | allow priv_app { cache_file cache_recovery_file }:dir create_dir_perms; |
| 44 | allow priv_app { cache_file cache_recovery_file }:file create_file_perms; |
Nick Kralevich | 21cb045 | 2017-01-23 22:19:06 -0800 | [diff] [blame] | 45 | # /cache is a symlink to /data/cache on some devices. Allow reading the link. |
| 46 | allow priv_app cache_file:lnk_file r_file_perms; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 47 | |
| 48 | # Write to /data/ota_package for OTA packages. |
| 49 | allow priv_app ota_package_file:dir rw_dir_perms; |
| 50 | allow priv_app ota_package_file:file create_file_perms; |
| 51 | |
| 52 | # Access to /data/media. |
| 53 | allow priv_app media_rw_data_file:dir create_dir_perms; |
| 54 | allow priv_app media_rw_data_file:file create_file_perms; |
| 55 | |
| 56 | # Used by Finsky / Android "Verify Apps" functionality when |
| 57 | # running "adb install foo.apk". |
| 58 | allow priv_app shell_data_file:file r_file_perms; |
| 59 | allow priv_app shell_data_file:dir r_dir_perms; |
| 60 | |
Max Bires | 715e2ae | 2018-03-13 09:56:27 -0700 | [diff] [blame] | 61 | # Allow traceur to pass file descriptors through a content provider to betterbug |
| 62 | allow priv_app trace_data_file:file { getattr read }; |
| 63 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 64 | # Allow verifier to access staged apks. |
| 65 | allow priv_app { apk_tmp_file apk_private_tmp_file }:dir r_dir_perms; |
| 66 | allow priv_app { apk_tmp_file apk_private_tmp_file }:file r_file_perms; |
| 67 | |
| 68 | # b/18504118: Allow reads from /data/anr/traces.txt |
| 69 | allow priv_app anr_data_file:file r_file_perms; |
| 70 | |
| 71 | # Allow GMS core to access perfprofd output, which is stored |
| 72 | # in /data/misc/perfprofd/. GMS core will need to list all |
| 73 | # data stored in that directory to process them one by one. |
| 74 | userdebug_or_eng(` |
| 75 | allow priv_app perfprofd_data_file:file r_file_perms; |
| 76 | allow priv_app perfprofd_data_file:dir r_dir_perms; |
| 77 | ') |
| 78 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 79 | # For AppFuse. |
| 80 | allow priv_app vold:fd use; |
| 81 | allow priv_app fuse_device:chr_file { read write }; |
| 82 | |
Tri Vo | f92cfb9 | 2017-12-08 15:37:01 -0800 | [diff] [blame] | 83 | # /proc access |
| 84 | allow priv_app { |
| 85 | proc_vmstat |
| 86 | }:file r_file_perms; |
| 87 | |
Jeff Vander Stoep | 7a4af30 | 2018-04-10 12:47:48 -0700 | [diff] [blame] | 88 | # /proc/net access. |
| 89 | # TODO(b/9496886) Audit access for removal. |
| 90 | r_dir_file(priv_app, proc_net_type) |
| 91 | userdebug_or_eng(` |
| 92 | auditallow priv_app proc_net_type:{ dir file lnk_file } { getattr open read }; |
| 93 | ') |
Jeff Vander Stoep | 7a4af30 | 2018-04-10 12:47:48 -0700 | [diff] [blame] | 94 | |
Tri Vo | f92cfb9 | 2017-12-08 15:37:01 -0800 | [diff] [blame] | 95 | allow priv_app sysfs_type:dir search; |
| 96 | # Read access to /sys/class/net/wlan*/address |
| 97 | r_dir_file(priv_app, sysfs_net) |
| 98 | # Read access to /sys/block/zram*/mm_stat |
| 99 | r_dir_file(priv_app, sysfs_zram) |
| 100 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 101 | r_dir_file(priv_app, rootfs) |
| 102 | |
Sandeep Patil | 0465442 | 2017-04-19 11:35:15 -0700 | [diff] [blame] | 103 | # Allow GMS core to open kernel config for OTA matching through libvintf |
| 104 | allow priv_app config_gz:file { open read getattr }; |
| 105 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 106 | # access the mac address |
| 107 | allowxperm priv_app self:udp_socket ioctl SIOCGIFHWADDR; |
| 108 | |
| 109 | # Allow GMS core to communicate with update_engine for A/B update. |
| 110 | binder_call(priv_app, update_engine) |
| 111 | allow priv_app update_engine_service:service_manager find; |
| 112 | |
Jin Qian | 00a1789 | 2017-04-12 17:38:11 -0700 | [diff] [blame] | 113 | # Allow GMS core to communicate with dumpsys storaged. |
| 114 | binder_call(priv_app, storaged) |
| 115 | allow priv_app storaged_service:service_manager find; |
| 116 | |
Tao Bao | d7d9cfc | 2017-10-16 21:57:12 -0700 | [diff] [blame] | 117 | # Allow GMS core to access system_update_service (e.g. to publish pending |
| 118 | # system update info). |
| 119 | allow priv_app system_update_service:service_manager find; |
| 120 | |
yro | 31b11d8 | 2018-01-09 11:27:36 -0800 | [diff] [blame] | 121 | # Allow GMS core to communicate with statsd. |
| 122 | binder_call(priv_app, statsd) |
| 123 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 124 | # Allow Phone to read/write cached ringtones (opened by system). |
| 125 | allow priv_app ringtone_file:file { getattr read write }; |
| 126 | |
| 127 | # Access to /data/preloads |
| 128 | allow priv_app preloads_data_file:file r_file_perms; |
| 129 | allow priv_app preloads_data_file:dir r_dir_perms; |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 130 | allow priv_app preloads_media_file:file r_file_perms; |
| 131 | allow priv_app preloads_media_file:dir r_dir_perms; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 132 | |
Shawn Willden | a0c7f01 | 2017-04-11 09:41:25 -0600 | [diff] [blame] | 133 | # Allow privileged apps (e.g. GMS core) to generate unique hardware IDs |
| 134 | allow priv_app keystore:keystore_key gen_unique_id; |
| 135 | |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 136 | # Allow GMS core to access /sys/fs/selinux/policyvers for compatibility check |
| 137 | allow priv_app selinuxfs:file r_file_perms; |
| 138 | |
Mark Salyzyn | d33a9a1 | 2016-11-07 15:11:39 -0800 | [diff] [blame] | 139 | read_runtime_log_tags(priv_app) |
| 140 | |
Primiano Tucci | c80f9e0 | 2017-12-21 03:51:15 +0100 | [diff] [blame] | 141 | # Write app-specific trace data to the Perfetto traced damon. This requires |
| 142 | # connecting to its producer socket and obtaining a (per-process) tmpfs fd. |
| 143 | allow priv_app traced:fd use; |
| 144 | allow priv_app traced_tmpfs:file { read write getattr map }; |
| 145 | unix_socket_connect(priv_app, traced_producer, traced) |
| 146 | |
Jeff Vander Stoep | 6d8a876 | 2018-01-18 08:55:02 -0800 | [diff] [blame] | 147 | # suppress denials for non-API accesses. |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 148 | dontaudit priv_app exec_type:file getattr; |
Jeff Vander Stoep | 6233848 | 2017-10-20 13:35:42 -0700 | [diff] [blame] | 149 | dontaudit priv_app device:dir read; |
Joel Galenson | 9ec59f6 | 2018-04-20 15:27:21 -0700 | [diff] [blame] | 150 | dontaudit priv_app fs_bpf:dir search; |
Jeff Vander Stoep | 9dc1d53 | 2018-04-04 14:36:13 -0700 | [diff] [blame] | 151 | dontaudit priv_app net_dns_prop:file read; |
Tri Vo | f92cfb9 | 2017-12-08 15:37:01 -0800 | [diff] [blame] | 152 | dontaudit priv_app proc:file read; |
Jeff Vander Stoep | 6233848 | 2017-10-20 13:35:42 -0700 | [diff] [blame] | 153 | dontaudit priv_app proc_interrupts:file read; |
| 154 | dontaudit priv_app proc_modules:file read; |
Jeff Vander Stoep | e88d649 | 2018-01-29 20:50:59 -0800 | [diff] [blame] | 155 | dontaudit priv_app proc_stat:file read; |
Jeff Vander Stoep | 6d8a876 | 2018-01-18 08:55:02 -0800 | [diff] [blame] | 156 | dontaudit priv_app proc_version:file read; |
Jeff Vander Stoep | 9dc1d53 | 2018-04-04 14:36:13 -0700 | [diff] [blame] | 157 | dontaudit priv_app sysfs:dir read; |
Jeff Vander Stoep | 4894d9f | 2018-06-29 11:04:24 -0700 | [diff] [blame] | 158 | dontaudit priv_app sysfs:file read; |
Jeff Vander Stoep | 9dc1d53 | 2018-04-04 14:36:13 -0700 | [diff] [blame] | 159 | dontaudit priv_app sysfs_android_usb:file read; |
Jeff Vander Stoep | 6d8a876 | 2018-01-18 08:55:02 -0800 | [diff] [blame] | 160 | dontaudit priv_app wifi_prop:file read; |
Jaekyun Seok | 224921d | 2018-04-09 12:07:32 +0900 | [diff] [blame] | 161 | dontaudit priv_app { wifi_prop exported_wifi_prop }:file read; |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame] | 162 | |
Nathan Harold | ee26864 | 2017-12-14 18:20:30 -0800 | [diff] [blame] | 163 | # allow privileged apps to use UDP sockets provided by the system server but not |
| 164 | # modify them other than to connect |
Nathan Harold | 252b015 | 2018-03-27 06:34:54 -0700 | [diff] [blame] | 165 | allow priv_app system_server:udp_socket { |
| 166 | connect getattr read recvfrom sendto write getopt setopt }; |
Nathan Harold | ee26864 | 2017-12-14 18:20:30 -0800 | [diff] [blame] | 167 | |
Jeff Vander Stoep | 9c7396d | 2018-06-01 12:12:11 -0700 | [diff] [blame] | 168 | # Attempts to write to system_data_file is generally a sign |
| 169 | # that apps are attempting to access encrypted storage before |
| 170 | # the ACTION_USER_UNLOCKED intent is delivered. Suppress this |
| 171 | # denial to prevent apps from spamming the logs. |
| 172 | dontaudit priv_app system_data_file:dir write; |
| 173 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 174 | ### |
| 175 | ### neverallow rules |
| 176 | ### |
| 177 | |
| 178 | # Receive or send uevent messages. |
| 179 | neverallow priv_app domain:netlink_kobject_uevent_socket *; |
| 180 | |
| 181 | # Receive or send generic netlink messages |
| 182 | neverallow priv_app domain:netlink_socket *; |
| 183 | |
| 184 | # Too much leaky information in debugfs. It's a security |
| 185 | # best practice to ensure these files aren't readable. |
| 186 | neverallow priv_app debugfs:file read; |
| 187 | |
| 188 | # Do not allow privileged apps to register services. |
| 189 | # Only trusted components of Android should be registering |
| 190 | # services. |
| 191 | neverallow priv_app service_manager_type:service_manager add; |
| 192 | |
| 193 | # Do not allow privileged apps to connect to the property service |
| 194 | # or set properties. b/10243159 |
| 195 | neverallow priv_app property_socket:sock_file write; |
| 196 | neverallow priv_app init:unix_stream_socket connectto; |
| 197 | neverallow priv_app property_type:property_service set; |
| 198 | |
| 199 | # Do not allow priv_app to be assigned mlstrustedsubject. |
| 200 | # This would undermine the per-user isolation model being |
| 201 | # enforced via levelFrom=user in seapp_contexts and the mls |
| 202 | # constraints. As there is no direct way to specify a neverallow |
| 203 | # on attribute assignment, this relies on the fact that fork |
| 204 | # permission only makes sense within a domain (hence should |
| 205 | # never be granted to any other domain within mlstrustedsubject) |
| 206 | # and priv_app is allowed fork permission to itself. |
| 207 | neverallow priv_app mlstrustedsubject:process fork; |
| 208 | |
| 209 | # Do not allow priv_app to hard link to any files. |
| 210 | # In particular, if priv_app links to other app data |
| 211 | # files, installd will not be able to guarantee the deletion |
| 212 | # of the linked to file. Hard links also contribute to security |
| 213 | # bugs, so we want to ensure priv_app never has this |
| 214 | # capability. |
| 215 | neverallow priv_app file_type:file link; |
Max Bires | 715e2ae | 2018-03-13 09:56:27 -0700 | [diff] [blame] | 216 | |
| 217 | # priv apps should not be able to open trace data files, they should depend |
| 218 | # upon traceur to pass a file descriptor which they can then read |
| 219 | neverallow priv_app trace_data_file:dir *; |
| 220 | neverallow priv_app trace_data_file:file { no_w_file_perms open }; |