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