Andreas Gampe | 6d5baca | 2019-02-26 13:13:28 -0800 | [diff] [blame] | 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 | |
Alan Stokes | 7aa4041 | 2020-12-04 14:07:52 +0000 | [diff] [blame] | 6 | type postinstall_dexopt, domain, coredomain, mlstrustedsubject; |
Alex Light | 16dfb43 | 2021-03-11 11:26:08 -0800 | [diff] [blame] | 7 | type postinstall_dexopt_exec, system_file_type, exec_type, file_type; |
Alex Light | 8393a05 | 2021-04-26 16:46:57 -0700 | [diff] [blame] | 8 | type postinstall_dexopt_tmpfs, file_type; |
Alex Klyubin | f5446eb | 2017-03-23 14:27:32 -0700 | [diff] [blame] | 9 | |
dcashman | cc39f63 | 2016-07-22 13:13:11 -0700 | [diff] [blame] | 10 | # Run dex2oat/patchoat in its own sandbox. |
| 11 | # We have to manually transition, as we don't have an entrypoint. |
Roland Levillain | 66f40a8 | 2019-03-13 18:52:23 +0000 | [diff] [blame] | 12 | # - Case where dex2oat is in a non-flattened APEX, which has retained |
| 13 | # the correct type (`dex2oat_exec`). |
Roland Levillain | ab9c053 | 2019-01-19 12:42:11 +0000 | [diff] [blame] | 14 | domain_auto_trans(postinstall_dexopt, dex2oat_exec, dex2oat) |
Roland Levillain | 66f40a8 | 2019-03-13 18:52:23 +0000 | [diff] [blame] | 15 | # - Case where dex2oat is in a flattened APEX, which has been tagged |
| 16 | # with the `postinstall_file` type by update_engine. |
| 17 | domain_auto_trans(postinstall_dexopt, postinstall_file, dex2oat) |
Andreas Gampe | 6d5baca | 2019-02-26 13:13:28 -0800 | [diff] [blame] | 18 | |
Alex Light | 8393a05 | 2021-04-26 16:46:57 -0700 | [diff] [blame] | 19 | # Run derive_classpath to get the current BCP. |
| 20 | domain_auto_trans(postinstall_dexopt, derive_classpath_exec, derive_classpath) |
| 21 | # Allow postinstall_dexopt to make a tempfile for derive_classpath to write into |
| 22 | tmpfs_domain(postinstall_dexopt); |
| 23 | allow postinstall_dexopt postinstall_dexopt_tmpfs:file open; |
| 24 | |
Andreas Gampe | 6d5baca | 2019-02-26 13:13:28 -0800 | [diff] [blame] | 25 | allow postinstall_dexopt self:global_capability_class_set { chown dac_override dac_read_search fowner fsetid setgid setuid }; |
| 26 | |
| 27 | allow postinstall_dexopt postinstall_file:filesystem getattr; |
| 28 | allow postinstall_dexopt postinstall_file:dir { getattr read search }; |
| 29 | allow postinstall_dexopt postinstall_file:lnk_file { getattr read }; |
| 30 | allow postinstall_dexopt proc_filesystems:file { getattr open read }; |
Alex Light | 16dfb43 | 2021-03-11 11:26:08 -0800 | [diff] [blame] | 31 | allow postinstall_dexopt rootfs:file r_file_perms; |
| 32 | |
Andreas Gampe | 6d5baca | 2019-02-26 13:13:28 -0800 | [diff] [blame] | 33 | allow postinstall_dexopt tmpfs:file read; |
| 34 | |
Orion Hodson | 5fcce9d | 2021-07-19 18:58:43 +0100 | [diff] [blame] | 35 | # Allow access odsign verification status |
| 36 | get_prop(postinstall_dexopt, odsign_prop) |
| 37 | |
Andreas Gampe | 6d5baca | 2019-02-26 13:13:28 -0800 | [diff] [blame] | 38 | # Allow access to /postinstall/apex. |
| 39 | allow postinstall_dexopt postinstall_apex_mnt_dir:dir { getattr search }; |
| 40 | |
| 41 | # Note: /data/ota is created by init (see system/core/rootdir/init.rc) to avoid giving access |
| 42 | # here and having to relabel the directory. |
| 43 | |
| 44 | # Read app data (APKs) as input to dex2oat. |
| 45 | r_dir_file(postinstall_dexopt, apk_data_file) |
| 46 | # Read vendor app data (APKs) as input to dex2oat. |
| 47 | r_dir_file(postinstall_dexopt, vendor_app_file) |
Andreas Gampe | 30186cf | 2019-03-22 12:13:53 -0700 | [diff] [blame] | 48 | # Read vendor overlay files (APKs) as input to dex2oat. |
| 49 | r_dir_file(postinstall_dexopt, vendor_overlay_file) |
Jooyung Han | 7c4f8a8 | 2023-06-09 13:26:54 +0900 | [diff] [blame] | 50 | # Vendor overlay can be found in vendor apex |
| 51 | allow postinstall_dexopt vendor_apex_metadata_file:dir { getattr search }; |
Andreas Gampe | 6d5baca | 2019-02-26 13:13:28 -0800 | [diff] [blame] | 52 | # Access to app oat directory. |
| 53 | r_dir_file(postinstall_dexopt, dalvikcache_data_file) |
| 54 | |
| 55 | # Read profile data. |
Alan Stokes | 7aa4041 | 2020-12-04 14:07:52 +0000 | [diff] [blame] | 56 | allow postinstall_dexopt { user_profile_root_file user_profile_data_file }:dir { getattr search }; |
Andreas Gampe | 6d5baca | 2019-02-26 13:13:28 -0800 | [diff] [blame] | 57 | allow postinstall_dexopt user_profile_data_file:file r_file_perms; |
| 58 | # Suppress deletion denial (we do not want to update the profile). |
| 59 | dontaudit postinstall_dexopt user_profile_data_file:file { write }; |
| 60 | |
| 61 | # Write to /data/ota(/*). Create symlinks in /data/ota(/*) |
| 62 | allow postinstall_dexopt ota_data_file:dir create_dir_perms; |
| 63 | allow postinstall_dexopt ota_data_file:file create_file_perms; |
| 64 | allow postinstall_dexopt ota_data_file:lnk_file create_file_perms; |
| 65 | |
| 66 | # Need to write .b files, which are dalvikcache_data_file, not ota_data_file. |
| 67 | # TODO: See whether we can apply ota_data_file? |
| 68 | allow postinstall_dexopt dalvikcache_data_file:dir rw_dir_perms; |
| 69 | allow postinstall_dexopt dalvikcache_data_file:file create_file_perms; |
| 70 | |
| 71 | # Allow labeling of files under /data/app/com.example/oat/ |
| 72 | # TODO: Restrict to .b suffix? |
| 73 | allow postinstall_dexopt dalvikcache_data_file:dir relabelto; |
| 74 | allow postinstall_dexopt dalvikcache_data_file:file { relabelto link }; |
| 75 | |
| 76 | # Check validity of SELinux context before use. |
| 77 | selinux_check_context(postinstall_dexopt) |
| 78 | selinux_check_access(postinstall_dexopt) |
| 79 | |
| 80 | |
| 81 | # Postinstall wants to know about our child. |
| 82 | allow postinstall_dexopt postinstall:process sigchld; |
| 83 | |
| 84 | # Allow otapreopt to use file descriptors from otapreopt_chroot. |
| 85 | # TODO: Probably we can actually close file descriptors... |
| 86 | allow postinstall_dexopt otapreopt_chroot:fd use; |
Nicolas Geoffray | 4001475 | 2019-03-01 10:05:35 +0000 | [diff] [blame] | 87 | |
| 88 | # Allow postinstall_dexopt to access the runtime feature flag properties. |
| 89 | get_prop(postinstall_dexopt, device_config_runtime_native_prop) |
| 90 | get_prop(postinstall_dexopt, device_config_runtime_native_boot_prop) |