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) |
Yo Chiang | ffe786e | 2020-10-07 13:59:52 +0800 | [diff] [blame] | 12 | |
| 13 | # Manage DSU metadata encryption key through vold. |
| 14 | allow gsid vold_service:service_manager find; |
| 15 | binder_call(gsid, vold) |
| 16 | |
David Anderson | 8fe3c74 | 2019-02-07 13:14:20 -0800 | [diff] [blame] | 17 | set_prop(gsid, gsid_prop) |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 18 | |
| 19 | # Needed to create/delete device-mapper nodes, and read/write to them. |
| 20 | allow gsid dm_device:chr_file rw_file_perms; |
| 21 | allow gsid dm_device:blk_file rw_file_perms; |
| 22 | allow gsid self:global_capability_class_set sys_admin; |
| 23 | dontaudit gsid self:global_capability_class_set dac_override; |
| 24 | |
David Anderson | 53ea513 | 2019-07-08 18:59:58 -0700 | [diff] [blame] | 25 | # On FBE devices (not using dm-default-key), gsid will use loop devices to map |
| 26 | # images rather than device-mapper. |
| 27 | allow gsid loop_control_device:chr_file rw_file_perms; |
| 28 | allow gsid loop_device:blk_file rw_file_perms; |
| 29 | allowxperm gsid loop_device:blk_file ioctl { |
| 30 | LOOP_GET_STATUS64 |
| 31 | LOOP_SET_STATUS64 |
| 32 | LOOP_SET_FD |
| 33 | LOOP_SET_BLOCK_SIZE |
| 34 | LOOP_SET_DIRECT_IO |
| 35 | LOOP_CLR_FD |
| 36 | BLKFLSBUF |
| 37 | }; |
| 38 | |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 39 | # libfiemap_writer uses sysfs to derive the bottom of a device-mapper stacking. |
| 40 | # This requires traversing /sys/block/dm-N/slaves/* and reading the list of |
| 41 | # file names. |
David Anderson | 95fbedd | 2019-06-07 14:28:37 -0700 | [diff] [blame] | 42 | r_dir_file(gsid, sysfs_dm) |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 43 | |
David Anderson | d2a70f1 | 2019-12-10 16:23:59 -0800 | [diff] [blame] | 44 | # libfiemap_writer needs to read /sys/fs/f2fs/<dev>/features to determine |
| 45 | # whether pin_file support is enabled. |
| 46 | r_dir_file(gsid, sysfs_fs_f2fs) |
| 47 | |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 48 | # Needed to read fstab, which is used to validate that system verity does not |
| 49 | # use check_once_at_most for sdcard installs. (Note: proc_cmdline is needed |
| 50 | # to get the A/B slot suffix). |
| 51 | allow gsid proc_cmdline:file r_file_perms; |
| 52 | allow gsid sysfs_dt_firmware_android:dir r_dir_perms; |
| 53 | allow gsid sysfs_dt_firmware_android:file r_file_perms; |
| 54 | |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 55 | # Needed to stat /data/gsi/* and realpath on /dev/block/by-name/* |
| 56 | allow gsid block_device:dir r_dir_perms; |
| 57 | |
| 58 | # liblp queries these block alignment properties. |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 59 | allowxperm gsid { userdata_block_device sdcard_block_device }:blk_file ioctl { |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 60 | BLKIOMIN |
| 61 | BLKALIGNOFF |
| 62 | }; |
| 63 | |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 64 | # When installing images to an sdcard, gsid needs to be able to stat() the |
| 65 | # block device. gsid also calls realpath() to remove symlinks. |
| 66 | allow gsid mnt_media_rw_file:dir r_dir_perms; |
Howard Chen | 4db8cbd | 2021-01-14 15:27:50 +0800 | [diff] [blame] | 67 | allow gsid mnt_media_rw_stub_file:dir r_dir_perms; |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 68 | |
| 69 | # When installing images to an sdcard, gsid must bypass sdcardfs and install |
| 70 | # directly to vfat, which supports the FIBMAP ioctl. |
Howard Chen | 4db8cbd | 2021-01-14 15:27:50 +0800 | [diff] [blame] | 71 | allow gsid vfat:dir create_dir_perms; |
David Anderson | 6557d87 | 2019-03-15 16:41:15 -0700 | [diff] [blame] | 72 | allow gsid vfat:file create_file_perms; |
| 73 | allow gsid sdcard_block_device:blk_file r_file_perms; |
| 74 | # This is needed for FIBMAP unfortunately. Oddly FIEMAP does not carry this |
| 75 | # requirement, but the kernel does not implement FIEMAP support for VFAT. |
| 76 | allow gsid self:global_capability_class_set sys_rawio; |
| 77 | |
Yo Chiang | 45fb38b | 2020-08-28 22:07:09 +0800 | [diff] [blame] | 78 | # Allow rules for gsi_tool. |
| 79 | userdebug_or_eng(` |
| 80 | # gsi_tool passes the system image over the adb connection, via stdin. |
| 81 | allow gsid adbd:fd use; |
| 82 | # Needed when running gsi_tool through "su root" rather than adb root. |
| 83 | allow gsid adbd:unix_stream_socket rw_socket_perms; |
| 84 | # gsi_tool passes a FIFO to gsid if invoked with pipe redirection. |
| 85 | allow gsid { shell su }:fifo_file r_file_perms; |
Yo Chiang | 04429cc | 2020-08-31 16:30:55 +0800 | [diff] [blame] | 86 | # Allow installing images from /storage/emulated/... |
| 87 | allow gsid sdcard_type:file r_file_perms; |
Yo Chiang | 45fb38b | 2020-08-28 22:07:09 +0800 | [diff] [blame] | 88 | ') |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 89 | |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 90 | neverallow { |
| 91 | domain |
| 92 | -gsid |
| 93 | -init |
| 94 | -update_engine_common |
David Anderson | b45bbe2 | 2019-10-17 19:07:52 -0700 | [diff] [blame] | 95 | -recovery |
| 96 | -fastbootd |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 97 | } gsid_prop:property_service set; |
David Anderson | 8fe3c74 | 2019-02-07 13:14:20 -0800 | [diff] [blame] | 98 | |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 99 | # gsid needs to store images on /data, but cannot use file I/O. If it did, the |
| 100 | # underlying blocks would be encrypted, and we couldn't mount the GSI image in |
| 101 | # first-stage init. So instead of directly writing to /data, we: |
| 102 | # |
| 103 | # 1. fallocate a file large enough to hold the signed GSI |
| 104 | # 2. extract its block layout with FIEMAP |
| 105 | # 3. create a dm-linear device using the FIEMAP, targeting /dev/block/by-name/userdata |
| 106 | # 4. write system_gsi into that dm device |
| 107 | # |
| 108 | # To make this process work, we need to unwrap the device-mapper stacking for |
| 109 | # userdata to reach the underlying block device. To verify the result we use |
| 110 | # stat(), which requires read access. |
| 111 | allow gsid userdata_block_device:blk_file r_file_perms; |
| 112 | |
| 113 | # gsid uses /metadata/gsi to communicate GSI boot information to first-stage |
| 114 | # init. It cannot use userdata since data cannot be decrypted during this |
| 115 | # stage. |
| 116 | # |
| 117 | # gsid uses /metadata/gsi to store three files: |
| 118 | # install_status - A short string indicating whether a GSI image is bootable. |
| 119 | # lp_metadata - LpMetadata blob describing the block ranges on userdata |
| 120 | # where system_gsi resides. |
| 121 | # booted - An empty file that, if exists, indicates that a GSI is |
| 122 | # currently running. |
| 123 | # |
David Anderson | 53ea513 | 2019-07-08 18:59:58 -0700 | [diff] [blame] | 124 | allow gsid metadata_file:dir { search getattr }; |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 125 | allow gsid { |
Yi-Yo Chiang | 806898d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 126 | gsi_metadata_file_type |
Howard Chen | e978947 | 2020-01-17 14:19:56 +0800 | [diff] [blame] | 127 | }:dir create_dir_perms; |
| 128 | |
| 129 | allow gsid { |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 130 | ota_metadata_file |
| 131 | }:dir rw_dir_perms; |
Howard Chen | e978947 | 2020-01-17 14:19:56 +0800 | [diff] [blame] | 132 | |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 133 | allow gsid { |
Yi-Yo Chiang | 806898d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 134 | gsi_metadata_file_type |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 135 | ota_metadata_file |
| 136 | }:file create_file_perms; |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 137 | |
Yi-Yo Chiang | 806898d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 138 | # Allow restorecon to fix context of gsi_public_metadata_file. |
| 139 | allow gsid file_contexts_file:file r_file_perms; |
| 140 | allow gsid gsi_metadata_file:file relabelfrom; |
| 141 | allow gsid gsi_public_metadata_file:file relabelto; |
| 142 | |
Yifan Hong | 07a99e1 | 2019-08-07 13:01:15 -0700 | [diff] [blame] | 143 | allow gsid { |
| 144 | gsi_data_file |
| 145 | ota_image_data_file |
| 146 | }:dir rw_dir_perms; |
| 147 | allow gsid { |
| 148 | gsi_data_file |
| 149 | ota_image_data_file |
| 150 | }:file create_file_perms; |
| 151 | allowxperm gsid { |
| 152 | gsi_data_file |
| 153 | ota_image_data_file |
Yo Chiang | a5d2562 | 2020-08-19 14:28:06 +0800 | [diff] [blame] | 154 | }:file ioctl { |
| 155 | FS_IOC_FIEMAP |
| 156 | FS_IOC_GETFLAGS |
| 157 | }; |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 158 | |
Howard Chen | 389bc7b | 2020-02-26 17:19:10 +0800 | [diff] [blame] | 159 | allow gsid system_server:binder call; |
| 160 | |
Yi-Yo Chiang | 806898d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 161 | # Prevent most processes from writing to gsi_metadata_file_type, but allow |
| 162 | # adding rules for path resolution of gsi_public_metadata_file and reading |
| 163 | # gsi_public_metadata_file. |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 164 | neverallow { |
| 165 | domain |
| 166 | -init |
| 167 | -gsid |
| 168 | -fastbootd |
Yi-Yo Chiang | 806898d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 169 | } gsi_metadata_file_type:dir no_w_dir_perms; |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 170 | |
| 171 | neverallow { |
| 172 | domain |
| 173 | -init |
| 174 | -gsid |
| 175 | -fastbootd |
Yi-Yo Chiang | 806898d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 176 | } { gsi_metadata_file_type -gsi_public_metadata_file }:file_class_set *; |
| 177 | |
| 178 | neverallow { |
| 179 | domain |
| 180 | -init |
| 181 | -gsid |
| 182 | -fastbootd |
Yi-Yo Chiang | 806898d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 183 | } gsi_public_metadata_file:file_class_set ~{ r_file_perms }; |
| 184 | |
| 185 | # Prevent apps from accessing gsi_metadata_file_type. |
Yi-Yo Chiang | 694ab79 | 2021-04-09 13:39:20 +0800 | [diff] [blame^] | 186 | neverallow { |
| 187 | appdomain |
| 188 | -shell |
| 189 | } gsi_metadata_file_type:dir_file_class_set *; |
Yi-Yo Chiang | 32e1f10 | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 190 | |
| 191 | neverallow { |
| 192 | domain |
| 193 | -init |
| 194 | -gsid |
Yi-Yo Chiang | 5854941 | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 195 | } gsi_data_file:dir_file_class_set *; |
David Anderson | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame] | 196 | |
| 197 | neverallow { |
| 198 | domain |
| 199 | -gsid |
Yi-Yo Chiang | 6ef4d9d | 2021-03-22 13:46:12 +0800 | [diff] [blame] | 200 | } gsi_data_file:file_class_set ~{ relabelto getattr }; |