1# Domain for the otapreopt executable, running under postinstall_dexopt
2#
3# Note: otapreopt is a driver for dex2oat, and reuses parts of installd. As such,
4# this is derived and adapted from installd.te.
5
6type postinstall_dexopt, domain, coredomain;
7
8# Run dex2oat/patchoat in its own sandbox.
9# We have to manually transition, as we don't have an entrypoint.
10# - Case where dex2oat is in a non-flattened APEX, which has retained
11#   the correct type (`dex2oat_exec`).
12domain_auto_trans(postinstall_dexopt, dex2oat_exec, dex2oat)
13# - Case where dex2oat is in a flattened APEX, which has been tagged
14#   with the `postinstall_file` type by update_engine.
15domain_auto_trans(postinstall_dexopt, postinstall_file, dex2oat)
16
17allow postinstall_dexopt self:global_capability_class_set { chown dac_override dac_read_search fowner fsetid setgid setuid };
18
19allow postinstall_dexopt postinstall_file:filesystem getattr;
20allow postinstall_dexopt postinstall_file:dir { getattr read search };
21allow postinstall_dexopt postinstall_file:lnk_file { getattr read };
22allow postinstall_dexopt proc_filesystems:file { getattr open read };
23allow postinstall_dexopt tmpfs:file read;
24
25# Allow access to /postinstall/apex.
26allow postinstall_dexopt postinstall_apex_mnt_dir:dir { getattr search };
27
28# Note: /data/ota is created by init (see system/core/rootdir/init.rc) to avoid giving access
29# here and having to relabel the directory.
30
31# Read app data (APKs) as input to dex2oat.
32r_dir_file(postinstall_dexopt, apk_data_file)
33# Read vendor app data (APKs) as input to dex2oat.
34r_dir_file(postinstall_dexopt, vendor_app_file)
35# Read vendor overlay files (APKs) as input to dex2oat.
36r_dir_file(postinstall_dexopt, vendor_overlay_file)
37# Access to app oat directory.
38r_dir_file(postinstall_dexopt, dalvikcache_data_file)
39
40# Read profile data.
41allow postinstall_dexopt user_profile_data_file:dir { getattr search };
42allow postinstall_dexopt user_profile_data_file:file r_file_perms;
43# Suppress deletion denial (we do not want to update the profile).
44dontaudit postinstall_dexopt user_profile_data_file:file { write };
45
46# Write to /data/ota(/*). Create symlinks in /data/ota(/*)
47allow postinstall_dexopt ota_data_file:dir create_dir_perms;
48allow postinstall_dexopt ota_data_file:file create_file_perms;
49allow postinstall_dexopt ota_data_file:lnk_file create_file_perms;
50
51# Need to write .b files, which are dalvikcache_data_file, not ota_data_file.
52# TODO: See whether we can apply ota_data_file?
53allow postinstall_dexopt dalvikcache_data_file:dir rw_dir_perms;
54allow postinstall_dexopt dalvikcache_data_file:file create_file_perms;
55
56# Allow labeling of files under /data/app/com.example/oat/
57# TODO: Restrict to .b suffix?
58allow postinstall_dexopt dalvikcache_data_file:dir relabelto;
59allow postinstall_dexopt dalvikcache_data_file:file { relabelto link };
60
61# Check validity of SELinux context before use.
62selinux_check_context(postinstall_dexopt)
63selinux_check_access(postinstall_dexopt)
64
65
66# Postinstall wants to know about our child.
67allow postinstall_dexopt postinstall:process sigchld;
68
69# Allow otapreopt to use file descriptors from otapreopt_chroot.
70# TODO: Probably we can actually close file descriptors...
71allow postinstall_dexopt otapreopt_chroot:fd use;
72
73# Allow postinstall_dexopt to access the runtime feature flag properties.
74get_prop(postinstall_dexopt, device_config_runtime_native_prop)
75get_prop(postinstall_dexopt, device_config_runtime_native_boot_prop)
76