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(). |
Daniel Micay | 41e3ee46 | 2017-01-08 17:19:02 -0500 | [diff] [blame] | 22 | allow priv_app app_data_file:file execute; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 23 | |
| 24 | allow priv_app audioserver_service:service_manager find; |
| 25 | allow priv_app cameraserver_service:service_manager find; |
| 26 | allow priv_app drmserver_service:service_manager find; |
| 27 | allow priv_app mediacodec_service:service_manager find; |
Ray Essick | 3918540 | 2017-01-24 12:53:45 -0800 | [diff] [blame] | 28 | allow priv_app mediametrics_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 29 | allow priv_app mediadrmserver_service:service_manager find; |
| 30 | allow priv_app mediaextractor_service:service_manager find; |
| 31 | allow priv_app mediaserver_service:service_manager find; |
| 32 | allow priv_app nfc_service:service_manager find; |
Andrew Scull | 3717424 | 2017-02-17 13:51:32 +0000 | [diff] [blame] | 33 | allow priv_app oem_lock_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 34 | allow priv_app radio_service:service_manager find; |
| 35 | allow priv_app surfaceflinger_service:service_manager find; |
| 36 | allow priv_app app_api_service:service_manager find; |
| 37 | allow priv_app system_api_service:service_manager find; |
| 38 | allow priv_app persistent_data_block_service:service_manager find; |
| 39 | allow priv_app recovery_service:service_manager find; |
| 40 | |
| 41 | # Write to /cache. |
| 42 | allow priv_app { cache_file cache_recovery_file }:dir create_dir_perms; |
| 43 | allow priv_app { cache_file cache_recovery_file }:file create_file_perms; |
Nick Kralevich | 21cb045 | 2017-01-23 22:19:06 -0800 | [diff] [blame] | 44 | # /cache is a symlink to /data/cache on some devices. Allow reading the link. |
| 45 | allow priv_app cache_file:lnk_file r_file_perms; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 46 | |
| 47 | # Write to /data/ota_package for OTA packages. |
| 48 | allow priv_app ota_package_file:dir rw_dir_perms; |
| 49 | allow priv_app ota_package_file:file create_file_perms; |
| 50 | |
| 51 | # Access to /data/media. |
| 52 | allow priv_app media_rw_data_file:dir create_dir_perms; |
| 53 | allow priv_app media_rw_data_file:file create_file_perms; |
| 54 | |
| 55 | # Used by Finsky / Android "Verify Apps" functionality when |
| 56 | # running "adb install foo.apk". |
| 57 | allow priv_app shell_data_file:file r_file_perms; |
| 58 | allow priv_app shell_data_file:dir r_dir_perms; |
| 59 | |
| 60 | # Allow verifier to access staged apks. |
| 61 | allow priv_app { apk_tmp_file apk_private_tmp_file }:dir r_dir_perms; |
| 62 | allow priv_app { apk_tmp_file apk_private_tmp_file }:file r_file_perms; |
| 63 | |
| 64 | # b/18504118: Allow reads from /data/anr/traces.txt |
| 65 | allow priv_app anr_data_file:file r_file_perms; |
| 66 | |
| 67 | # Allow GMS core to access perfprofd output, which is stored |
| 68 | # in /data/misc/perfprofd/. GMS core will need to list all |
| 69 | # data stored in that directory to process them one by one. |
| 70 | userdebug_or_eng(` |
| 71 | allow priv_app perfprofd_data_file:file r_file_perms; |
| 72 | allow priv_app perfprofd_data_file:dir r_dir_perms; |
| 73 | ') |
| 74 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 75 | # For AppFuse. |
| 76 | allow priv_app vold:fd use; |
| 77 | allow priv_app fuse_device:chr_file { read write }; |
| 78 | |
| 79 | # /sys and /proc access |
| 80 | r_dir_file(priv_app, sysfs_type) |
| 81 | r_dir_file(priv_app, proc) |
| 82 | r_dir_file(priv_app, rootfs) |
| 83 | |
Sandeep Patil | 0465442 | 2017-04-19 11:35:15 -0700 | [diff] [blame] | 84 | # Allow GMS core to open kernel config for OTA matching through libvintf |
| 85 | allow priv_app config_gz:file { open read getattr }; |
| 86 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 87 | # access the mac address |
| 88 | allowxperm priv_app self:udp_socket ioctl SIOCGIFHWADDR; |
| 89 | |
| 90 | # Allow GMS core to communicate with update_engine for A/B update. |
| 91 | binder_call(priv_app, update_engine) |
| 92 | allow priv_app update_engine_service:service_manager find; |
| 93 | |
Jin Qian | 00a1789 | 2017-04-12 17:38:11 -0700 | [diff] [blame] | 94 | # Allow GMS core to communicate with dumpsys storaged. |
| 95 | binder_call(priv_app, storaged) |
| 96 | allow priv_app storaged_service:service_manager find; |
| 97 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 98 | # Allow Phone to read/write cached ringtones (opened by system). |
| 99 | allow priv_app ringtone_file:file { getattr read write }; |
| 100 | |
| 101 | # Access to /data/preloads |
| 102 | allow priv_app preloads_data_file:file r_file_perms; |
| 103 | allow priv_app preloads_data_file:dir r_dir_perms; |
Fyodor Kupolov | b238fe6 | 2017-03-14 11:42:03 -0700 | [diff] [blame] | 104 | allow priv_app preloads_media_file:file r_file_perms; |
| 105 | allow priv_app preloads_media_file:dir r_dir_perms; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 106 | |
Shawn Willden | a0c7f01 | 2017-04-11 09:41:25 -0600 | [diff] [blame] | 107 | # Allow privileged apps (e.g. GMS core) to generate unique hardware IDs |
| 108 | allow priv_app keystore:keystore_key gen_unique_id; |
| 109 | |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame^] | 110 | # Allow GMS core to access /sys/fs/selinux/policyvers for compatibility check |
| 111 | allow priv_app selinuxfs:file r_file_perms; |
| 112 | |
Mark Salyzyn | d33a9a1 | 2016-11-07 15:11:39 -0800 | [diff] [blame] | 113 | read_runtime_log_tags(priv_app) |
| 114 | |
Dan Cashman | 91d398d | 2017-09-26 12:58:29 -0700 | [diff] [blame^] | 115 | # suppress denials when safetynet scans /system |
| 116 | dontaudit priv_app exec_type:file getattr; |
| 117 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 118 | ### |
| 119 | ### neverallow rules |
| 120 | ### |
| 121 | |
| 122 | # Receive or send uevent messages. |
| 123 | neverallow priv_app domain:netlink_kobject_uevent_socket *; |
| 124 | |
| 125 | # Receive or send generic netlink messages |
| 126 | neverallow priv_app domain:netlink_socket *; |
| 127 | |
| 128 | # Too much leaky information in debugfs. It's a security |
| 129 | # best practice to ensure these files aren't readable. |
| 130 | neverallow priv_app debugfs:file read; |
| 131 | |
| 132 | # Do not allow privileged apps to register services. |
| 133 | # Only trusted components of Android should be registering |
| 134 | # services. |
| 135 | neverallow priv_app service_manager_type:service_manager add; |
| 136 | |
| 137 | # Do not allow privileged apps to connect to the property service |
| 138 | # or set properties. b/10243159 |
| 139 | neverallow priv_app property_socket:sock_file write; |
| 140 | neverallow priv_app init:unix_stream_socket connectto; |
| 141 | neverallow priv_app property_type:property_service set; |
| 142 | |
| 143 | # Do not allow priv_app to be assigned mlstrustedsubject. |
| 144 | # This would undermine the per-user isolation model being |
| 145 | # enforced via levelFrom=user in seapp_contexts and the mls |
| 146 | # constraints. As there is no direct way to specify a neverallow |
| 147 | # on attribute assignment, this relies on the fact that fork |
| 148 | # permission only makes sense within a domain (hence should |
| 149 | # never be granted to any other domain within mlstrustedsubject) |
| 150 | # and priv_app is allowed fork permission to itself. |
| 151 | neverallow priv_app mlstrustedsubject:process fork; |
| 152 | |
| 153 | # Do not allow priv_app to hard link to any files. |
| 154 | # In particular, if priv_app links to other app data |
| 155 | # files, installd will not be able to guarantee the deletion |
| 156 | # of the linked to file. Hard links also contribute to security |
| 157 | # bugs, so we want to ensure priv_app never has this |
| 158 | # capability. |
| 159 | neverallow priv_app file_type:file link; |