David Anderson | 6d53efc | 2019-01-14 14:38:17 -0800 | [diff] [blame] | 1 | # gsid - Manager for GSI Installation |
| 2 | |
| 3 | type gsid, domain; |
| 4 | type gsid_exec, exec_type, file_type, system_file_type; |
| 5 | typeattribute gsid coredomain; |
| 6 | |
| 7 | init_daemon_domain(gsid) |
| 8 | |
| 9 | binder_use(gsid) |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 10 | binder_service(gsid) |
David Anderson | 6d53efc | 2019-01-14 14:38:17 -0800 | [diff] [blame] | 11 | add_service(gsid, gsi_service) |
David Anderson | 8fe3c74 | 2019-02-07 13:14:20 -0800 | [diff] [blame] | 12 | set_prop(gsid, gsid_prop) |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 13 | |
| 14 | # Needed to create/delete device-mapper nodes, and read/write to them. |
| 15 | allow gsid dm_device:chr_file rw_file_perms; |
| 16 | allow gsid dm_device:blk_file rw_file_perms; |
| 17 | allow gsid self:global_capability_class_set sys_admin; |
| 18 | dontaudit gsid self:global_capability_class_set dac_override; |
| 19 | |
David Anderson | 53ea513 | 2019-07-08 18:59:58 -0700 | [diff] [blame] | 20 | # On FBE devices (not using dm-default-key), gsid will use loop devices to map |
| 21 | # images rather than device-mapper. |
| 22 | allow gsid loop_control_device:chr_file rw_file_perms; |
| 23 | allow gsid loop_device:blk_file rw_file_perms; |
| 24 | allowxperm gsid loop_device:blk_file ioctl { |
| 25 | LOOP_GET_STATUS64 |
| 26 | LOOP_SET_STATUS64 |
| 27 | LOOP_SET_FD |
| 28 | LOOP_SET_BLOCK_SIZE |
| 29 | LOOP_SET_DIRECT_IO |
| 30 | LOOP_CLR_FD |
| 31 | BLKFLSBUF |
| 32 | }; |
| 33 | |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 34 | # libfiemap_writer uses sysfs to derive the bottom of a device-mapper stacking. |
| 35 | # This requires traversing /sys/block/dm-N/slaves/* and reading the list of |
| 36 | # file names. |
David Anderson | 95fbedd | 2019-06-07 14:28:37 -0700 | [diff] [blame] | 37 | r_dir_file(gsid, sysfs_dm) |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 38 | |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 39 | # Needed to read fstab, which is used to validate that system verity does not |
| 40 | # use check_once_at_most for sdcard installs. (Note: proc_cmdline is needed |
| 41 | # to get the A/B slot suffix). |
| 42 | allow gsid proc_cmdline:file r_file_perms; |
| 43 | allow gsid sysfs_dt_firmware_android:dir r_dir_perms; |
| 44 | allow gsid sysfs_dt_firmware_android:file r_file_perms; |
| 45 | |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 46 | # Needed to stat /data/gsi/* and realpath on /dev/block/by-name/* |
| 47 | allow gsid block_device:dir r_dir_perms; |
| 48 | |
| 49 | # liblp queries these block alignment properties. |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 50 | allowxperm gsid { userdata_block_device sdcard_block_device }:blk_file ioctl { |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 51 | BLKIOMIN |
| 52 | BLKALIGNOFF |
| 53 | }; |
| 54 | |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 55 | # When installing images to an sdcard, gsid needs to be able to stat() the |
| 56 | # block device. gsid also calls realpath() to remove symlinks. |
| 57 | allow gsid mnt_media_rw_file:dir r_dir_perms; |
| 58 | |
| 59 | # When installing images to an sdcard, gsid must bypass sdcardfs and install |
| 60 | # directly to vfat, which supports the FIBMAP ioctl. |
| 61 | allow gsid vfat:dir rw_dir_perms; |
| 62 | allow gsid vfat:file create_file_perms; |
| 63 | allow gsid sdcard_block_device:blk_file r_file_perms; |
| 64 | # This is needed for FIBMAP unfortunately. Oddly FIEMAP does not carry this |
| 65 | # requirement, but the kernel does not implement FIEMAP support for VFAT. |
| 66 | allow gsid self:global_capability_class_set sys_rawio; |
| 67 | |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 68 | # gsi_tool passes the system image over the adb connection, via stdin. |
| 69 | allow gsid adbd:fd use; |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 70 | # Needed when running gsi_tool through "su root" rather than adb root. |
| 71 | allow gsid adbd:unix_stream_socket rw_socket_perms; |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 72 | |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 73 | neverallow { |
| 74 | domain |
| 75 | -gsid |
| 76 | -init |
| 77 | -update_engine_common |
| 78 | } gsid_prop:property_service set; |
David Anderson | 8fe3c74 | 2019-02-07 13:14:20 -0800 | [diff] [blame] | 79 | |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 80 | # gsid needs to store images on /data, but cannot use file I/O. If it did, the |
| 81 | # underlying blocks would be encrypted, and we couldn't mount the GSI image in |
| 82 | # first-stage init. So instead of directly writing to /data, we: |
| 83 | # |
| 84 | # 1. fallocate a file large enough to hold the signed GSI |
| 85 | # 2. extract its block layout with FIEMAP |
| 86 | # 3. create a dm-linear device using the FIEMAP, targeting /dev/block/by-name/userdata |
| 87 | # 4. write system_gsi into that dm device |
| 88 | # |
| 89 | # To make this process work, we need to unwrap the device-mapper stacking for |
| 90 | # userdata to reach the underlying block device. To verify the result we use |
| 91 | # stat(), which requires read access. |
| 92 | allow gsid userdata_block_device:blk_file r_file_perms; |
| 93 | |
| 94 | # gsid uses /metadata/gsi to communicate GSI boot information to first-stage |
| 95 | # init. It cannot use userdata since data cannot be decrypted during this |
| 96 | # stage. |
| 97 | # |
| 98 | # gsid uses /metadata/gsi to store three files: |
| 99 | # install_status - A short string indicating whether a GSI image is bootable. |
| 100 | # lp_metadata - LpMetadata blob describing the block ranges on userdata |
| 101 | # where system_gsi resides. |
| 102 | # booted - An empty file that, if exists, indicates that a GSI is |
| 103 | # currently running. |
| 104 | # |
David Anderson | 53ea513 | 2019-07-08 18:59:58 -0700 | [diff] [blame] | 105 | allow gsid metadata_file:dir { search getattr }; |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 106 | allow gsid { |
| 107 | gsi_metadata_file |
| 108 | ota_metadata_file |
| 109 | }:dir rw_dir_perms; |
| 110 | allow gsid { |
| 111 | gsi_metadata_file |
| 112 | ota_metadata_file |
| 113 | }:file create_file_perms; |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 114 | |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 115 | allow gsid { |
| 116 | gsi_data_file |
| 117 | ota_image_data_file |
| 118 | }:dir rw_dir_perms; |
| 119 | allow gsid { |
| 120 | gsi_data_file |
| 121 | ota_image_data_file |
| 122 | }:file create_file_perms; |
| 123 | allowxperm gsid { |
| 124 | gsi_data_file |
| 125 | ota_image_data_file |
| 126 | }:file ioctl FS_IOC_FIEMAP; |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 127 | |
| 128 | neverallow { |
| 129 | domain |
| 130 | -init |
| 131 | -gsid |
| 132 | -fastbootd |
| 133 | -vold |
| 134 | } gsi_metadata_file:dir *; |
| 135 | |
| 136 | neverallow { |
| 137 | domain |
| 138 | -init |
| 139 | -gsid |
| 140 | -fastbootd |
| 141 | -vold |
| 142 | } gsi_metadata_file:notdevfile_class_set ~{ relabelto getattr }; |
| 143 | |
| 144 | neverallow { |
| 145 | domain |
| 146 | -init |
| 147 | -gsid |
| 148 | -fastbootd |
| 149 | -vold |
| 150 | } { gsi_data_file gsi_metadata_file }:notdevfile_class_set *; |
| 151 | |
| 152 | neverallow { |
| 153 | domain |
| 154 | -gsid |
David Anderson | 0b1094c | 2019-05-23 13:44:22 -0700 | [diff] [blame] | 155 | -init |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 156 | } gsi_data_file:dir ~{ open create read getattr setattr search relabelto ioctl }; |
| 157 | |
| 158 | neverallow { |
| 159 | domain |
| 160 | -init |
| 161 | -gsid |
| 162 | } gsi_data_file:dir *; |
| 163 | |
| 164 | neverallow { |
| 165 | domain |
| 166 | -gsid |
| 167 | } gsi_data_file:notdevfile_class_set ~{ relabelto getattr }; |