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