1*e4a36f41SAndroid Build Coastguard Worker# installer daemon 2*e4a36f41SAndroid Build Coastguard Workertype installd, domain; 3*e4a36f41SAndroid Build Coastguard Workertype installd_exec, system_file_type, exec_type, file_type; 4*e4a36f41SAndroid Build Coastguard Workertypeattribute installd mlstrustedsubject; 5*e4a36f41SAndroid Build Coastguard Workerallow installd self:global_capability_class_set { chown dac_override dac_read_search fowner fsetid setgid setuid sys_admin }; 6*e4a36f41SAndroid Build Coastguard Worker 7*e4a36f41SAndroid Build Coastguard Worker# Allow labeling of files under /data/app/com.example/oat/ 8*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:dir relabelto; 9*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:file { relabelto link }; 10*e4a36f41SAndroid Build Coastguard Worker 11*e4a36f41SAndroid Build Coastguard Worker# Allow movement of APK files between volumes 12*e4a36f41SAndroid Build Coastguard Workerallow installd apk_data_file:dir { create_dir_perms relabelfrom }; 13*e4a36f41SAndroid Build Coastguard Workerallow installd apk_data_file:file { create_file_perms relabelfrom link }; 14*e4a36f41SAndroid Build Coastguard Workerallow installd apk_data_file:lnk_file { create r_file_perms unlink }; 15*e4a36f41SAndroid Build Coastguard Worker 16*e4a36f41SAndroid Build Coastguard Worker# FS_IOC_ENABLE_VERITY and FS_IOC_MEASURE_VERITY (or in old implementation used in installd, 17*e4a36f41SAndroid Build Coastguard Worker# FS_IOC_SET_VERITY_MEASUREMENT) ioctls on APKs in /data/app, to support fsverity. 18*e4a36f41SAndroid Build Coastguard Worker# TODO(b/120629632): this path is deprecated, remove when possible. 19*e4a36f41SAndroid Build Coastguard Workerallowxperm installd apk_data_file:file ioctl { 20*e4a36f41SAndroid Build Coastguard Worker FS_IOC_ENABLE_VERITY FS_IOC_MEASURE_VERITY 21*e4a36f41SAndroid Build Coastguard Worker}; 22*e4a36f41SAndroid Build Coastguard Worker 23*e4a36f41SAndroid Build Coastguard Workerallow installd asec_apk_file:file r_file_perms; 24*e4a36f41SAndroid Build Coastguard Workerallow installd apk_tmp_file:file { r_file_perms unlink }; 25*e4a36f41SAndroid Build Coastguard Workerallow installd apk_tmp_file:dir { relabelfrom create_dir_perms }; 26*e4a36f41SAndroid Build Coastguard Workerallow installd oemfs:dir r_dir_perms; 27*e4a36f41SAndroid Build Coastguard Workerallow installd oemfs:file r_file_perms; 28*e4a36f41SAndroid Build Coastguard Workerallow installd cgroup:dir create_dir_perms; 29*e4a36f41SAndroid Build Coastguard Workerallow installd mnt_expand_file:dir { search getattr }; 30*e4a36f41SAndroid Build Coastguard Worker# Check validity of SELinux context before use. 31*e4a36f41SAndroid Build Coastguard Workerselinux_check_context(installd) 32*e4a36f41SAndroid Build Coastguard Worker 33*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, rootfs) 34*e4a36f41SAndroid Build Coastguard Worker# Scan through APKs in /system/app and /system/priv-app 35*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, system_file) 36*e4a36f41SAndroid Build Coastguard Worker# Scan through APKs in /vendor/app 37*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_app_file) 38*e4a36f41SAndroid Build Coastguard Worker# Scan through JARs in /vendor/framework 39*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_framework_file) 40*e4a36f41SAndroid Build Coastguard Worker# Scan through Runtime Resource Overlay APKs in /vendor/overlay 41*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_overlay_file) 42*e4a36f41SAndroid Build Coastguard Worker# Get file context 43*e4a36f41SAndroid Build Coastguard Workerallow installd file_contexts_file:file r_file_perms; 44*e4a36f41SAndroid Build Coastguard Worker# Get seapp_context 45*e4a36f41SAndroid Build Coastguard Workerallow installd seapp_contexts_file:file r_file_perms; 46*e4a36f41SAndroid Build Coastguard Worker 47*e4a36f41SAndroid Build Coastguard Worker# Search /data/app-asec and stat files in it. 48*e4a36f41SAndroid Build Coastguard Workerallow installd asec_image_file:dir search; 49*e4a36f41SAndroid Build Coastguard Workerallow installd asec_image_file:file getattr; 50*e4a36f41SAndroid Build Coastguard Worker 51*e4a36f41SAndroid Build Coastguard Worker# Create /data/user and /data/user/0 if necessary. 52*e4a36f41SAndroid Build Coastguard Worker# Also required to initially create /data/data subdirectories 53*e4a36f41SAndroid Build Coastguard Worker# and lib symlinks before the setfilecon call. May want to 54*e4a36f41SAndroid Build Coastguard Worker# move symlink creation after setfilecon in installd. 55*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:dir create_dir_perms; 56*e4a36f41SAndroid Build Coastguard Worker# Also, allow read for lnk_file so that we can process /data/user/0 links when 57*e4a36f41SAndroid Build Coastguard Worker# optimizing application code. 58*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:lnk_file { create getattr read setattr unlink }; 59*e4a36f41SAndroid Build Coastguard Worker 60*e4a36f41SAndroid Build Coastguard Worker# Manage lower filesystem via pass_through mounts 61*e4a36f41SAndroid Build Coastguard Workerallow installd mnt_pass_through_file:dir r_dir_perms; 62*e4a36f41SAndroid Build Coastguard Worker 63*e4a36f41SAndroid Build Coastguard Worker# Upgrade /data/media for multi-user if necessary. 64*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:dir create_dir_perms; 65*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:file { getattr unlink }; 66*e4a36f41SAndroid Build Coastguard Worker# restorecon new /data/media directory. 67*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:dir relabelfrom; 68*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:dir relabelto; 69*e4a36f41SAndroid Build Coastguard Worker 70*e4a36f41SAndroid Build Coastguard Worker# Delete /data/media files through sdcardfs, instead of going behind its back 71*e4a36f41SAndroid Build Coastguard Workerallow installd tmpfs:dir r_dir_perms; 72*e4a36f41SAndroid Build Coastguard Workerallow installd storage_file:dir search; 73*e4a36f41SAndroid Build Coastguard Workerallow installd sdcard_type:dir { search open read write remove_name getattr rmdir }; 74*e4a36f41SAndroid Build Coastguard Workerallow installd sdcard_type:file { getattr unlink }; 75*e4a36f41SAndroid Build Coastguard Worker 76*e4a36f41SAndroid Build Coastguard Worker# Create app's mirror data directory in /data_mirror, and bind mount the real directory to it 77*e4a36f41SAndroid Build Coastguard Workerallow installd mirror_data_file:dir { create_dir_perms mounton }; 78*e4a36f41SAndroid Build Coastguard Worker 79*e4a36f41SAndroid Build Coastguard Worker# Upgrade /data/misc/keychain for multi-user if necessary. 80*e4a36f41SAndroid Build Coastguard Workerallow installd misc_user_data_file:dir create_dir_perms; 81*e4a36f41SAndroid Build Coastguard Workerallow installd misc_user_data_file:file create_file_perms; 82*e4a36f41SAndroid Build Coastguard Workerallow installd keychain_data_file:dir create_dir_perms; 83*e4a36f41SAndroid Build Coastguard Workerallow installd keychain_data_file:file {r_file_perms unlink}; 84*e4a36f41SAndroid Build Coastguard Worker 85*e4a36f41SAndroid Build Coastguard Worker# Create /data/misc/installd/layout_version.* file 86*e4a36f41SAndroid Build Coastguard Workerallow installd install_data_file:file create_file_perms; 87*e4a36f41SAndroid Build Coastguard Workerallow installd install_data_file:dir rw_dir_perms; 88*e4a36f41SAndroid Build Coastguard Worker 89*e4a36f41SAndroid Build Coastguard Worker# Create files under /data/dalvik-cache. 90*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:dir create_dir_perms; 91*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:file create_file_perms; 92*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:lnk_file getattr; 93*e4a36f41SAndroid Build Coastguard Worker 94*e4a36f41SAndroid Build Coastguard Worker# Create files under /data/resource-cache. 95*e4a36f41SAndroid Build Coastguard Workerallow installd resourcecache_data_file:dir rw_dir_perms; 96*e4a36f41SAndroid Build Coastguard Workerallow installd resourcecache_data_file:file create_file_perms; 97*e4a36f41SAndroid Build Coastguard Worker 98*e4a36f41SAndroid Build Coastguard Worker# Upgrade from unlabeled userdata. 99*e4a36f41SAndroid Build Coastguard Worker# Just need enough to remove and/or relabel it. 100*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:dir { getattr search relabelfrom rw_dir_perms rmdir }; 101*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:notdevfile_class_set { getattr relabelfrom rename unlink setattr }; 102*e4a36f41SAndroid Build Coastguard Worker# Read pkg.apk file for input during dexopt. 103*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:file r_file_perms; 104*e4a36f41SAndroid Build Coastguard Worker 105*e4a36f41SAndroid Build Coastguard Worker# Upgrade from before system_app_data_file was used for system UID apps. 106*e4a36f41SAndroid Build Coastguard Worker# Just need enough to relabel it and to unlink removed package files. 107*e4a36f41SAndroid Build Coastguard Worker# Directory access covered by earlier rule above. 108*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:notdevfile_class_set { getattr relabelfrom unlink }; 109*e4a36f41SAndroid Build Coastguard Worker 110*e4a36f41SAndroid Build Coastguard Worker# Manage /data/data subdirectories, including initially labeling them 111*e4a36f41SAndroid Build Coastguard Worker# upon creation via setfilecon or running restorecon_recursive, 112*e4a36f41SAndroid Build Coastguard Worker# setting owner/mode, creating symlinks within them, and deleting them 113*e4a36f41SAndroid Build Coastguard Worker# upon package uninstall. 114*e4a36f41SAndroid Build Coastguard Worker 115*e4a36f41SAndroid Build Coastguard Worker# Types extracted from seapp_contexts type= fields. 116*e4a36f41SAndroid Build Coastguard Workerallow installd { 117*e4a36f41SAndroid Build Coastguard Worker system_app_data_file 118*e4a36f41SAndroid Build Coastguard Worker bluetooth_data_file 119*e4a36f41SAndroid Build Coastguard Worker nfc_data_file 120*e4a36f41SAndroid Build Coastguard Worker radio_data_file 121*e4a36f41SAndroid Build Coastguard Worker shell_data_file 122*e4a36f41SAndroid Build Coastguard Worker app_data_file 123*e4a36f41SAndroid Build Coastguard Worker privapp_data_file 124*e4a36f41SAndroid Build Coastguard Worker}:dir { create_dir_perms relabelfrom relabelto }; 125*e4a36f41SAndroid Build Coastguard Worker 126*e4a36f41SAndroid Build Coastguard Workerallow installd { 127*e4a36f41SAndroid Build Coastguard Worker system_app_data_file 128*e4a36f41SAndroid Build Coastguard Worker bluetooth_data_file 129*e4a36f41SAndroid Build Coastguard Worker nfc_data_file 130*e4a36f41SAndroid Build Coastguard Worker radio_data_file 131*e4a36f41SAndroid Build Coastguard Worker shell_data_file 132*e4a36f41SAndroid Build Coastguard Worker app_data_file 133*e4a36f41SAndroid Build Coastguard Worker privapp_data_file 134*e4a36f41SAndroid Build Coastguard Worker}:notdevfile_class_set { create_file_perms relabelfrom relabelto }; 135*e4a36f41SAndroid Build Coastguard Worker 136*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to unmount mirror directories 137*e4a36f41SAndroid Build Coastguard Workerallow installd labeledfs:filesystem unmount; 138*e4a36f41SAndroid Build Coastguard Worker 139*e4a36f41SAndroid Build Coastguard Worker# Similar for the files under /data/misc/profiles/ 140*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:dir create_dir_perms; 141*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:file create_file_perms; 142*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:dir rmdir; 143*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:file unlink; 144*e4a36f41SAndroid Build Coastguard Worker 145*e4a36f41SAndroid Build Coastguard Worker# Files created/updated by profman dumps. 146*e4a36f41SAndroid Build Coastguard Workerallow installd profman_dump_data_file:dir { search add_name write }; 147*e4a36f41SAndroid Build Coastguard Workerallow installd profman_dump_data_file:file { create setattr open write }; 148*e4a36f41SAndroid Build Coastguard Worker 149*e4a36f41SAndroid Build Coastguard Worker# Create and use pty created by android_fork_execvp(). 150*e4a36f41SAndroid Build Coastguard Workerallow installd devpts:chr_file rw_file_perms; 151*e4a36f41SAndroid Build Coastguard Worker 152*e4a36f41SAndroid Build Coastguard Worker# execute toybox for app relocation 153*e4a36f41SAndroid Build Coastguard Workerallow installd toolbox_exec:file rx_file_perms; 154*e4a36f41SAndroid Build Coastguard Worker 155*e4a36f41SAndroid Build Coastguard Worker# Allow installd to publish a binder service and make binder calls. 156*e4a36f41SAndroid Build Coastguard Workerbinder_use(installd) 157*e4a36f41SAndroid Build Coastguard Workeradd_service(installd, installd_service) 158*e4a36f41SAndroid Build Coastguard Workerallow installd dumpstate:fifo_file { getattr write }; 159*e4a36f41SAndroid Build Coastguard Worker 160*e4a36f41SAndroid Build Coastguard Worker# Allow installd to call into the system server so it can check permissions. 161*e4a36f41SAndroid Build Coastguard Workerbinder_call(installd, system_server) 162*e4a36f41SAndroid Build Coastguard Workerallow installd permission_service:service_manager find; 163*e4a36f41SAndroid Build Coastguard Worker 164*e4a36f41SAndroid Build Coastguard Worker# Allow installd to read and write quotas 165*e4a36f41SAndroid Build Coastguard Workerallow installd block_device:dir { search }; 166*e4a36f41SAndroid Build Coastguard Workerallow installd labeledfs:filesystem { quotaget quotamod }; 167*e4a36f41SAndroid Build Coastguard Worker 168*e4a36f41SAndroid Build Coastguard Worker# Allow installd to delete from /data/preloads when trimming data caches 169*e4a36f41SAndroid Build Coastguard Worker# TODO b/34690396 Remove when time-based purge policy for preloads is implemented in system_server 170*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_data_file:file { r_file_perms unlink }; 171*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_data_file:dir { r_dir_perms write remove_name rmdir }; 172*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_media_file:file { r_file_perms unlink }; 173*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_media_file:dir { r_dir_perms write remove_name rmdir }; 174*e4a36f41SAndroid Build Coastguard Worker 175*e4a36f41SAndroid Build Coastguard Worker# Allow installd to read /proc/filesystems 176*e4a36f41SAndroid Build Coastguard Workerallow installd proc_filesystems:file r_file_perms; 177*e4a36f41SAndroid Build Coastguard Worker 178*e4a36f41SAndroid Build Coastguard Worker### 179*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 180*e4a36f41SAndroid Build Coastguard Worker### 181*e4a36f41SAndroid Build Coastguard Worker 182*e4a36f41SAndroid Build Coastguard Worker# only system_server, installd, dumpstate, and servicemanager may interact with installd over binder 183*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server -dumpstate -installd } installd_service:service_manager find; 184*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server -dumpstate -servicemanager } installd:binder call; 185*e4a36f41SAndroid Build Coastguard Workerneverallow installd { 186*e4a36f41SAndroid Build Coastguard Worker domain 187*e4a36f41SAndroid Build Coastguard Worker -system_server 188*e4a36f41SAndroid Build Coastguard Worker -servicemanager 189*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-su') 190*e4a36f41SAndroid Build Coastguard Worker}:binder call; 191