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