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