Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 1 | ### |
| 2 | ### A domain for further sandboxing privileged apps. |
| 3 | ### |
| 4 | |
dcashman | 3e8dbf0 | 2016-12-08 11:23:34 -0800 | [diff] [blame] | 5 | app_domain(priv_app) |
dcashman | 2e00e63 | 2016-10-12 14:58:09 -0700 | [diff] [blame] | 6 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 7 | # Access the network. |
| 8 | net_domain(priv_app) |
| 9 | # Access bluetooth. |
| 10 | bluetooth_domain(priv_app) |
| 11 | |
dcashman | 2e00e63 | 2016-10-12 14:58:09 -0700 | [diff] [blame] | 12 | # Allow the allocation and use of ptys |
| 13 | # Used by: https://play.privileged.com/store/apps/details?id=jackpal.androidterm |
| 14 | create_pty(priv_app) |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 15 | |
| 16 | # webview crash handling depends on self ptrace (b/27697529, b/20150694, b/19277529#comment7) |
| 17 | allow priv_app self:process ptrace; |
| 18 | |
| 19 | # Some apps ship with shared libraries that they write out |
| 20 | # to their sandbox directory and then dlopen(). |
Daniel Micay | 41e3ee46 | 2017-01-08 17:19:02 -0500 | [diff] [blame] | 21 | allow priv_app app_data_file:file execute; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 22 | |
| 23 | allow priv_app audioserver_service:service_manager find; |
| 24 | allow priv_app cameraserver_service:service_manager find; |
| 25 | allow priv_app drmserver_service:service_manager find; |
| 26 | allow priv_app mediacodec_service:service_manager find; |
Ray Essick | 3918540 | 2017-01-24 12:53:45 -0800 | [diff] [blame] | 27 | allow priv_app mediametrics_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 28 | allow priv_app mediadrmserver_service:service_manager find; |
Chong Zhang | 7291641 | 2016-10-31 17:02:32 -0700 | [diff] [blame] | 29 | allow priv_app mediacasserver_service:service_manager find; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 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; |
| 33 | allow priv_app radio_service:service_manager find; |
| 34 | allow priv_app surfaceflinger_service:service_manager find; |
| 35 | allow priv_app app_api_service:service_manager find; |
| 36 | allow priv_app system_api_service:service_manager find; |
| 37 | allow priv_app persistent_data_block_service:service_manager find; |
| 38 | allow priv_app recovery_service:service_manager find; |
| 39 | |
| 40 | # Write to /cache. |
| 41 | allow priv_app { cache_file cache_recovery_file }:dir create_dir_perms; |
| 42 | allow priv_app { cache_file cache_recovery_file }:file create_file_perms; |
Nick Kralevich | 21cb045 | 2017-01-23 22:19:06 -0800 | [diff] [blame] | 43 | # /cache is a symlink to /data/cache on some devices. Allow reading the link. |
| 44 | allow priv_app cache_file:lnk_file r_file_perms; |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 45 | |
| 46 | # Write to /data/ota_package for OTA packages. |
| 47 | allow priv_app ota_package_file:dir rw_dir_perms; |
| 48 | allow priv_app ota_package_file:file create_file_perms; |
| 49 | |
| 50 | # Access to /data/media. |
| 51 | allow priv_app media_rw_data_file:dir create_dir_perms; |
| 52 | allow priv_app media_rw_data_file:file create_file_perms; |
| 53 | |
| 54 | # Used by Finsky / Android "Verify Apps" functionality when |
| 55 | # running "adb install foo.apk". |
| 56 | allow priv_app shell_data_file:file r_file_perms; |
| 57 | allow priv_app shell_data_file:dir r_dir_perms; |
| 58 | |
| 59 | # Allow verifier to access staged apks. |
| 60 | allow priv_app { apk_tmp_file apk_private_tmp_file }:dir r_dir_perms; |
| 61 | allow priv_app { apk_tmp_file apk_private_tmp_file }:file r_file_perms; |
| 62 | |
| 63 | # b/18504118: Allow reads from /data/anr/traces.txt |
| 64 | allow priv_app anr_data_file:file r_file_perms; |
| 65 | |
| 66 | # Allow GMS core to access perfprofd output, which is stored |
| 67 | # in /data/misc/perfprofd/. GMS core will need to list all |
| 68 | # data stored in that directory to process them one by one. |
| 69 | userdebug_or_eng(` |
| 70 | allow priv_app perfprofd_data_file:file r_file_perms; |
| 71 | allow priv_app perfprofd_data_file:dir r_dir_perms; |
| 72 | ') |
| 73 | |
| 74 | # Allow GMS core to scan executables on the system partition |
| 75 | allow priv_app exec_type:file { getattr read open }; |
| 76 | |
| 77 | # For AppFuse. |
| 78 | allow priv_app vold:fd use; |
| 79 | allow priv_app fuse_device:chr_file { read write }; |
| 80 | |
| 81 | # /sys and /proc access |
| 82 | r_dir_file(priv_app, sysfs_type) |
| 83 | r_dir_file(priv_app, proc) |
| 84 | r_dir_file(priv_app, rootfs) |
| 85 | |
| 86 | # access the mac address |
| 87 | allowxperm priv_app self:udp_socket ioctl SIOCGIFHWADDR; |
| 88 | |
| 89 | # Allow GMS core to communicate with update_engine for A/B update. |
| 90 | binder_call(priv_app, update_engine) |
| 91 | allow priv_app update_engine_service:service_manager find; |
| 92 | |
| 93 | # Allow Phone to read/write cached ringtones (opened by system). |
| 94 | allow priv_app ringtone_file:file { getattr read write }; |
| 95 | |
| 96 | # Access to /data/preloads |
| 97 | allow priv_app preloads_data_file:file r_file_perms; |
| 98 | allow priv_app preloads_data_file:dir r_dir_perms; |
| 99 | |
| 100 | # TODO: revert this as part of fixing 33574909 |
| 101 | # android.process.media uses /dev/mtp_usb |
| 102 | allow priv_app mtp_device:chr_file rw_file_perms; |
| 103 | |
| 104 | # TODO: revert this as part of fixing 33574909 |
| 105 | # MtpServer uses /dev/usb-ffs/mtp |
| 106 | allow priv_app functionfs:dir search; |
| 107 | allow priv_app functionfs:file rw_file_perms; |
| 108 | |
| 109 | # TODO: revert this as part of fixing 33574909 |
| 110 | # Traverse into /mnt/media_rw for bypassing FUSE daemon |
| 111 | # TODO: narrow this to just MediaProvider |
| 112 | allow priv_app mnt_media_rw_file:dir search; |
| 113 | |
Mark Salyzyn | d33a9a1 | 2016-11-07 15:11:39 -0800 | [diff] [blame] | 114 | read_runtime_log_tags(priv_app) |
| 115 | |
Alex Klyubin | 92295ef | 2017-01-05 15:44:32 -0800 | [diff] [blame] | 116 | ### |
| 117 | ### neverallow rules |
| 118 | ### |
| 119 | |
| 120 | # Receive or send uevent messages. |
| 121 | neverallow priv_app domain:netlink_kobject_uevent_socket *; |
| 122 | |
| 123 | # Receive or send generic netlink messages |
| 124 | neverallow priv_app domain:netlink_socket *; |
| 125 | |
| 126 | # Too much leaky information in debugfs. It's a security |
| 127 | # best practice to ensure these files aren't readable. |
| 128 | neverallow priv_app debugfs:file read; |
| 129 | |
| 130 | # Do not allow privileged apps to register services. |
| 131 | # Only trusted components of Android should be registering |
| 132 | # services. |
| 133 | neverallow priv_app service_manager_type:service_manager add; |
| 134 | |
| 135 | # Do not allow privileged apps to connect to the property service |
| 136 | # or set properties. b/10243159 |
| 137 | neverallow priv_app property_socket:sock_file write; |
| 138 | neverallow priv_app init:unix_stream_socket connectto; |
| 139 | neverallow priv_app property_type:property_service set; |
| 140 | |
| 141 | # Do not allow priv_app to be assigned mlstrustedsubject. |
| 142 | # This would undermine the per-user isolation model being |
| 143 | # enforced via levelFrom=user in seapp_contexts and the mls |
| 144 | # constraints. As there is no direct way to specify a neverallow |
| 145 | # on attribute assignment, this relies on the fact that fork |
| 146 | # permission only makes sense within a domain (hence should |
| 147 | # never be granted to any other domain within mlstrustedsubject) |
| 148 | # and priv_app is allowed fork permission to itself. |
| 149 | neverallow priv_app mlstrustedsubject:process fork; |
| 150 | |
| 151 | # Do not allow priv_app to hard link to any files. |
| 152 | # In particular, if priv_app links to other app data |
| 153 | # files, installd will not be able to guarantee the deletion |
| 154 | # of the linked to file. Hard links also contribute to security |
| 155 | # bugs, so we want to ensure priv_app never has this |
| 156 | # capability. |
| 157 | neverallow priv_app file_type:file link; |