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