1# installer daemon
2type installd, domain;
3type installd_exec, exec_type, file_type;
4
5init_daemon_domain(installd)
6typeattribute installd mlstrustedsubject;
7allow installd self:capability { chown dac_override fowner fsetid setgid setuid };
8allow installd apk_data_file:file rename;
9allow installd apk_data_file:dir create_dir_perms;
10allow installd apk_data_file:lnk_file { create read unlink };
11allow installd asec_apk_file:file r_file_perms;
12allow installd apk_tmp_file:file r_file_perms;
13allow installd oemfs:dir r_dir_perms;
14allow installd oemfs:file r_file_perms;
15allow installd system_file:file x_file_perms;
16allow installd cgroup:dir create_dir_perms;
17# Check validity of SELinux context before use.
18selinux_check_context(installd)
19# Read /seapp_contexts and /data/security/seapp_contexts
20security_access_policy(installd)
21
22# Search /data/app-asec and stat files in it.
23allow installd asec_image_file:dir search;
24allow installd asec_image_file:file getattr;
25
26# Create /data/user and /data/user/0 if necessary.
27# Also required to initially create /data/data subdirectories
28# and lib symlinks before the setfilecon call.  May want to
29# move symlink creation after setfilecon in installd.
30allow installd system_data_file:dir create_dir_perms;
31allow installd system_data_file:lnk_file { create setattr unlink };
32
33# Upgrade /data/media for multi-user if necessary.
34allow installd media_rw_data_file:dir create_dir_perms;
35allow installd media_rw_data_file:file { getattr unlink };
36# restorecon new /data/media directory.
37allow installd system_data_file:dir relabelfrom;
38allow installd media_rw_data_file:dir relabelto;
39
40# Upgrade /data/misc/keychain for multi-user if necessary.
41allow installd misc_user_data_file:dir create_dir_perms;
42allow installd misc_user_data_file:file create_file_perms;
43allow installd keychain_data_file:dir create_dir_perms;
44allow installd keychain_data_file:file {r_file_perms unlink};
45
46# Create /data/.layout_version.* file
47type_transition installd system_data_file:file install_data_file;
48allow installd install_data_file:file create_file_perms;
49
50# Create files under /data/dalvik-cache.
51allow installd dalvikcache_data_file:dir create_dir_perms;
52allow installd dalvikcache_data_file:file create_file_perms;
53
54# Create /data/dalvik-cache/profiles.
55allow installd dalvikcache_profiles_data_file:dir rw_dir_perms;
56allow installd dalvikcache_profiles_data_file:file create_file_perms;
57
58# Create files under /data/resource-cache.
59allow installd resourcecache_data_file:dir rw_dir_perms;
60allow installd resourcecache_data_file:file create_file_perms;
61
62# Run dex2oat in its own sandbox.
63domain_auto_trans(installd, dex2oat_exec, dex2oat)
64# dex2oat needs LD_PRELOAD, passed down from init
65# https://android-review.googlesource.com/94851
66allow installd dex2oat:process noatsecure;
67
68# Upgrade from unlabeled userdata.
69# Just need enough to remove and/or relabel it.
70allow installd unlabeled:dir { getattr search relabelfrom rw_dir_perms rmdir };
71allow installd unlabeled:notdevfile_class_set { getattr relabelfrom rename unlink setattr };
72# Read pkg.apk file for input during dexopt.
73allow installd unlabeled:file r_file_perms;
74
75# Upgrade from before system_app_data_file was used for system UID apps.
76# Just need enough to relabel it and to unlink removed package files.
77# Directory access covered by earlier rule above.
78allow installd system_data_file:notdevfile_class_set { getattr relabelfrom unlink };
79
80# Manage /data/data subdirectories, including initially labeling them
81# upon creation via setfilecon or running restorecon_recursive,
82# setting owner/mode, creating symlinks within them, and deleting them
83# upon package uninstall.
84# Types extracted from seapp_contexts type= fields.
85allow installd { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:dir { create_dir_perms relabelfrom relabelto };
86allow installd { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:lnk_file { create setattr getattr unlink rename relabelfrom relabelto };
87allow installd { system_app_data_file bluetooth_data_file nfc_data_file radio_data_file shell_data_file app_data_file }:{ file sock_file fifo_file } { getattr unlink rename relabelfrom relabelto setattr };
88