Tri Vo | bc8dc3a | 2019-05-26 13:17:08 -0700 | [diff] [blame^] | 1 | typeattribute apexd coredomain; |
| 2 | |
| 3 | init_daemon_domain(apexd) |
| 4 | |
| 5 | # Allow creating, reading and writing of APEX files/dirs in the APEX data dir |
| 6 | allow apexd apex_data_file:dir create_dir_perms; |
| 7 | allow apexd apex_data_file:file create_file_perms; |
| 8 | |
| 9 | # Allow creating, reading and writing of APEX files/dirs in the APEX metadata dir |
| 10 | allow apexd metadata_file:dir search; |
| 11 | allow apexd apex_metadata_file:dir create_dir_perms; |
| 12 | allow apexd apex_metadata_file:file create_file_perms; |
| 13 | |
| 14 | # allow apexd to create loop devices with /dev/loop-control |
| 15 | allow apexd loop_control_device:chr_file rw_file_perms; |
| 16 | # allow apexd to access loop devices |
| 17 | allow apexd loop_device:blk_file rw_file_perms; |
| 18 | allowxperm apexd loop_device:blk_file ioctl { |
| 19 | LOOP_GET_STATUS64 |
| 20 | LOOP_SET_STATUS64 |
| 21 | LOOP_SET_FD |
| 22 | LOOP_SET_BLOCK_SIZE |
| 23 | LOOP_SET_DIRECT_IO |
| 24 | LOOP_CLR_FD |
| 25 | BLKFLSBUF |
| 26 | }; |
| 27 | # allow apexd to access /dev/block |
| 28 | allow apexd block_device:dir r_dir_perms; |
| 29 | |
| 30 | # allow apexd to access /dev/block/dm-* (device-mapper entries) |
| 31 | allow apexd dm_device:chr_file rw_file_perms; |
| 32 | allow apexd dm_device:blk_file rw_file_perms; |
| 33 | |
| 34 | # sys_admin is required to access the device-mapper and mount |
| 35 | allow apexd self:global_capability_class_set sys_admin; |
| 36 | |
| 37 | # allow apexd to create a mount point in /apex |
| 38 | allow apexd apex_mnt_dir:dir create_dir_perms; |
| 39 | # allow apexd to mount in /apex |
| 40 | allow apexd apex_mnt_dir:filesystem { mount unmount }; |
| 41 | allow apexd apex_mnt_dir:dir mounton; |
| 42 | # allow apexd to create symlinks in /apex |
| 43 | allow apexd apex_mnt_dir:lnk_file create_file_perms; |
| 44 | # allow apexd to unlink apex files in /data/apex/active |
| 45 | # note that apexd won't be able to unlink files in /data/app-staging/session_XXXX, |
| 46 | # because it doesn't have write permission for staging_data_file object. |
| 47 | allow apexd staging_data_file:file unlink; |
| 48 | |
| 49 | # allow apexd to read files from /data/app-staging and hardlink them to /data/apex. |
| 50 | allow apexd staging_data_file:dir r_dir_perms; |
| 51 | allow apexd staging_data_file:file { r_file_perms link }; |
| 52 | |
| 53 | # allow apexd to read files from /vendor/apex |
| 54 | |
| 55 | # Unmount and mount filesystems |
| 56 | allow apexd labeledfs:filesystem { mount unmount }; |
| 57 | |
| 58 | # /sys directory tree traversal |
| 59 | allow apexd sysfs_type:dir search; |
| 60 | # Configure read-ahead of dm-verity and loop devices |
| 61 | # for dm-X |
| 62 | allow apexd sysfs_dm:dir r_dir_perms; |
| 63 | allow apexd sysfs_dm:file rw_file_perms; |
| 64 | # for loopX |
| 65 | allow apexd sysfs_loop:dir r_dir_perms; |
| 66 | allow apexd sysfs_loop:file rw_file_perms; |
| 67 | |
| 68 | # Spawning a libbinder thread results in a dac_override deny, |
| 69 | # /dev/cpuset/tasks is owned by system. |
| 70 | # |
| 71 | # See b/35323867#comment3 |
| 72 | dontaudit apexd self:global_capability_class_set { dac_override dac_read_search }; |
| 73 | |
| 74 | # Allow apexd to log to the kernel. |
| 75 | allow apexd kmsg_device:chr_file w_file_perms; |
| 76 | |
| 77 | # Allow apexd to reboot device. Required for rollbacks of apexes that are |
| 78 | # not covered by rollback manager. |
| 79 | set_prop(apexd, powerctl_prop) |
| 80 | |
| 81 | # Find the vold service, and call into vold to manage FS checkpoints |
| 82 | allow apexd vold_service:service_manager find; |
| 83 | binder_call(apexd, vold) |
| 84 | |
| 85 | # Apex pre- & post-install permission. |
| 86 | |
| 87 | # Allow self-execute for the fork mount helper. |
| 88 | allow apexd apexd_exec:file execute_no_trans; |
| 89 | |
| 90 | # Unshare and make / private so that hooks cannot influence the |
| 91 | # running system. |
| 92 | allow apexd rootfs:dir mounton; |
| 93 | |
| 94 | # Allow to execute shell for pre- and postinstall scripts. A transition |
| 95 | # rule is required, thus restricted to execute and not execute_no_trans. |
| 96 | allow apexd shell_exec:file { r_file_perms execute }; |
| 97 | |
| 98 | # apexd is using bootstrap bionic |
| 99 | allow apexd system_bootstrap_lib_file:dir r_dir_perms; |
| 100 | allow apexd system_bootstrap_lib_file:file { execute read open getattr map }; |
| 101 | |
| 102 | # Allow transition to ART APEX preinstall domain. |
| 103 | domain_auto_trans(apexd, art_apex_preinstall_exec, art_apex_preinstall) |
| 104 | # Allow transition to ART APEX postinstall domain. |
| 105 | domain_auto_trans(apexd, art_apex_postinstall_exec, art_apex_postinstall) |
| 106 | |
| 107 | # Allow transition to test APEX preinstall domain. |
| 108 | userdebug_or_eng(` |
| 109 | domain_auto_trans(apexd, apex_test_prepostinstall_exec, apex_test_prepostinstall) |
| 110 | ') |
| 111 | |
| 112 | neverallow { domain -apexd -init } apex_data_file:dir no_w_dir_perms; |
| 113 | neverallow { domain -apexd -init } apex_metadata_file:dir no_w_dir_perms; |
| 114 | neverallow { domain -apexd -init -kernel } apex_data_file:file no_w_file_perms; |
| 115 | neverallow { domain -apexd -init -kernel } apex_metadata_file:file no_w_file_perms; |
| 116 | neverallow { domain -apexd } apex_mnt_dir:lnk_file no_w_file_perms; |