xref: /aosp_15_r20/system/sepolicy/prebuilts/api/202404/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# Allow relabeling file created in /data/apex/decompressed
9*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_data_file:file relabelfrom;
10*e4a36f41SAndroid Build Coastguard Worker
11*e4a36f41SAndroid Build Coastguard Worker# Allow creating, reading and writing of APEX files/dirs in the APEX metadata dir
12*e4a36f41SAndroid Build Coastguard Workerallow apexd metadata_file:dir search;
13*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_metadata_file:dir create_dir_perms;
14*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_metadata_file:file create_file_perms;
15*e4a36f41SAndroid Build Coastguard Worker
16*e4a36f41SAndroid Build Coastguard Worker# Allow reserving space on /data/apex/ota_reserved for apex decompression
17*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_ota_reserved_file:dir create_dir_perms;
18*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_ota_reserved_file:file create_file_perms;
19*e4a36f41SAndroid Build Coastguard Worker
20*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to create files and directories for snapshots of apex data
21*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_data_file_type:dir { create_dir_perms relabelto };
22*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_data_file_type:file { create_file_perms relabelto };
23*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_module_data_file:dir { create_dir_perms relabelfrom };
24*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_module_data_file:file { create_file_perms relabelfrom };
25*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_rollback_data_file:dir create_dir_perms;
26*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_rollback_data_file:file create_file_perms;
27*e4a36f41SAndroid Build Coastguard Worker
28*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read /data/misc_de and the directories under it, in order to
29*e4a36f41SAndroid Build Coastguard Worker# snapshot and restore apex data for all users.
30*e4a36f41SAndroid Build Coastguard Workerallow apexd {
31*e4a36f41SAndroid Build Coastguard Worker    system_userdir_file
32*e4a36f41SAndroid Build Coastguard Worker    system_data_file
33*e4a36f41SAndroid Build Coastguard Worker}:dir r_dir_perms;
34*e4a36f41SAndroid Build Coastguard Worker
35*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create loop devices with /dev/loop-control
36*e4a36f41SAndroid Build Coastguard Workerallow apexd loop_control_device:chr_file rw_file_perms;
37*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access loop devices
38*e4a36f41SAndroid Build Coastguard Workerallow apexd loop_device:blk_file rw_file_perms;
39*e4a36f41SAndroid Build Coastguard Workerallowxperm apexd loop_device:blk_file ioctl {
40*e4a36f41SAndroid Build Coastguard Worker  LOOP_GET_STATUS64
41*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_STATUS64
42*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_FD
43*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_BLOCK_SIZE
44*e4a36f41SAndroid Build Coastguard Worker  LOOP_SET_DIRECT_IO
45*e4a36f41SAndroid Build Coastguard Worker  LOOP_CLR_FD
46*e4a36f41SAndroid Build Coastguard Worker  BLKFLSBUF
47*e4a36f41SAndroid Build Coastguard Worker  LOOP_CONFIGURE
48*e4a36f41SAndroid Build Coastguard Worker};
49*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to access /dev/block
50*e4a36f41SAndroid Build Coastguard Workerallow apexd dev_type:dir r_dir_perms;
51*e4a36f41SAndroid Build Coastguard Workerallow apexd dev_type:blk_file getattr;
52*e4a36f41SAndroid Build Coastguard Worker
53*e4a36f41SAndroid Build Coastguard Worker#allow apexd to access virtual disks
54*e4a36f41SAndroid Build Coastguard Workerallow apexd vd_device:blk_file r_file_perms;
55*e4a36f41SAndroid Build Coastguard Worker
56*e4a36f41SAndroid Build Coastguard Worker# allow apexd to access /dev/block/dm-* (device-mapper entries)
57*e4a36f41SAndroid Build Coastguard Workerallow apexd dm_device:chr_file rw_file_perms;
58*e4a36f41SAndroid Build Coastguard Workerallow apexd dm_device:blk_file rw_file_perms;
59*e4a36f41SAndroid Build Coastguard Worker
60*e4a36f41SAndroid Build Coastguard Worker# sys_admin is required to access the device-mapper and mount
61*e4a36f41SAndroid Build Coastguard Worker# dac_override, chown, and fowner are needed for snapshot and restore
62*e4a36f41SAndroid Build Coastguard Workerallow apexd self:global_capability_class_set { sys_admin chown dac_override dac_read_search fowner };
63*e4a36f41SAndroid Build Coastguard Worker
64*e4a36f41SAndroid Build Coastguard Worker# Note: fsetid is deliberately not included above. fsetid checks are
65*e4a36f41SAndroid Build Coastguard Worker# triggered by chmod on a directory or file owned by a group other
66*e4a36f41SAndroid Build Coastguard Worker# than one of the groups assigned to the current process to see if
67*e4a36f41SAndroid Build Coastguard Worker# the setgid bit should be cleared, regardless of whether the setgid
68*e4a36f41SAndroid Build Coastguard Worker# bit was even set.  We do not appear to truly need this capability
69*e4a36f41SAndroid Build Coastguard Worker# for apexd to operate.
70*e4a36f41SAndroid Build Coastguard Workerdontaudit apexd self:global_capability_class_set fsetid;
71*e4a36f41SAndroid Build Coastguard Worker
72*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create a mount point in /apex
73*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:dir create_dir_perms;
74*e4a36f41SAndroid Build Coastguard Worker# allow apexd to mount in /apex
75*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:filesystem { mount unmount };
76*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:dir mounton;
77*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create symlinks in /apex
78*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:lnk_file create_file_perms;
79*e4a36f41SAndroid Build Coastguard Worker# allow apexd to create /apex/apex-info-list.xml and relabel to apex_info_file
80*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_mnt_dir:file { create_file_perms relabelfrom mounton };
81*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_info_file:file relabelto;
82*e4a36f41SAndroid Build Coastguard Worker# apexd needs to update /apex/apex-info-list.xml after non-staged APEX update.
83*e4a36f41SAndroid Build Coastguard Workerallow apexd apex_info_file:file rw_file_perms;
84*e4a36f41SAndroid Build Coastguard Worker
85*e4a36f41SAndroid Build Coastguard Worker# allow apexd to unlink apex files in /data/apex/active
86*e4a36f41SAndroid Build Coastguard Worker# note that apexd won't be able to unlink files in /data/app-staging/session_XXXX,
87*e4a36f41SAndroid Build Coastguard Worker# because it doesn't have write permission for staging_data_file object.
88*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file unlink;
89*e4a36f41SAndroid Build Coastguard Worker
90*e4a36f41SAndroid Build Coastguard Worker# allow apexd to read files from /data/app-staging and hardlink them to /data/apex.
91*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:dir r_dir_perms;
92*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file { r_file_perms link };
93*e4a36f41SAndroid Build Coastguard Worker# # Allow relabeling file created in /data/apex/decompressed
94*e4a36f41SAndroid Build Coastguard Workerallow apexd staging_data_file:file relabelto;
95*e4a36f41SAndroid Build Coastguard Worker
96*e4a36f41SAndroid Build Coastguard Worker# allow apexd to read files from /vendor/apex
97*e4a36f41SAndroid Build Coastguard Workerr_dir_file(apexd, vendor_apex_file)
98*e4a36f41SAndroid Build Coastguard Workerr_dir_file(apexd, vendor_apex_metadata_file)
99*e4a36f41SAndroid Build Coastguard Worker
100*e4a36f41SAndroid Build Coastguard Worker# Unmount and mount filesystems
101*e4a36f41SAndroid Build Coastguard Workerallow apexd labeledfs:filesystem { mount unmount };
102*e4a36f41SAndroid Build Coastguard Worker
103*e4a36f41SAndroid Build Coastguard Worker# /sys directory tree traversal
104*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:dir search;
105*e4a36f41SAndroid Build Coastguard Worker# Access to /sys/class/block
106*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:dir r_dir_perms;
107*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_type:file r_file_perms;
108*e4a36f41SAndroid Build Coastguard Worker# Configure read-ahead of dm-verity and loop devices
109*e4a36f41SAndroid Build Coastguard Worker# for dm-X
110*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:dir r_dir_perms;
111*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_dm:file rw_file_perms;
112*e4a36f41SAndroid Build Coastguard Worker# for loopX
113*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:dir r_dir_perms;
114*e4a36f41SAndroid Build Coastguard Workerallow apexd sysfs_loop:file rw_file_perms;
115*e4a36f41SAndroid Build Coastguard Worker
116*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to log to the kernel.
117*e4a36f41SAndroid Build Coastguard Workerallow apexd kmsg_device:chr_file w_file_perms;
118*e4a36f41SAndroid Build Coastguard Worker
119*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to reboot device. Required for rollbacks of apexes that are
120*e4a36f41SAndroid Build Coastguard Worker# not covered by rollback manager.
121*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, powerctl_prop)
122*e4a36f41SAndroid Build Coastguard Worker
123*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to stop itself
124*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, ctl_apexd_prop)
125*e4a36f41SAndroid Build Coastguard Worker
126*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to send control messages to load/unload apex from init
127*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, ctl_apex_load_prop)
128*e4a36f41SAndroid Build Coastguard Worker
129*e4a36f41SAndroid Build Coastguard Worker# Find the vold service, and call into vold to manage FS checkpoints
130*e4a36f41SAndroid Build Coastguard Workerallow apexd vold_service:service_manager find;
131*e4a36f41SAndroid Build Coastguard Workerbinder_call(apexd, vold)
132*e4a36f41SAndroid Build Coastguard Worker
133*e4a36f41SAndroid Build Coastguard Worker# apexd is using bootstrap bionic
134*e4a36f41SAndroid Build Coastguard Workeruse_bootstrap_libs(apexd)
135*e4a36f41SAndroid Build Coastguard Worker
136*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to be invoked with logwrapper from init during userspace reboot.
137*e4a36f41SAndroid Build Coastguard Workerallow apexd devpts:chr_file { read write };
138*e4a36f41SAndroid Build Coastguard Worker
139*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to create pts files via logwrap_fork_exec for its own use, to pass to
140*e4a36f41SAndroid Build Coastguard Worker# other processes
141*e4a36f41SAndroid Build Coastguard Workercreate_pty(apexd)
142*e4a36f41SAndroid Build Coastguard Worker
143*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read file contexts when performing restorecon of snapshots.
144*e4a36f41SAndroid Build Coastguard Workerallow apexd file_contexts_file:file r_file_perms;
145*e4a36f41SAndroid Build Coastguard Worker
146*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to execute toybox for snapshot & restore
147*e4a36f41SAndroid Build Coastguard Workerallow apexd toolbox_exec:file rx_file_perms;
148*e4a36f41SAndroid Build Coastguard Worker
149*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to release compressed blocks in case /data is f2fs-compressed fs.
150*e4a36f41SAndroid Build Coastguard Workerallowxperm apexd staging_data_file:file ioctl {
151*e4a36f41SAndroid Build Coastguard Worker  FS_IOC_GETFLAGS
152*e4a36f41SAndroid Build Coastguard Worker  F2FS_IOC_RELEASE_COMPRESS_BLOCKS
153*e4a36f41SAndroid Build Coastguard Worker};
154*e4a36f41SAndroid Build Coastguard Worker
155*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read ro.cold_boot_done prop.
156*e4a36f41SAndroid Build Coastguard Worker# apexd uses it to decide whether it needs to keep retrying polling for loop device.
157*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, cold_boot_done_prop)
158*e4a36f41SAndroid Build Coastguard Worker
159*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read per-device configuration properties.
160*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, apexd_config_prop)
161*e4a36f41SAndroid Build Coastguard Worker
162*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read apex selection properties.
163*e4a36f41SAndroid Build Coastguard Worker# These are used to choose between multi-installed APEXes at activation time.
164*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, apexd_select_prop)
165*e4a36f41SAndroid Build Coastguard Worker#
166*e4a36f41SAndroid Build Coastguard Worker# Allow apexd to read apexd_payload_metadata_prop
167*e4a36f41SAndroid Build Coastguard Workerget_prop(apexd, apexd_payload_metadata_prop)
168*e4a36f41SAndroid Build Coastguard Worker
169*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_data_file:dir no_w_dir_perms;
170*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apex_metadata_file:dir no_w_dir_perms;
171*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_data_file:file no_w_file_perms;
172*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -kernel } apex_metadata_file:file no_w_file_perms;
173*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd } apex_mnt_dir:lnk_file no_w_file_perms;
174*e4a36f41SAndroid Build Coastguard Worker
175*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:dir no_w_dir_perms;
176*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_module_data_file:file no_w_file_perms;
177*e4a36f41SAndroid Build Coastguard Worker
178*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:dir no_w_dir_perms;
179*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -vold_prepare_subdirs } apex_rollback_data_file:file no_w_file_perms;
180*e4a36f41SAndroid Build Coastguard Worker
181*e4a36f41SAndroid Build Coastguard Worker# only apexd can set apexd sysprop
182*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, apexd_prop)
183*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init } apexd_prop:property_service set;
184*e4a36f41SAndroid Build Coastguard Worker
185*e4a36f41SAndroid Build Coastguard Worker# only apexd can write apex-info-list.xml
186*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd } apex_info_file:file no_w_file_perms;
187*e4a36f41SAndroid Build Coastguard Worker
188*e4a36f41SAndroid Build Coastguard Worker# Only apexd and init should be allowed to manage /apex mounts
189*e4a36f41SAndroid Build Coastguard Worker# A note on otapreopt_chroot. It used to mount APEXes during postainstall stage of A/B OTAs,
190*e4a36f41SAndroid Build Coastguard Worker# but starting from S it just calls into apexd to prepare /apex for otapreoprt. Once the sepolicies
191*e4a36f41SAndroid Build Coastguard Worker# around otapreopt_chroot are cleaned up we should be able to remove it from the lists below.
192*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -otapreopt_chroot } apex_mnt_dir:filesystem { mount unmount };
193*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -apexd -init -otapreopt_chroot } apex_mnt_dir:dir { mounton };
194*e4a36f41SAndroid Build Coastguard Worker
195*e4a36f41SAndroid Build Coastguard Worker# Allow for use in postinstall
196*e4a36f41SAndroid Build Coastguard Workerallow apexd otapreopt_chroot:fd use;
197*e4a36f41SAndroid Build Coastguard Workerallow apexd postinstall_apex_mnt_dir:dir { create_dir_perms mounton };
198*e4a36f41SAndroid Build Coastguard Workerallow apexd postinstall_apex_mnt_dir:file { create_file_perms relabelfrom };
199*e4a36f41SAndroid Build Coastguard Workerallow apexd postinstall_apex_mnt_dir:lnk_file create;
200*e4a36f41SAndroid Build Coastguard Workerallow apexd proc_filesystems:file r_file_perms;
201*e4a36f41SAndroid Build Coastguard Worker
202*e4a36f41SAndroid Build Coastguard Worker# Allow calling derive_classpath to gather BCP information for staged sessions
203*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(apexd, derive_classpath_exec, apexd_derive_classpath);
204*e4a36f41SAndroid Build Coastguard Worker
205*e4a36f41SAndroid Build Coastguard Worker# Allow set apex ready property
206*e4a36f41SAndroid Build Coastguard Workerset_prop(apexd, apex_ready_prop)
207