xref: /aosp_15_r20/system/sepolicy/private/dexopt_chroot_setup.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# A service that sets up the chroot environment for Pre-reboot Dexopt.
2*e4a36f41SAndroid Build Coastguard Workertype dexopt_chroot_setup, domain, coredomain;
3*e4a36f41SAndroid Build Coastguard Workertype dexopt_chroot_setup_exec, system_file_type, exec_type, file_type;
4*e4a36f41SAndroid Build Coastguard Workertype dexopt_chroot_setup_tmpfs, file_type;
5*e4a36f41SAndroid Build Coastguard Worker
6*e4a36f41SAndroid Build Coastguard Worker# Allow dexopt_chroot_setup to publish a binder service and make binder calls.
7*e4a36f41SAndroid Build Coastguard Workerbinder_use(dexopt_chroot_setup)
8*e4a36f41SAndroid Build Coastguard Workeradd_service(dexopt_chroot_setup, dexopt_chroot_setup_service)
9*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup dumpstate:fifo_file { getattr write };
10*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup dumpstate:fd use;
11*e4a36f41SAndroid Build Coastguard Worker
12*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(dexopt_chroot_setup)
13*e4a36f41SAndroid Build Coastguard Worker
14*e4a36f41SAndroid Build Coastguard Worker# Use tmpfs_domain() which will give tmpfs files created by dexopt_chroot_setup
15*e4a36f41SAndroid Build Coastguard Worker# their own label, which differs from other labels created by other processes.
16*e4a36f41SAndroid Build Coastguard Worker# This allows to distinguish in policy files created by dexopt_chroot_setup vs
17*e4a36f41SAndroid Build Coastguard Worker# other processes.
18*e4a36f41SAndroid Build Coastguard Workertmpfs_domain(dexopt_chroot_setup)
19*e4a36f41SAndroid Build Coastguard Worker
20*e4a36f41SAndroid Build Coastguard Worker# libart (mark_compact.cc) has some intialization code that touches the cache
21*e4a36f41SAndroid Build Coastguard Worker# info file and userfaultfd.
22*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup apex_module_data_file:dir { getattr search };
23*e4a36f41SAndroid Build Coastguard Workerr_dir_file(dexopt_chroot_setup, apex_art_data_file)
24*e4a36f41SAndroid Build Coastguard Workeruserfaultfd_use(dexopt_chroot_setup)
25*e4a36f41SAndroid Build Coastguard Worker
26*e4a36f41SAndroid Build Coastguard Worker# Allow getting root capabilities to bypass permission checks.
27*e4a36f41SAndroid Build Coastguard Worker# - "sys_admin" is for performing mount and umount.
28*e4a36f41SAndroid Build Coastguard Worker# - "sys_chroot" is for performing chroot.
29*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup self:global_capability_class_set { sys_admin sys_chroot };
30*e4a36f41SAndroid Build Coastguard Worker
31*e4a36f41SAndroid Build Coastguard Worker# Allow managing its own files.
32*e4a36f41SAndroid Build Coastguard Worker# The root of the temp dir that dexopt_chroot_setup uses is labeled
33*e4a36f41SAndroid Build Coastguard Worker# pre_reboot_dexopt_file.
34*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup pre_reboot_dexopt_file:dir create_dir_perms;
35*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup pre_reboot_dexopt_file:file create_file_perms;
36*e4a36f41SAndroid Build Coastguard Worker
37*e4a36f41SAndroid Build Coastguard Worker# Allow accessing /proc/filesystems.
38*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup proc_filesystems:file r_file_perms;
39*e4a36f41SAndroid Build Coastguard Worker
40*e4a36f41SAndroid Build Coastguard Worker# Allow accessing block devices (/dev/block/...).
41*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup block_device:dir { getattr search };
42*e4a36f41SAndroid Build Coastguard Worker
43*e4a36f41SAndroid Build Coastguard Worker# Allow mounting file systems, to create a chroot environment.
44*e4a36f41SAndroid Build Coastguard Worker# We recursively bind-mount directories under /data, /mnt/expand, /proc, /sys,
45*e4a36f41SAndroid Build Coastguard Worker# and /dev. We need some of them (e.g., incremental-fs directories for
46*e4a36f41SAndroid Build Coastguard Worker# incremental apps in /data; /dev/cpuctl and /dev/blkio for task profiles), but
47*e4a36f41SAndroid Build Coastguard Worker# not necessarily all of them. However, to avoid random crashes and silent
48*e4a36f41SAndroid Build Coastguard Worker# fallbacks, we bind-mount all of them. Therefore, we need access to many of the
49*e4a36f41SAndroid Build Coastguard Worker# fstypes.
50*e4a36f41SAndroid Build Coastguard Worker
51*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup {
52*e4a36f41SAndroid Build Coastguard Worker  apex_mnt_dir
53*e4a36f41SAndroid Build Coastguard Worker  apk_data_file
54*e4a36f41SAndroid Build Coastguard Worker  binderfs
55*e4a36f41SAndroid Build Coastguard Worker  binfmt_miscfs
56*e4a36f41SAndroid Build Coastguard Worker  cgroup
57*e4a36f41SAndroid Build Coastguard Worker  cgroup_v2
58*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(debugfs)
59*e4a36f41SAndroid Build Coastguard Worker  debugfs_tracing_debug
60*e4a36f41SAndroid Build Coastguard Worker  device
61*e4a36f41SAndroid Build Coastguard Worker  devpts
62*e4a36f41SAndroid Build Coastguard Worker  fs_bpf
63*e4a36f41SAndroid Build Coastguard Worker  functionfs
64*e4a36f41SAndroid Build Coastguard Worker  fusectlfs
65*e4a36f41SAndroid Build Coastguard Worker  linkerconfig_file
66*e4a36f41SAndroid Build Coastguard Worker  metadata_file
67*e4a36f41SAndroid Build Coastguard Worker  mnt_expand_file
68*e4a36f41SAndroid Build Coastguard Worker  pre_reboot_dexopt_file
69*e4a36f41SAndroid Build Coastguard Worker  proc
70*e4a36f41SAndroid Build Coastguard Worker  pstorefs
71*e4a36f41SAndroid Build Coastguard Worker  rootfs
72*e4a36f41SAndroid Build Coastguard Worker  selinuxfs
73*e4a36f41SAndroid Build Coastguard Worker  sysfs
74*e4a36f41SAndroid Build Coastguard Worker  system_data_file
75*e4a36f41SAndroid Build Coastguard Worker  system_data_root_file
76*e4a36f41SAndroid Build Coastguard Worker  system_file
77*e4a36f41SAndroid Build Coastguard Worker  system_lib_file
78*e4a36f41SAndroid Build Coastguard Worker  tmpfs
79*e4a36f41SAndroid Build Coastguard Worker  vendor_file
80*e4a36f41SAndroid Build Coastguard Worker}:dir mounton;
81*e4a36f41SAndroid Build Coastguard Worker
82*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup { tmpfs labeledfs }:filesystem mount;
83*e4a36f41SAndroid Build Coastguard Worker
84*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup {
85*e4a36f41SAndroid Build Coastguard Worker  binderfs
86*e4a36f41SAndroid Build Coastguard Worker  binfmt_miscfs
87*e4a36f41SAndroid Build Coastguard Worker  cgroup
88*e4a36f41SAndroid Build Coastguard Worker  cgroup_v2
89*e4a36f41SAndroid Build Coastguard Worker  userdebug_or_eng(debugfs)
90*e4a36f41SAndroid Build Coastguard Worker  debugfs_tracing_debug
91*e4a36f41SAndroid Build Coastguard Worker  devpts
92*e4a36f41SAndroid Build Coastguard Worker  fs_bpf
93*e4a36f41SAndroid Build Coastguard Worker  functionfs
94*e4a36f41SAndroid Build Coastguard Worker  fusectlfs
95*e4a36f41SAndroid Build Coastguard Worker  labeledfs
96*e4a36f41SAndroid Build Coastguard Worker  proc
97*e4a36f41SAndroid Build Coastguard Worker  pstorefs
98*e4a36f41SAndroid Build Coastguard Worker  selinuxfs
99*e4a36f41SAndroid Build Coastguard Worker  sysfs
100*e4a36f41SAndroid Build Coastguard Worker  tmpfs
101*e4a36f41SAndroid Build Coastguard Worker}:filesystem unmount;
102*e4a36f41SAndroid Build Coastguard Worker
103*e4a36f41SAndroid Build Coastguard Worker# Allow reading /apex in chroot.
104*e4a36f41SAndroid Build Coastguard Workerr_dir_file(dexopt_chroot_setup, apex_mnt_dir)
105*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup apex_info_file:file r_file_perms;
106*e4a36f41SAndroid Build Coastguard Worker
107*e4a36f41SAndroid Build Coastguard Worker# Allow writing an empty linker config in chroot to suppress linker warnings.
108*e4a36f41SAndroid Build Coastguard Worker# The empty linker config is used until linkerconfig has run.
109*e4a36f41SAndroid Build Coastguard Worker# In chroot, we're reusing the type outside the chroot, to reuse all the rules
110*e4a36f41SAndroid Build Coastguard Worker# for it for other domains, even though we're not changing the real linker
111*e4a36f41SAndroid Build Coastguard Worker# config outside the chroot.
112*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup linkerconfig_file:dir { write add_name };
113*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup linkerconfig_file:file { create write };
114*e4a36f41SAndroid Build Coastguard Worker
115*e4a36f41SAndroid Build Coastguard Worker# Allow using the `rootcontext=` option when mounting tmpfs, so we can give the
116*e4a36f41SAndroid Build Coastguard Worker# right labels to /apex, /linkerconfig, /mnt/artd_tmp in chroot.
117*e4a36f41SAndroid Build Coastguard Worker# Combined with `allow file_type tmpfs:filesystem associate;`, this allows
118*e4a36f41SAndroid Build Coastguard Worker# giving any labels to any tmpfs filesystems as soon as they are mounted.
119*e4a36f41SAndroid Build Coastguard Worker# Note that those tmpfs filesystems are known to be empty at the time where the
120*e4a36f41SAndroid Build Coastguard Worker# labels are given, and this rule doesn't allow relabeling any existing tmpfs.
121*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup tmpfs:filesystem relabelfrom;
122*e4a36f41SAndroid Build Coastguard Worker
123*e4a36f41SAndroid Build Coastguard Worker# Allow executing art_exec_exec without a domain transition because it is a thin
124*e4a36f41SAndroid Build Coastguard Worker# wrapper that executes other binaries on behalf of dexopt_chroot_setup. Domain
125*e4a36f41SAndroid Build Coastguard Worker# transition will take place as soon as art_exec_exec executes other binaries.
126*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup art_exec_exec:file rx_file_perms;
127*e4a36f41SAndroid Build Coastguard Worker
128*e4a36f41SAndroid Build Coastguard Worker# Allow running other binaries in their own domains.
129*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(dexopt_chroot_setup, apexd_exec, apexd)
130*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(dexopt_chroot_setup, linkerconfig_exec, linkerconfig)
131*e4a36f41SAndroid Build Coastguard Worker
132*e4a36f41SAndroid Build Coastguard Worker# Allow running snapshotctl through init, to map and unmap block devices.
133*e4a36f41SAndroid Build Coastguard Workerset_prop(dexopt_chroot_setup, snapshotctl_prop)
134*e4a36f41SAndroid Build Coastguard Worker
135*e4a36f41SAndroid Build Coastguard Worker# Allow accessing /data/app/..., to bind-mount dirs for incremental apps.
136*e4a36f41SAndroid Build Coastguard Workerallow dexopt_chroot_setup apk_data_file:dir { getattr search };
137*e4a36f41SAndroid Build Coastguard Worker
138*e4a36f41SAndroid Build Coastguard Worker# Neverallow rules.
139*e4a36f41SAndroid Build Coastguard Worker
140*e4a36f41SAndroid Build Coastguard Worker# Never allow running other binaries without a domain transition.
141*e4a36f41SAndroid Build Coastguard Worker# The exception for art_exec_exec is explained above.
142*e4a36f41SAndroid Build Coastguard Workerneverallow dexopt_chroot_setup ~{art_exec_exec}:file execute_no_trans;
143*e4a36f41SAndroid Build Coastguard Worker
144*e4a36f41SAndroid Build Coastguard Worker# Given how powerful this domain is, it shouldn't be used for other purposes.
145*e4a36f41SAndroid Build Coastguard Workerneverallow { domain -init } dexopt_chroot_setup:process transition;
146*e4a36f41SAndroid Build Coastguard Workerneverallow * dexopt_chroot_setup:process dyntransition;
147*e4a36f41SAndroid Build Coastguard Worker
148*e4a36f41SAndroid Build Coastguard Worker# Never allow other processes to access the temp dirs for Pre-reboot Dexopt.
149*e4a36f41SAndroid Build Coastguard Workerneverallow {
150*e4a36f41SAndroid Build Coastguard Worker  domain
151*e4a36f41SAndroid Build Coastguard Worker  -art_exec
152*e4a36f41SAndroid Build Coastguard Worker  -artd
153*e4a36f41SAndroid Build Coastguard Worker  -dexopt_chroot_setup
154*e4a36f41SAndroid Build Coastguard Worker  -init
155*e4a36f41SAndroid Build Coastguard Worker  -system_server
156*e4a36f41SAndroid Build Coastguard Worker  -vendor_init
157*e4a36f41SAndroid Build Coastguard Worker} pre_reboot_dexopt_file:dir *;
158