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