xref: /aosp_15_r20/system/sepolicy/private/artd.te (revision e4a36f4174b17bbab9dc043f4a65dc8d87377290)
1*e4a36f41SAndroid Build Coastguard Worker# ART service daemon.
2*e4a36f41SAndroid Build Coastguard Workertypeattribute artd coredomain;
3*e4a36f41SAndroid Build Coastguard Workertypeattribute artd mlstrustedsubject;
4*e4a36f41SAndroid Build Coastguard Workertype artd_exec, system_file_type, exec_type, file_type;
5*e4a36f41SAndroid Build Coastguard Workertype artd_tmpfs, file_type;
6*e4a36f41SAndroid Build Coastguard Worker
7*e4a36f41SAndroid Build Coastguard Worker# All types of artd subprocesses, which artd can kill.
8*e4a36f41SAndroid Build Coastguard Workerattribute artd_subprocess_type;
9*e4a36f41SAndroid Build Coastguard Worker
10*e4a36f41SAndroid Build Coastguard Worker# Allow artd to publish a binder service and make binder calls.
11*e4a36f41SAndroid Build Coastguard Workerbinder_use(artd)
12*e4a36f41SAndroid Build Coastguard Workeradd_service(artd, artd_service)
13*e4a36f41SAndroid Build Coastguard Workeradd_service(artd, artd_pre_reboot_service)
14*e4a36f41SAndroid Build Coastguard Workerallow artd dumpstate:fifo_file { getattr write };
15*e4a36f41SAndroid Build Coastguard Workerallow artd dumpstate:fd use;
16*e4a36f41SAndroid Build Coastguard Worker
17*e4a36f41SAndroid Build Coastguard Workerinit_daemon_domain(artd)
18*e4a36f41SAndroid Build Coastguard Worker
19*e4a36f41SAndroid Build Coastguard Worker# Allow query ART device config properties
20*e4a36f41SAndroid Build Coastguard Workerget_prop(artd, device_config_runtime_native_prop)
21*e4a36f41SAndroid Build Coastguard Workerget_prop(artd, device_config_runtime_native_boot_prop)
22*e4a36f41SAndroid Build Coastguard Worker
23*e4a36f41SAndroid Build Coastguard Worker# Access to "odsign.verification.success" for deciding whether to deny files in
24*e4a36f41SAndroid Build Coastguard Worker# the ART APEX data directory.
25*e4a36f41SAndroid Build Coastguard Workerget_prop(artd, odsign_prop)
26*e4a36f41SAndroid Build Coastguard Worker
27*e4a36f41SAndroid Build Coastguard Worker# Reading an APK opens a ZipArchive, which unpack to tmpfs.
28*e4a36f41SAndroid Build Coastguard Worker# Use tmpfs_domain() which will give tmpfs files created by artd their
29*e4a36f41SAndroid Build Coastguard Worker# own label, which differs from other labels created by other processes.
30*e4a36f41SAndroid Build Coastguard Worker# This allows to distinguish in policy files created by artd vs other
31*e4a36f41SAndroid Build Coastguard Worker# processes.
32*e4a36f41SAndroid Build Coastguard Workertmpfs_domain(artd)
33*e4a36f41SAndroid Build Coastguard Worker
34*e4a36f41SAndroid Build Coastguard Worker# Allow testing userfaultfd support.
35*e4a36f41SAndroid Build Coastguard Workeruserfaultfd_use(artd)
36*e4a36f41SAndroid Build Coastguard Worker
37*e4a36f41SAndroid Build Coastguard Worker# Read access to primary dex'es on writable partitions
38*e4a36f41SAndroid Build Coastguard Worker# ({/data,/mnt/expand/<volume-uuid>}/app/...).
39*e4a36f41SAndroid Build Coastguard Worker# Also allow creating the "oat" directory before restorecon.
40*e4a36f41SAndroid Build Coastguard Workerallow artd mnt_expand_file:dir { getattr search };
41*e4a36f41SAndroid Build Coastguard Workerallow artd apk_data_file:dir { rw_dir_perms create setattr relabelfrom };
42*e4a36f41SAndroid Build Coastguard Workerallow artd apk_data_file:file r_file_perms;
43*e4a36f41SAndroid Build Coastguard Workerallow artd apk_tmp_file:dir { rw_dir_perms create setattr relabelfrom };
44*e4a36f41SAndroid Build Coastguard Workerallow artd apk_tmp_file:file r_file_perms;
45*e4a36f41SAndroid Build Coastguard Worker
46*e4a36f41SAndroid Build Coastguard Worker# Read access to vendor APKs ({/vendor,/odm}/{app,priv-app}/...).
47*e4a36f41SAndroid Build Coastguard Workerr_dir_file(artd, vendor_app_file)
48*e4a36f41SAndroid Build Coastguard Worker
49*e4a36f41SAndroid Build Coastguard Worker# Read access to vendor overlay APKs ({/vendor,/odm,/oem,/apex/*}/overlay/...).
50*e4a36f41SAndroid Build Coastguard Workerallow artd oemfs:dir { getattr search };
51*e4a36f41SAndroid Build Coastguard Workerr_dir_file(artd, vendor_overlay_file)
52*e4a36f41SAndroid Build Coastguard Worker# Vendor overlay can be found in vendor apex
53*e4a36f41SAndroid Build Coastguard Workerallow artd vendor_apex_metadata_file:dir { getattr search };
54*e4a36f41SAndroid Build Coastguard Worker
55*e4a36f41SAndroid Build Coastguard Worker# Read access to vendor shared libraries ({/vendor,/odm}/framework/...).
56*e4a36f41SAndroid Build Coastguard Workerr_dir_file(artd, vendor_framework_file)
57*e4a36f41SAndroid Build Coastguard Worker
58*e4a36f41SAndroid Build Coastguard Worker# Read/write access to all compilation artifacts generated on device for apps'
59*e4a36f41SAndroid Build Coastguard Worker# primary dex'es. (/data/dalvik-cache/..., /data/app/.../oat/..., etc.)
60*e4a36f41SAndroid Build Coastguard Workerallow artd dalvikcache_data_file:dir { create_dir_perms relabelto };
61*e4a36f41SAndroid Build Coastguard Workerallow artd dalvikcache_data_file:file { create_file_perms relabelto };
62*e4a36f41SAndroid Build Coastguard Worker
63*e4a36f41SAndroid Build Coastguard Worker# Read access to the ART APEX data directory.
64*e4a36f41SAndroid Build Coastguard Worker# Needed for reading the boot image generated on device.
65*e4a36f41SAndroid Build Coastguard Workerallow artd apex_module_data_file:dir { getattr search };
66*e4a36f41SAndroid Build Coastguard Workerr_dir_file(artd, apex_art_data_file)
67*e4a36f41SAndroid Build Coastguard Worker
68*e4a36f41SAndroid Build Coastguard Worker# Read access to /apex/apex-info-list.xml
69*e4a36f41SAndroid Build Coastguard Worker# Needed for getting APEX versions.
70*e4a36f41SAndroid Build Coastguard Workerallow artd apex_info_file:file r_file_perms;
71*e4a36f41SAndroid Build Coastguard Worker
72*e4a36f41SAndroid Build Coastguard Worker# Allow getting root capabilities to bypass permission checks.
73*e4a36f41SAndroid Build Coastguard Worker# - "dac_override" and "dac_read_search" are for
74*e4a36f41SAndroid Build Coastguard Worker#   - reading secondary dex'es in app data directories (reading primary dex'es
75*e4a36f41SAndroid Build Coastguard Worker#     doesn't need root capabilities)
76*e4a36f41SAndroid Build Coastguard Worker#   - managing (CRUD) compilation artifacts in both APK directories for primary
77*e4a36f41SAndroid Build Coastguard Worker#     dex'es and in app data directories for secondary dex'es
78*e4a36f41SAndroid Build Coastguard Worker#   - managing (CRUD) profile files for both primary dex'es and secondary dex'es
79*e4a36f41SAndroid Build Coastguard Worker# - "fowner" is for adjusting the file permissions of compilation artifacts and
80*e4a36f41SAndroid Build Coastguard Worker#   profile files based on whether they include user data or not.
81*e4a36f41SAndroid Build Coastguard Worker# - "chown" is for transferring the ownership of compilation artifacts and
82*e4a36f41SAndroid Build Coastguard Worker#   profile files to the system or apps.
83*e4a36f41SAndroid Build Coastguard Workerallow artd self:global_capability_class_set { dac_override dac_read_search fowner chown };
84*e4a36f41SAndroid Build Coastguard Worker
85*e4a36f41SAndroid Build Coastguard Worker# Read/write access to profiles (/data/misc/profiles/{ref,cur}/...). Also allow
86*e4a36f41SAndroid Build Coastguard Worker# scanning /data/misc/profiles/cur, for cleaning up obsolete managed files.
87*e4a36f41SAndroid Build Coastguard Workerallow artd user_profile_root_file:dir r_dir_perms;
88*e4a36f41SAndroid Build Coastguard Workerallow artd user_profile_data_file:dir rw_dir_perms;
89*e4a36f41SAndroid Build Coastguard Workerallow artd user_profile_data_file:file create_file_perms;
90*e4a36f41SAndroid Build Coastguard Worker
91*e4a36f41SAndroid Build Coastguard Worker# Read/write access to secondary dex files, their profiles, and their
92*e4a36f41SAndroid Build Coastguard Worker# compilation artifacts
93*e4a36f41SAndroid Build Coastguard Worker# ({/data,/mnt/expand/<volume-uuid>}/{user,user_de}/<user-id>/<package-name>/...).
94*e4a36f41SAndroid Build Coastguard Workerallow artd app_data_file_type:dir { create_dir_perms relabelfrom relabelto };
95*e4a36f41SAndroid Build Coastguard Workerallow artd app_data_file_type:file { create_file_perms relabelfrom relabelto };
96*e4a36f41SAndroid Build Coastguard Worker
97*e4a36f41SAndroid Build Coastguard Worker# Allow symlinks for secondary dex files. This has be to restricted because
98*e4a36f41SAndroid Build Coastguard Worker# symlinks can cause various security issues. We allow "privapp_data_file" just
99*e4a36f41SAndroid Build Coastguard Worker# for GMS because so far we only see GMS using symlinks.
100*e4a36f41SAndroid Build Coastguard Workerallow artd privapp_data_file:lnk_file { getattr read };
101*e4a36f41SAndroid Build Coastguard Worker
102*e4a36f41SAndroid Build Coastguard Worker# Read access to SELinux context files, for restorecon.
103*e4a36f41SAndroid Build Coastguard Workerallow artd file_contexts_file:file r_file_perms;
104*e4a36f41SAndroid Build Coastguard Workerallow artd seapp_contexts_file:file r_file_perms;
105*e4a36f41SAndroid Build Coastguard Worker
106*e4a36f41SAndroid Build Coastguard Worker# Check validity of SELinux context, for restorecon.
107*e4a36f41SAndroid Build Coastguard Workerselinux_check_context(artd)
108*e4a36f41SAndroid Build Coastguard Worker
109*e4a36f41SAndroid Build Coastguard Worker# Allow scanning /, for cleaning up obsolete managed files.
110*e4a36f41SAndroid Build Coastguard Workerallow artd rootfs:dir r_dir_perms;
111*e4a36f41SAndroid Build Coastguard Worker
112*e4a36f41SAndroid Build Coastguard Worker# Allow scanning /data, for cleaning up obsolete managed files.
113*e4a36f41SAndroid Build Coastguard Workerallow artd system_data_root_file:dir r_dir_perms;
114*e4a36f41SAndroid Build Coastguard Worker
115*e4a36f41SAndroid Build Coastguard Worker# Allow scanning /mnt, for cleaning up obsolete managed files.
116*e4a36f41SAndroid Build Coastguard Workerallow artd tmpfs:dir r_dir_perms;
117*e4a36f41SAndroid Build Coastguard Worker
118*e4a36f41SAndroid Build Coastguard Worker# Allow scanning /mnt/expand, for cleaning up obsolete managed files.
119*e4a36f41SAndroid Build Coastguard Workerallow artd mnt_expand_file:dir r_dir_perms;
120*e4a36f41SAndroid Build Coastguard Worker
121*e4a36f41SAndroid Build Coastguard Worker# Allow scanning {/data,/mnt/expand/<volume-uuid>}/{user,user_de}, for cleaning
122*e4a36f41SAndroid Build Coastguard Worker# up obsolete managed files.
123*e4a36f41SAndroid Build Coastguard Workerallow artd system_userdir_file:dir r_dir_perms;
124*e4a36f41SAndroid Build Coastguard Worker
125*e4a36f41SAndroid Build Coastguard Worker# Allow scanning {/data,/mnt/expand/<volume-uuid>}/{user,user_de}/<user-id> and
126*e4a36f41SAndroid Build Coastguard Worker# /mnt/expand/<volume-uuid>, for cleaning up obsolete managed files.
127*e4a36f41SAndroid Build Coastguard Workerallow artd system_data_file:dir r_dir_perms;
128*e4a36f41SAndroid Build Coastguard Worker
129*e4a36f41SAndroid Build Coastguard Worker# Allow art_exec_exec to use the artd domain because it is a thin wrapper that
130*e4a36f41SAndroid Build Coastguard Worker# executes other binaries on behalf of artd. Domain transition will take place
131*e4a36f41SAndroid Build Coastguard Worker# as soon as art_exec_exec executes other binaries.
132*e4a36f41SAndroid Build Coastguard Workerallow artd art_exec_exec:file rx_file_perms;
133*e4a36f41SAndroid Build Coastguard Worker
134*e4a36f41SAndroid Build Coastguard Worker# Allow running other binaries in their own domains.
135*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(artd, profman_exec, profman)
136*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(artd, dex2oat_exec, dex2oat)
137*e4a36f41SAndroid Build Coastguard Worker
138*e4a36f41SAndroid Build Coastguard Worker# Allow sending sigkill to subprocesses.
139*e4a36f41SAndroid Build Coastguard Workerallow artd artd_subprocess_type:process sigkill;
140*e4a36f41SAndroid Build Coastguard Worker
141*e4a36f41SAndroid Build Coastguard Worker# Allow reading process info (/proc/<pid>/...).
142*e4a36f41SAndroid Build Coastguard Worker# This is needed for getting CPU time and wall time spent on subprocesses.
143*e4a36f41SAndroid Build Coastguard Workerr_dir_file(artd, profman);
144*e4a36f41SAndroid Build Coastguard Workerr_dir_file(artd, dex2oat);
145*e4a36f41SAndroid Build Coastguard Worker
146*e4a36f41SAndroid Build Coastguard Worker# Allow artd to reopen its own memfd.
147*e4a36f41SAndroid Build Coastguard Worker# artd needs to reopen a memfd with readonly in order to pass it to subprocesses
148*e4a36f41SAndroid Build Coastguard Worker# that don't have write permissions on memfds.
149*e4a36f41SAndroid Build Coastguard Workerallow artd artd_tmpfs:file open;
150*e4a36f41SAndroid Build Coastguard Worker
151*e4a36f41SAndroid Build Coastguard Worker# For Pre-reboot Dexopt.
152*e4a36f41SAndroid Build Coastguard Worker
153*e4a36f41SAndroid Build Coastguard Worker# Allow init to execute artd through art_exec.
154*e4a36f41SAndroid Build Coastguard Workerallow artd art_exec:fd use;
155*e4a36f41SAndroid Build Coastguard Worker
156*e4a36f41SAndroid Build Coastguard Worker# During Pre-reboot Dexopt, artd needs one more capability:
157*e4a36f41SAndroid Build Coastguard Worker# - "sys_admin" is for bind-mounting temp dirs at
158*e4a36f41SAndroid Build Coastguard Worker#   /data/misc/apexdata/com.android.art and /data/misc/odrefresh, to run
159*e4a36f41SAndroid Build Coastguard Worker#   odrefresh innocuously (in a way that doesn't affect the real boot images,
160*e4a36f41SAndroid Build Coastguard Worker#   metrics, etc.).
161*e4a36f41SAndroid Build Coastguard Workerallow artd self:global_capability_class_set sys_admin;
162*e4a36f41SAndroid Build Coastguard Worker
163*e4a36f41SAndroid Build Coastguard Worker# Allow running other binaries in their own domains.
164*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(artd, derive_classpath_exec, derive_classpath)
165*e4a36f41SAndroid Build Coastguard Workerdomain_auto_trans(artd, odrefresh_exec, odrefresh)
166*e4a36f41SAndroid Build Coastguard Worker
167*e4a36f41SAndroid Build Coastguard Worker# Allow accessing Pre-reboot Dexopt files.
168*e4a36f41SAndroid Build Coastguard Workerallow artd pre_reboot_dexopt_file:dir { getattr search };
169*e4a36f41SAndroid Build Coastguard Worker
170*e4a36f41SAndroid Build Coastguard Worker# Allow reading /init.environ.rc in chroot, to extract env vars from it.
171*e4a36f41SAndroid Build Coastguard Workerallow artd rootfs:file { read open getattr };
172*e4a36f41SAndroid Build Coastguard Worker
173*e4a36f41SAndroid Build Coastguard Worker# Allow managing Pre-reboot Dexopt temp files.
174*e4a36f41SAndroid Build Coastguard Worker# The root of the temp dir that artd uses during Pre-reboot Dexopt is labeled
175*e4a36f41SAndroid Build Coastguard Worker# pre_reboot_dexopt_artd_file. Inside the temp dir, we create files and dirs and
176*e4a36f41SAndroid Build Coastguard Worker# relabel them after creation, so we need relabelfrom.
177*e4a36f41SAndroid Build Coastguard Workerallow artd pre_reboot_dexopt_artd_file:dir { create_dir_perms relabelfrom };
178*e4a36f41SAndroid Build Coastguard Workerallow artd pre_reboot_dexopt_artd_file:file { create_file_perms relabelfrom };
179*e4a36f41SAndroid Build Coastguard Worker
180*e4a36f41SAndroid Build Coastguard Worker# Allow bind-mounting at /data/misc/apexdata/com.android.art and
181*e4a36f41SAndroid Build Coastguard Worker# /data/misc/odrefresh and restorecon, to run odrefresh innocuously.
182*e4a36f41SAndroid Build Coastguard Workerallow artd { apex_art_data_file odrefresh_data_file }:dir relabelto;
183*e4a36f41SAndroid Build Coastguard Workerallow artd { apex_art_data_file odrefresh_data_file pre_reboot_dexopt_artd_file }:dir mounton;
184*e4a36f41SAndroid Build Coastguard Worker
185*e4a36f41SAndroid Build Coastguard Worker# Neverallow rules.
186*e4a36f41SAndroid Build Coastguard Worker
187*e4a36f41SAndroid Build Coastguard Worker# Never allow running other binaries without a domain transition.
188*e4a36f41SAndroid Build Coastguard Worker# The exception for art_exec_exec is explained above.
189*e4a36f41SAndroid Build Coastguard Workerneverallow artd ~{art_exec_exec}:file execute_no_trans;
190*e4a36f41SAndroid Build Coastguard Worker
191*e4a36f41SAndroid Build Coastguard Worker# Make sure artd_subprocess_type is complete, in a sense that it includes all
192*e4a36f41SAndroid Build Coastguard Worker# types of artd subprocesses.
193*e4a36f41SAndroid Build Coastguard Workerneverallow artd ~{artd_subprocess_type crash_dump}:process transition;
194*e4a36f41SAndroid Build Coastguard Worker
195*e4a36f41SAndroid Build Coastguard Worker# artd uses process groups to manage subprocesses and kill them. To ensure
196*e4a36f41SAndroid Build Coastguard Worker# successful kill, we need to prevent subprocesses from changing their
197*e4a36f41SAndroid Build Coastguard Worker# process groups or transitioning to other domains.
198*e4a36f41SAndroid Build Coastguard Worker# Transitioning crash_dump is allowed because it is transient and is only used
199*e4a36f41SAndroid Build Coastguard Worker# upon crashes.
200*e4a36f41SAndroid Build Coastguard Workerneverallow artd_subprocess_type self:process setpgid;
201*e4a36f41SAndroid Build Coastguard Workerneverallow artd_subprocess_type ~{artd_subprocess_type crash_dump}:process transition;
202