xref: /aosp_15_r20/system/sepolicy/prebuilts/api/30.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 files and directories for snapshots of apex data
15*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_permission_data_file:dir { create_dir_perms relabelto };
16*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_permission_data_file:file { create_file_perms relabelto };
17*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_module_data_file:dir { create_dir_perms relabelfrom };
18*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_module_data_file:file { create_file_perms relabelfrom };
19*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_rollback_data_file:dir create_dir_perms;
20*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_rollback_data_file:file create_file_perms;
21*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_wifi_data_file:dir { create_dir_perms relabelto };
22*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_wifi_data_file:file { create_file_perms relabelto };
23*e4a36f41SAndroid Build Coastguard Worker
24*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read directories under /data/misc_de in order to snapshot and
25*e4a36f41SAndroid Build Coastguard Worker# restore apex data for all users.
26*e4a36f41SAndroid Build Coastguard Workerallow apexd system_data_file:dir r_dir_perms;
27*e4a36f41SAndroid Build Coastguard Worker
28*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create loop devices with /dev/loop-control
29*e4a36f41SAndroid Build Coastguard Workerallow apexd loop_control_device:chr_file rw_file_perms;
30*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access loop devices
31*e4a36f41SAndroid Build Coastguard Workerallow apexd loop_device:blk_file rw_file_perms;
32*e4a36f41SAndroid Build Coastguard Workerallowxperm apexd loop_device:blk_file ioctl {
33*e4a36f41SAndroid Build Coastguard Worker  LOOP_GET_STATUS64
34*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_STATUS64
35*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_FD
36*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_BLOCK_SIZE
37*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_DIRECT_IO
38*e4a36f41SAndroid Build Coastguard Worker  LOOP_CLR_FD
39*e4a36f41SAndroid Build Coastguard Worker  BLKFLSBUF
40*e4a36f41SAndroid Build Coastguard Worker};
41*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access /dev/block
42*e4a36f41SAndroid Build Coastguard Workerallow apexd block_device:dir r_dir_perms;
43*e4a36f41SAndroid Build Coastguard Worker
44*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access /dev/block/dm-* (device-mapper entries)
45*e4a36f41SAndroid Build Coastguard Workerallow apexd dm_device:chr_file rw_file_perms;
46*e4a36f41SAndroid Build Coastguard Workerallow apexd dm_device:blk_file rw_file_perms;
47*e4a36f41SAndroid Build Coastguard Worker
48*e4a36f41SAndroid Build Coastguard Worker# sys_admin is required to access the device-mapper and mount
49*e4a36f41SAndroid Build Coastguard Worker# dac_override, chown, and fowner are needed for snapshot and restore
50*e4a36f41SAndroid Build Coastguard Workerallow apexd self:global_capability_class_set { sys_admin chown dac_override dac_read_search fowner };
51*e4a36f41SAndroid Build Coastguard Worker
52*e4a36f41SAndroid Build Coastguard Worker# Note: fsetid is deliberately not included above. fsetid checks are
53*e4a36f41SAndroid Build Coastguard Worker# triggered by chmod on a directory or file owned by a group other
54*e4a36f41SAndroid Build Coastguard Worker# than one of the groups assigned to the current process to see if
55*e4a36f41SAndroid Build Coastguard Worker# the setgid bit should be cleared, regardless of whether the setgid
56*e4a36f41SAndroid Build Coastguard Worker# bit was even set.  We do not appear to truly need this capability
57*e4a36f41SAndroid Build Coastguard Worker# for apexd to operate.
58*e4a36f41SAndroid Build Coastguard Workerdontaudit apexd self:global_capability_class_set fsetid;
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create a mount point in /apex
61*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:dir create_dir_perms;
62*e4a36f41SAndroid Build Coastguard Worker# allow apexd to mount in /apex
63*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:filesystem { mount unmount };
64*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:dir mounton;
65*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create symlinks in /apex
66*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:lnk_file create_file_perms;
67*e4a36f41SAndroid Build Coastguard Worker# allow apexd to unlink apex files in /data/apex/active
68*e4a36f41SAndroid Build Coastguard Worker# note that apexd won't be able to unlink files in /data/app-staging/session_XXXX,
69*e4a36f41SAndroid Build Coastguard Worker# because it doesn't have write permission for staging_data_file object.
70*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file unlink;
71*e4a36f41SAndroid Build Coastguard Worker
72*e4a36f41SAndroid Build Coastguard Worker# allow apexd to read files from /data/app-staging and hardlink them to /data/apex.
73*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:dir r_dir_perms;
74*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file { r_file_perms link };
75*e4a36f41SAndroid Build Coastguard Worker
76*e4a36f41SAndroid Build Coastguard Worker# allow apexd to read files from /vendor/apex
77*e4a36f41SAndroid Build Coastguard Workerallow apexd vendor_apex_file:dir r_dir_perms;
78*e4a36f41SAndroid Build Coastguard Workerallow apexd vendor_apex_file:file r_file_perms;
79*e4a36f41SAndroid Build Coastguard Worker
80*e4a36f41SAndroid Build Coastguard Worker# Unmount and mount filesystems
81*e4a36f41SAndroid Build Coastguard Workerallow apexd labeledfs:filesystem { mount unmount };
82*e4a36f41SAndroid Build Coastguard Worker
83*e4a36f41SAndroid Build Coastguard Worker# /sys directory tree traversal
84*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:dir search;
85*e4a36f41SAndroid Build Coastguard Worker# Configure read-ahead of dm-verity and loop devices
86*e4a36f41SAndroid Build Coastguard Worker# for dm-X
87*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:dir r_dir_perms;
88*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:file rw_file_perms;
89*e4a36f41SAndroid Build Coastguard Worker# for loopX
90*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:dir r_dir_perms;
91*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:file rw_file_perms;
92*e4a36f41SAndroid Build Coastguard Worker
93*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to log to the kernel.
94*e4a36f41SAndroid Build Coastguard Workerallow apexd kmsg_device:chr_file w_file_perms;
95*e4a36f41SAndroid Build Coastguard Worker
96*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to reboot device. Required for rollbacks of apexes that are
97*e4a36f41SAndroid Build Coastguard Worker# not covered by rollback manager.
98*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, powerctl_prop)
99*e4a36f41SAndroid Build Coastguard Worker
100*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to stop itself
101*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, ctl_apexd_prop)
102*e4a36f41SAndroid Build Coastguard Worker
103*e4a36f41SAndroid Build Coastguard Worker# Find the vold service, and call into vold to manage FS checkpoints
104*e4a36f41SAndroid Build Coastguard Workerallow apexd vold_service:service_manager find;
105*e4a36f41SAndroid Build Coastguard Workerbinder_call(apexd, vold)
106*e4a36f41SAndroid Build Coastguard Worker
107*e4a36f41SAndroid Build Coastguard Worker# Apex pre- & post-install permission.
108*e4a36f41SAndroid Build Coastguard Worker
109*e4a36f41SAndroid Build Coastguard Worker# Allow self-execute for the fork mount helper.
110*e4a36f41SAndroid Build Coastguard Workerallow apexd apexd_exec:file execute_no_trans;
111*e4a36f41SAndroid Build Coastguard Worker
112*e4a36f41SAndroid Build Coastguard Worker# Unshare and make / private so that hooks cannot influence the
113*e4a36f41SAndroid Build Coastguard Worker# running system.
114*e4a36f41SAndroid Build Coastguard Workerallow apexd rootfs:dir mounton;
115*e4a36f41SAndroid Build Coastguard Worker
116*e4a36f41SAndroid Build Coastguard Worker# Allow to execute shell for pre- and postinstall scripts. A transition
117*e4a36f41SAndroid Build Coastguard Worker# rule is required, thus restricted to execute and not execute_no_trans.
118*e4a36f41SAndroid Build Coastguard Workerallow apexd shell_exec:file { r_file_perms execute };
119*e4a36f41SAndroid Build Coastguard Worker
120*e4a36f41SAndroid Build Coastguard Worker# apexd is using bootstrap bionic
121*e4a36f41SAndroid Build Coastguard Workerallow apexd system_bootstrap_lib_file:dir r_dir_perms;
122*e4a36f41SAndroid Build Coastguard Workerallow apexd system_bootstrap_lib_file:file { execute read open getattr map };
123*e4a36f41SAndroid Build Coastguard Worker
124*e4a36f41SAndroid Build Coastguard Worker# Allow transition to ART APEX preinstall domain.
125*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(apexd, art_apex_preinstall_exec, art_apex_preinstall)
126*e4a36f41SAndroid Build Coastguard Worker# Allow transition to ART APEX postinstall domain.
127*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(apexd, art_apex_postinstall_exec, art_apex_postinstall)
128*e4a36f41SAndroid Build Coastguard Worker
129*e4a36f41SAndroid Build Coastguard Worker# Allow transition to test APEX preinstall domain.
130*e4a36f41SAndroid Build Coastguard Workeruserdebug_or_eng(`
131*e4a36f41SAndroid Build Coastguard Worker  domain_auto_trans(apexd, apex_test_prepostinstall_exec, apex_test_prepostinstall)
132*e4a36f41SAndroid Build Coastguard Worker')
133*e4a36f41SAndroid Build Coastguard Worker
134*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to be invoked with logwrapper from init during userspace reboot.
135*e4a36f41SAndroid Build Coastguard Workerallow apexd devpts:chr_file { read write };
136*e4a36f41SAndroid Build Coastguard Worker
137*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to create pts files via logwrap_fork_exec for its own use, to pass to
138*e4a36f41SAndroid Build Coastguard Worker# other processes
139*e4a36f41SAndroid Build Coastguard Workercreate_pty(apexd)
140*e4a36f41SAndroid Build Coastguard Worker
141*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read file contexts when performing restorecon of snapshots.
142*e4a36f41SAndroid Build Coastguard Workerallow apexd file_contexts_file:file r_file_perms;
143*e4a36f41SAndroid Build Coastguard Worker
144*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to execute toybox for snapshot & restore
145*e4a36f41SAndroid Build Coastguard Workerallow apexd toolbox_exec:file rx_file_perms;
146*e4a36f41SAndroid Build Coastguard Worker
147*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_data_file:dir no_w_dir_perms;
148*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_metadata_file:dir no_w_dir_perms;
149*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_data_file:file no_w_file_perms;
150*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_metadata_file:file no_w_file_perms;
151*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd } apex_mnt_dir:lnk_file no_w_file_perms;
152*e4a36f41SAndroid Build Coastguard Worker
153*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:dir no_w_dir_perms;
154*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:file no_w_file_perms;
155*e4a36f41SAndroid Build Coastguard Worker
156*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:dir no_w_dir_perms;
157*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:file no_w_file_perms;
158