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