blob: ede53d44b988dbeb9e5cde83730531faae371b24 [file] [log] [blame]
Jiakai Zhang4acd0732024-03-20 11:24:54 +00001# A service that sets up the chroot environment for Pre-reboot Dexopt.
Jiakai Zhang817c49f2023-10-18 17:03:20 +01002type dexopt_chroot_setup, domain, coredomain;
3type dexopt_chroot_setup_exec, system_file_type, exec_type, file_type;
4type dexopt_chroot_setup_tmpfs, file_type;
5
6# Allow dexopt_chroot_setup to publish a binder service and make binder calls.
7binder_use(dexopt_chroot_setup)
8add_service(dexopt_chroot_setup, dexopt_chroot_setup_service)
9allow dexopt_chroot_setup dumpstate:fifo_file { getattr write };
10allow dexopt_chroot_setup dumpstate:fd use;
11
12init_daemon_domain(dexopt_chroot_setup)
13
Jiakai Zhang4acd0732024-03-20 11:24:54 +000014# Use tmpfs_domain() which will give tmpfs files created by dexopt_chroot_setup
15# their own label, which differs from other labels created by other processes.
16# This allows to distinguish in policy files created by dexopt_chroot_setup vs
17# other processes.
Jiakai Zhang817c49f2023-10-18 17:03:20 +010018tmpfs_domain(dexopt_chroot_setup)
19
20# libart (mark_compact.cc) has some intialization code that touches the cache
21# info file and userfaultfd.
22allow dexopt_chroot_setup apex_module_data_file:dir { getattr search };
23r_dir_file(dexopt_chroot_setup, apex_art_data_file)
24userfaultfd_use(dexopt_chroot_setup)
Jiakai Zhang4acd0732024-03-20 11:24:54 +000025
26# Allow getting root capabilities to bypass permission checks.
27# - "sys_admin" is for performing mount and umount.
28# - "sys_chroot" is for performing chroot.
29allow dexopt_chroot_setup self:global_capability_class_set { sys_admin sys_chroot };
30
31# Allow managing its own files.
32# The root of the temp dir that dexopt_chroot_setup uses is labeled
33# pre_reboot_dexopt_file.
34allow dexopt_chroot_setup pre_reboot_dexopt_file:dir create_dir_perms;
35allow dexopt_chroot_setup pre_reboot_dexopt_file:file create_file_perms;
36
37# Allow accessing /proc/filesystems.
38allow dexopt_chroot_setup proc_filesystems:file r_file_perms;
39
40# Allow accessing block devices (/dev/block/...).
41allow dexopt_chroot_setup block_device:dir { getattr search };
42
43# Allow mounting file systems, to create a chroot environment.
44allow dexopt_chroot_setup {
45 apex_mnt_dir
Jiakai Zhang0a49ac32024-06-03 20:12:40 +010046 apk_data_file
Jiakai Zhang4acd0732024-03-20 11:24:54 +000047 binderfs
48 cgroup
49 cgroup_v2
50 debugfs_tracing_debug
51 device
52 devpts
53 fs_bpf
Jiakai Zhangbe2e7192024-05-09 04:03:18 +000054 functionfs
Jiakai Zhang4acd0732024-03-20 11:24:54 +000055 fusectlfs
56 linkerconfig_file
57 metadata_file
58 mnt_expand_file
59 pre_reboot_dexopt_file
60 proc
61 pstorefs
62 rootfs
63 selinuxfs
64 sysfs
65 system_data_file
66 system_data_root_file
67 system_file
68 tmpfs
69 vendor_file
70}:dir mounton;
71
72allow dexopt_chroot_setup { tmpfs labeledfs }:filesystem mount;
73
74allow dexopt_chroot_setup {
75 binderfs
76 cgroup
77 cgroup_v2
78 debugfs_tracing_debug
79 devpts
80 fs_bpf
Jiakai Zhangbe2e7192024-05-09 04:03:18 +000081 functionfs
Jiakai Zhang4acd0732024-03-20 11:24:54 +000082 fusectlfs
83 labeledfs
84 proc
85 pstorefs
86 selinuxfs
87 sysfs
88 tmpfs
89}:filesystem unmount;
90
91# Allow reading /apex in chroot.
92r_dir_file(dexopt_chroot_setup, apex_mnt_dir)
93allow dexopt_chroot_setup apex_info_file:file r_file_perms;
94
95# Allow writing an empty linker config in chroot to suppress linker warnings.
96# The empty linker config is used until linkerconfig has run.
97# In chroot, we're reusing the type outside the chroot, to reuse all the rules
98# for it for other domains, even though we're not changing the real linker
99# config outside the chroot.
100allow dexopt_chroot_setup linkerconfig_file:dir { write add_name };
101allow dexopt_chroot_setup linkerconfig_file:file { create write };
102
103# Allow using the `rootcontext=` option when mounting tmpfs, so we can give the
104# right labels to /apex, /linkerconfig, /mnt/artd_tmp in chroot.
105# Combined with `allow file_type tmpfs:filesystem associate;`, this allows
106# giving any labels to any tmpfs filesystems as soon as they are mounted.
107# Note that those tmpfs filesystems are known to be empty at the time where the
108# labels are given, and this rule doesn't allow relabeling any existing tmpfs.
109allow dexopt_chroot_setup tmpfs:filesystem relabelfrom;
110
111# Allow executing art_exec_exec without a domain transition because it is a thin
112# wrapper that executes other binaries on behalf of dexopt_chroot_setup. Domain
113# transition will take place as soon as art_exec_exec executes other binaries.
114allow dexopt_chroot_setup art_exec_exec:file rx_file_perms;
115
116# Allow running other binaries in their own domains.
117domain_auto_trans(dexopt_chroot_setup, apexd_exec, apexd)
118domain_auto_trans(dexopt_chroot_setup, linkerconfig_exec, linkerconfig)
119
120# Allow running snapshotctl through init, to map and unmap block devices.
121set_prop(dexopt_chroot_setup, snapshotctl_prop)
122
Jiakai Zhang0a49ac32024-06-03 20:12:40 +0100123# Allow accessing /data/app/..., to bind-mount dirs for incremental apps.
124allow dexopt_chroot_setup apk_data_file:dir { getattr search };
125
Jiakai Zhang4acd0732024-03-20 11:24:54 +0000126# Neverallow rules.
127
128# Never allow running other binaries without a domain transition.
129# The exception for art_exec_exec is explained above.
130neverallow dexopt_chroot_setup ~{art_exec_exec}:file execute_no_trans;
131
132# Given how powerful this domain is, it shouldn't be used for other purposes.
133neverallow { domain -init } dexopt_chroot_setup:process transition;
134neverallow * dexopt_chroot_setup:process dyntransition;
135
136# Never allow other processes to access the temp dirs for Pre-reboot Dexopt.
137neverallow {
138 domain
139 -art_exec
140 -artd
141 -dexopt_chroot_setup
142 -init
143 -system_server
144 -vendor_init
145} pre_reboot_dexopt_file:dir *;