xref: /aosp_15_r20/system/sepolicy/prebuilts/api/29.0/private/apexd.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Workertypeattribute apexd coredomain;
2*e4a36f41SAndroid Build Coastguard Worker
3*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(apexd)
4*e4a36f41SAndroid Build Coastguard Worker
5*e4a36f41SAndroid Build Coastguard Worker# Allow creating, reading and writing of APEX files/dirs in the APEX data dir
6*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_data_file:dir create_dir_perms;
7*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_data_file:file create_file_perms;
8*e4a36f41SAndroid Build Coastguard Worker
9*e4a36f41SAndroid Build Coastguard Worker# Allow creating, reading and writing of APEX files/dirs in the APEX metadata dir
10*e4a36f41SAndroid Build Coastguard Workerallow apexd metadata_file:dir search;
11*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_metadata_file:dir create_dir_perms;
12*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_metadata_file:file create_file_perms;
13*e4a36f41SAndroid Build Coastguard Worker
14*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create loop devices with /dev/loop-control
15*e4a36f41SAndroid Build Coastguard Workerallow apexd loop_control_device:chr_file rw_file_perms;
16*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access loop devices
17*e4a36f41SAndroid Build Coastguard Workerallow apexd loop_device:blk_file rw_file_perms;
18*e4a36f41SAndroid Build Coastguard Workerallowxperm apexd loop_device:blk_file ioctl {
19*e4a36f41SAndroid Build Coastguard Worker  LOOP_GET_STATUS64
20*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_STATUS64
21*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_FD
22*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_BLOCK_SIZE
23*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_DIRECT_IO
24*e4a36f41SAndroid Build Coastguard Worker  LOOP_CLR_FD
25*e4a36f41SAndroid Build Coastguard Worker  BLKFLSBUF
26*e4a36f41SAndroid Build Coastguard Worker};
27*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access /dev/block
28*e4a36f41SAndroid Build Coastguard Workerallow apexd block_device:dir r_dir_perms;
29*e4a36f41SAndroid Build Coastguard Worker
30*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access /dev/block/dm-* (device-mapper entries)
31*e4a36f41SAndroid Build Coastguard Workerallow apexd dm_device:chr_file rw_file_perms;
32*e4a36f41SAndroid Build Coastguard Workerallow apexd dm_device:blk_file rw_file_perms;
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker# sys_admin is required to access the device-mapper and mount
35*e4a36f41SAndroid Build Coastguard Workerallow apexd self:global_capability_class_set sys_admin;
36*e4a36f41SAndroid Build Coastguard Worker
37*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create a mount point in /apex
38*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:dir create_dir_perms;
39*e4a36f41SAndroid Build Coastguard Worker# allow apexd to mount in /apex
40*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:filesystem { mount unmount };
41*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:dir mounton;
42*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create symlinks in /apex
43*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:lnk_file create_file_perms;
44*e4a36f41SAndroid Build Coastguard Worker# allow apexd to unlink apex files in /data/apex/active
45*e4a36f41SAndroid Build Coastguard Worker# note that apexd won't be able to unlink files in /data/app-staging/session_XXXX,
46*e4a36f41SAndroid Build Coastguard Worker# because it doesn't have write permission for staging_data_file object.
47*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file unlink;
48*e4a36f41SAndroid Build Coastguard Worker
49*e4a36f41SAndroid Build Coastguard Worker# allow apexd to read files from /data/app-staging and hardlink them to /data/apex.
50*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:dir r_dir_perms;
51*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file { r_file_perms link };
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Worker# Unmount and mount filesystems
54*e4a36f41SAndroid Build Coastguard Workerallow apexd labeledfs:filesystem { mount unmount };
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Worker# /sys directory tree traversal
57*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:dir search;
58*e4a36f41SAndroid Build Coastguard Worker# Configure read-ahead of dm-verity and loop devices
59*e4a36f41SAndroid Build Coastguard Worker# for dm-X
60*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:dir r_dir_perms;
61*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:file rw_file_perms;
62*e4a36f41SAndroid Build Coastguard Worker# for loopX
63*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:dir r_dir_perms;
64*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:file rw_file_perms;
65*e4a36f41SAndroid Build Coastguard Worker
66*e4a36f41SAndroid Build Coastguard Worker# Spawning a libbinder thread results in a dac_override deny,
67*e4a36f41SAndroid Build Coastguard Worker# /dev/cpuset/tasks is owned by system.
68*e4a36f41SAndroid Build Coastguard Worker#
69*e4a36f41SAndroid Build Coastguard Worker# See b/35323867#comment3
70*e4a36f41SAndroid Build Coastguard Workerdontaudit apexd self:global_capability_class_set { dac_override dac_read_search };
71*e4a36f41SAndroid Build Coastguard Worker
72*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to log to the kernel.
73*e4a36f41SAndroid Build Coastguard Workerallow apexd kmsg_device:chr_file w_file_perms;
74*e4a36f41SAndroid Build Coastguard Worker
75*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to reboot device. Required for rollbacks of apexes that are
76*e4a36f41SAndroid Build Coastguard Worker# not covered by rollback manager.
77*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, powerctl_prop)
78*e4a36f41SAndroid Build Coastguard Worker
79*e4a36f41SAndroid Build Coastguard Worker# Find the vold service, and call into vold to manage FS checkpoints
80*e4a36f41SAndroid Build Coastguard Workerallow apexd vold_service:service_manager find;
81*e4a36f41SAndroid Build Coastguard Workerbinder_call(apexd, vold)
82*e4a36f41SAndroid Build Coastguard Worker
83*e4a36f41SAndroid Build Coastguard Worker# Apex pre- & post-install permission.
84*e4a36f41SAndroid Build Coastguard Worker
85*e4a36f41SAndroid Build Coastguard Worker# Allow self-execute for the fork mount helper.
86*e4a36f41SAndroid Build Coastguard Workerallow apexd apexd_exec:file execute_no_trans;
87*e4a36f41SAndroid Build Coastguard Worker
88*e4a36f41SAndroid Build Coastguard Worker# Unshare and make / private so that hooks cannot influence the
89*e4a36f41SAndroid Build Coastguard Worker# running system.
90*e4a36f41SAndroid Build Coastguard Workerallow apexd rootfs:dir mounton;
91*e4a36f41SAndroid Build Coastguard Worker
92*e4a36f41SAndroid Build Coastguard Worker# Allow to execute shell for pre- and postinstall scripts. A transition
93*e4a36f41SAndroid Build Coastguard Worker# rule is required, thus restricted to execute and not execute_no_trans.
94*e4a36f41SAndroid Build Coastguard Workerallow apexd shell_exec:file { r_file_perms execute };
95*e4a36f41SAndroid Build Coastguard Worker
96*e4a36f41SAndroid Build Coastguard Worker# apexd is using bootstrap bionic
97*e4a36f41SAndroid Build Coastguard Workerallow apexd system_bootstrap_lib_file:dir r_dir_perms;
98*e4a36f41SAndroid Build Coastguard Workerallow apexd system_bootstrap_lib_file:file { execute read open getattr map };
99*e4a36f41SAndroid Build Coastguard Worker
100*e4a36f41SAndroid Build Coastguard Worker# Allow transition to ART APEX preinstall domain.
101*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(apexd, art_apex_preinstall_exec, art_apex_preinstall)
102*e4a36f41SAndroid Build Coastguard Worker# Allow transition to ART APEX postinstall domain.
103*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(apexd, art_apex_postinstall_exec, art_apex_postinstall)
104*e4a36f41SAndroid Build Coastguard Worker
105*e4a36f41SAndroid Build Coastguard Worker# Allow transition to test APEX preinstall domain.
106*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
107*e4a36f41SAndroid Build Coastguard Worker  domain_auto_trans(apexd, apex_test_prepostinstall_exec, apex_test_prepostinstall)
108*e4a36f41SAndroid Build Coastguard Worker')
109*e4a36f41SAndroid Build Coastguard Worker
110*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_data_file:dir no_w_dir_perms;
111*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_metadata_file:dir no_w_dir_perms;
112*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_data_file:file no_w_file_perms;
113*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_metadata_file:file no_w_file_perms;
114*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd } apex_mnt_dir:lnk_file no_w_file_perms;
115