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 cgroup_v2:dir create_dir_perms; 30*e4a36f41SAndroid Build Coastguard Workerallow installd mnt_expand_file:dir { search getattr }; 31*e4a36f41SAndroid Build Coastguard Worker# Check validity of SELinux context before use. 32*e4a36f41SAndroid Build Coastguard Workerselinux_check_context(installd) 33*e4a36f41SAndroid Build Coastguard Worker 34*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, rootfs) 35*e4a36f41SAndroid Build Coastguard Worker# Scan through APKs in /system/app and /system/priv-app 36*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, system_file) 37*e4a36f41SAndroid Build Coastguard Worker# Scan through APKs in /vendor/app 38*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_app_file) 39*e4a36f41SAndroid Build Coastguard Worker# Scan through JARs in /vendor/framework 40*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_framework_file) 41*e4a36f41SAndroid Build Coastguard Worker# Scan through Runtime Resource Overlay APKs in /vendor/overlay 42*e4a36f41SAndroid Build Coastguard Workerr_dir_file(installd, vendor_overlay_file) 43*e4a36f41SAndroid Build Coastguard Worker# Get file context 44*e4a36f41SAndroid Build Coastguard Workerallow installd file_contexts_file:file r_file_perms; 45*e4a36f41SAndroid Build Coastguard Worker# Get seapp_context 46*e4a36f41SAndroid Build Coastguard Workerallow installd seapp_contexts_file:file r_file_perms; 47*e4a36f41SAndroid Build Coastguard Worker 48*e4a36f41SAndroid Build Coastguard Worker# Search /data/app-asec and stat files in it. 49*e4a36f41SAndroid Build Coastguard Workerallow installd asec_image_file:dir search; 50*e4a36f41SAndroid Build Coastguard Workerallow installd asec_image_file:file getattr; 51*e4a36f41SAndroid Build Coastguard Worker 52*e4a36f41SAndroid Build Coastguard Worker# Create /data/user and /data/user/0 if necessary. 53*e4a36f41SAndroid Build Coastguard Worker# Also required to initially create /data/data subdirectories 54*e4a36f41SAndroid Build Coastguard Worker# and lib symlinks before the setfilecon call. May want to 55*e4a36f41SAndroid Build Coastguard Worker# move symlink creation after setfilecon in installd. 56*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:dir create_dir_perms; 57*e4a36f41SAndroid Build Coastguard Worker# Also, allow read for lnk_file so that we can process /data/user/0 links when 58*e4a36f41SAndroid Build Coastguard Worker# optimizing application code. 59*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:lnk_file { create getattr read setattr unlink }; 60*e4a36f41SAndroid Build Coastguard Worker 61*e4a36f41SAndroid Build Coastguard Worker# Manage lower filesystem via pass_through mounts 62*e4a36f41SAndroid Build Coastguard Workerallow installd mnt_pass_through_file:dir r_dir_perms; 63*e4a36f41SAndroid Build Coastguard Worker 64*e4a36f41SAndroid Build Coastguard Worker# Upgrade /data/media for multi-user if necessary. 65*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:dir create_dir_perms; 66*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:file { getattr unlink }; 67*e4a36f41SAndroid Build Coastguard Worker# restorecon new /data/media directory. 68*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:dir relabelfrom; 69*e4a36f41SAndroid Build Coastguard Workerallow installd media_rw_data_file:dir relabelto; 70*e4a36f41SAndroid Build Coastguard Worker 71*e4a36f41SAndroid Build Coastguard Worker# Delete /data/media files through sdcardfs, instead of going behind its back 72*e4a36f41SAndroid Build Coastguard Workerallow installd tmpfs:dir r_dir_perms; 73*e4a36f41SAndroid Build Coastguard Workerallow installd storage_file:dir search; 74*e4a36f41SAndroid Build Coastguard Workerallow installd sdcard_type:dir { search open read write remove_name getattr rmdir }; 75*e4a36f41SAndroid Build Coastguard Workerallow installd sdcard_type:file { getattr unlink }; 76*e4a36f41SAndroid Build Coastguard Worker 77*e4a36f41SAndroid Build Coastguard Worker# Create app's mirror data directory in /data_mirror, and bind mount the real directory to it 78*e4a36f41SAndroid Build Coastguard Workerallow installd mirror_data_file:dir { create_dir_perms mounton }; 79*e4a36f41SAndroid Build Coastguard Worker 80*e4a36f41SAndroid Build Coastguard Worker# Upgrade /data/misc/keychain for multi-user if necessary. 81*e4a36f41SAndroid Build Coastguard Workerallow installd misc_user_data_file:dir create_dir_perms; 82*e4a36f41SAndroid Build Coastguard Workerallow installd misc_user_data_file:file create_file_perms; 83*e4a36f41SAndroid Build Coastguard Workerallow installd keychain_data_file:dir create_dir_perms; 84*e4a36f41SAndroid Build Coastguard Workerallow installd keychain_data_file:file {r_file_perms unlink}; 85*e4a36f41SAndroid Build Coastguard Worker 86*e4a36f41SAndroid Build Coastguard Worker# Create /data/misc/installd/layout_version.* file 87*e4a36f41SAndroid Build Coastguard Workerallow installd install_data_file:file create_file_perms; 88*e4a36f41SAndroid Build Coastguard Workerallow installd install_data_file:dir rw_dir_perms; 89*e4a36f41SAndroid Build Coastguard Worker 90*e4a36f41SAndroid Build Coastguard Worker# Create files under /data/dalvik-cache. 91*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:dir create_dir_perms; 92*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:file create_file_perms; 93*e4a36f41SAndroid Build Coastguard Workerallow installd dalvikcache_data_file:lnk_file getattr; 94*e4a36f41SAndroid Build Coastguard Worker 95*e4a36f41SAndroid Build Coastguard Worker# Create files under /data/resource-cache. 96*e4a36f41SAndroid Build Coastguard Workerallow installd resourcecache_data_file:dir rw_dir_perms; 97*e4a36f41SAndroid Build Coastguard Workerallow installd resourcecache_data_file:file create_file_perms; 98*e4a36f41SAndroid Build Coastguard Worker 99*e4a36f41SAndroid Build Coastguard Worker# Upgrade from unlabeled userdata. 100*e4a36f41SAndroid Build Coastguard Worker# Just need enough to remove and/or relabel it. 101*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:dir { getattr search relabelfrom rw_dir_perms rmdir }; 102*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:notdevfile_class_set { getattr relabelfrom rename unlink setattr }; 103*e4a36f41SAndroid Build Coastguard Worker# Read pkg.apk file for input during dexopt. 104*e4a36f41SAndroid Build Coastguard Workerallow installd unlabeled:file r_file_perms; 105*e4a36f41SAndroid Build Coastguard Worker 106*e4a36f41SAndroid Build Coastguard Worker# Upgrade from before system_app_data_file was used for system UID apps. 107*e4a36f41SAndroid Build Coastguard Worker# Just need enough to relabel it and to unlink removed package files. 108*e4a36f41SAndroid Build Coastguard Worker# Directory access covered by earlier rule above. 109*e4a36f41SAndroid Build Coastguard Workerallow installd system_data_file:notdevfile_class_set { getattr relabelfrom unlink }; 110*e4a36f41SAndroid Build Coastguard Worker 111*e4a36f41SAndroid Build Coastguard Worker# Manage /data/data subdirectories, including initially labeling them 112*e4a36f41SAndroid Build Coastguard Worker# upon creation via setfilecon or running restorecon_recursive, 113*e4a36f41SAndroid Build Coastguard Worker# setting owner/mode, creating symlinks within them, and deleting them 114*e4a36f41SAndroid Build Coastguard Worker# upon package uninstall. 115*e4a36f41SAndroid Build Coastguard Workerallow installd app_data_file_type:dir { create_dir_perms relabelfrom relabelto }; 116*e4a36f41SAndroid Build Coastguard Workerallow installd app_data_file_type:notdevfile_class_set { create_file_perms relabelfrom relabelto }; 117*e4a36f41SAndroid Build Coastguard Worker 118*e4a36f41SAndroid Build Coastguard Worker# Similar for the files under /data/misc/profiles/ 119*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_root_file:dir { create_dir_perms relabelfrom }; 120*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:dir { create_dir_perms relabelto }; 121*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:file create_file_perms; 122*e4a36f41SAndroid Build Coastguard Workerallow installd user_profile_data_file:file unlink; 123*e4a36f41SAndroid Build Coastguard Worker 124*e4a36f41SAndroid Build Coastguard Worker# Allow zygote to unmount mirror directories 125*e4a36f41SAndroid Build Coastguard Workerallow installd labeledfs:filesystem unmount; 126*e4a36f41SAndroid Build Coastguard Worker 127*e4a36f41SAndroid Build Coastguard Worker# Files created/updated by profman dumps. 128*e4a36f41SAndroid Build Coastguard Workerallow installd profman_dump_data_file:dir { search add_name write }; 129*e4a36f41SAndroid Build Coastguard Workerallow installd profman_dump_data_file:file { create setattr open write }; 130*e4a36f41SAndroid Build Coastguard Worker 131*e4a36f41SAndroid Build Coastguard Worker# Create and use pty created by android_fork_execvp(). 132*e4a36f41SAndroid Build Coastguard Workerallow installd devpts:chr_file rw_file_perms; 133*e4a36f41SAndroid Build Coastguard Worker 134*e4a36f41SAndroid Build Coastguard Worker# execute toybox for app relocation 135*e4a36f41SAndroid Build Coastguard Workerallow installd toolbox_exec:file rx_file_perms; 136*e4a36f41SAndroid Build Coastguard Worker 137*e4a36f41SAndroid Build Coastguard Worker# Allow installd to publish a binder service and make binder calls. 138*e4a36f41SAndroid Build Coastguard Workerbinder_use(installd) 139*e4a36f41SAndroid Build Coastguard Workeradd_service(installd, installd_service) 140*e4a36f41SAndroid Build Coastguard Workerallow installd dumpstate:fifo_file { getattr write }; 141*e4a36f41SAndroid Build Coastguard Worker 142*e4a36f41SAndroid Build Coastguard Worker# Allow installd to call into the system server so it can check permissions. 143*e4a36f41SAndroid Build Coastguard Workerbinder_call(installd, system_server) 144*e4a36f41SAndroid Build Coastguard Workerallow installd permission_service:service_manager find; 145*e4a36f41SAndroid Build Coastguard Worker 146*e4a36f41SAndroid Build Coastguard Worker# Allow installd to read and write quotas 147*e4a36f41SAndroid Build Coastguard Workerallow installd block_device:dir { search }; 148*e4a36f41SAndroid Build Coastguard Workerallow installd labeledfs:filesystem { quotaget quotamod }; 149*e4a36f41SAndroid Build Coastguard Worker 150*e4a36f41SAndroid Build Coastguard Worker# Allow installd to delete from /data/preloads when trimming data caches 151*e4a36f41SAndroid Build Coastguard Worker# TODO b/34690396 Remove when time-based purge policy for preloads is implemented in system_server 152*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_data_file:file { r_file_perms unlink }; 153*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_data_file:dir { r_dir_perms write remove_name rmdir }; 154*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_media_file:file { r_file_perms unlink }; 155*e4a36f41SAndroid Build Coastguard Workerallow installd preloads_media_file:dir { r_dir_perms write remove_name rmdir }; 156*e4a36f41SAndroid Build Coastguard Worker 157*e4a36f41SAndroid Build Coastguard Worker# Allow installd to read /proc/filesystems 158*e4a36f41SAndroid Build Coastguard Workerallow installd proc_filesystems:file r_file_perms; 159*e4a36f41SAndroid Build Coastguard Worker 160*e4a36f41SAndroid Build Coastguard Worker#add for move app to sd card 161*e4a36f41SAndroid Build Coastguard Workerget_prop(installd, storage_config_prop) 162*e4a36f41SAndroid Build Coastguard Worker 163*e4a36f41SAndroid Build Coastguard Worker# Allow installd to access apps installed on the Incremental File System 164*e4a36f41SAndroid Build Coastguard Worker# Accessing files on the Incremental File System uses fds opened in the context of vold. 165*e4a36f41SAndroid Build Coastguard Workerallow installd vold:fd use; 166*e4a36f41SAndroid Build Coastguard Worker 167*e4a36f41SAndroid Build Coastguard Worker### 168*e4a36f41SAndroid Build Coastguard Worker### Neverallow rules 169*e4a36f41SAndroid Build Coastguard Worker### 170*e4a36f41SAndroid Build Coastguard Worker 171*e4a36f41SAndroid Build Coastguard Worker# only system_server, installd, dumpstate, and servicemanager may interact with installd over binder 172*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server -dumpstate -installd } installd_service:service_manager find; 173*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -system_server -dumpstate -servicemanager } installd:binder call; 174*e4a36f41SAndroid Build Coastguard Workerneverallow installd { 175*e4a36f41SAndroid Build Coastguard Worker domain 176*e4a36f41SAndroid Build Coastguard Worker -system_server 177*e4a36f41SAndroid Build Coastguard Worker -servicemanager 178*e4a36f41SAndroid Build Coastguard Worker userdebug_or_eng(`-su') 179*e4a36f41SAndroid Build Coastguard Worker}:binder call; 180