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 | db90b91 | 2019-01-22 19:05:29 -0800 | [diff] [blame^] | 12 | |
| 13 | # Needed to create/delete device-mapper nodes, and read/write to them. |
| 14 | allow gsid dm_device:chr_file rw_file_perms; |
| 15 | allow gsid dm_device:blk_file rw_file_perms; |
| 16 | allow gsid self:global_capability_class_set sys_admin; |
| 17 | dontaudit gsid self:global_capability_class_set dac_override; |
| 18 | |
| 19 | # libfiemap_writer uses sysfs to derive the bottom of a device-mapper stacking. |
| 20 | # This requires traversing /sys/block/dm-N/slaves/* and reading the list of |
| 21 | # file names. |
| 22 | allow gsid sysfs_dm:dir r_dir_perms; |
| 23 | |
| 24 | # Needed to stat /data/gsi/* and realpath on /dev/block/by-name/* |
| 25 | allow gsid block_device:dir r_dir_perms; |
| 26 | |
| 27 | # liblp queries these block alignment properties. |
| 28 | allowxperm gsid userdata_block_device:blk_file ioctl { |
| 29 | BLKIOMIN |
| 30 | BLKALIGNOFF |
| 31 | }; |
| 32 | |
| 33 | # gsi_tool passes the system image over the adb connection, via stdin. |
| 34 | allow gsid adbd:fd use; |
| 35 | |
| 36 | # gsid needs to store images on /data, but cannot use file I/O. If it did, the |
| 37 | # underlying blocks would be encrypted, and we couldn't mount the GSI image in |
| 38 | # first-stage init. So instead of directly writing to /data, we: |
| 39 | # |
| 40 | # 1. fallocate a file large enough to hold the signed GSI |
| 41 | # 2. extract its block layout with FIEMAP |
| 42 | # 3. create a dm-linear device using the FIEMAP, targeting /dev/block/by-name/userdata |
| 43 | # 4. write system_gsi into that dm device |
| 44 | # |
| 45 | # To make this process work, we need to unwrap the device-mapper stacking for |
| 46 | # userdata to reach the underlying block device. To verify the result we use |
| 47 | # stat(), which requires read access. |
| 48 | allow gsid userdata_block_device:blk_file r_file_perms; |
| 49 | |
| 50 | # gsid uses /metadata/gsi to communicate GSI boot information to first-stage |
| 51 | # init. It cannot use userdata since data cannot be decrypted during this |
| 52 | # stage. |
| 53 | # |
| 54 | # gsid uses /metadata/gsi to store three files: |
| 55 | # install_status - A short string indicating whether a GSI image is bootable. |
| 56 | # lp_metadata - LpMetadata blob describing the block ranges on userdata |
| 57 | # where system_gsi resides. |
| 58 | # booted - An empty file that, if exists, indicates that a GSI is |
| 59 | # currently running. |
| 60 | # |
| 61 | allow gsid metadata_file:dir search; |
| 62 | allow gsid gsi_metadata_file:dir rw_dir_perms; |
| 63 | allow gsid gsi_metadata_file:file create_file_perms; |
| 64 | |
| 65 | allow gsid gsi_data_file:dir rw_dir_perms; |
| 66 | allow gsid gsi_data_file:file create_file_perms; |
| 67 | allowxperm gsid gsi_data_file:file ioctl FS_IOC_FIEMAP; |
| 68 | |
| 69 | neverallow { |
| 70 | domain |
| 71 | -init |
| 72 | -gsid |
| 73 | -fastbootd |
| 74 | -vold |
| 75 | } gsi_metadata_file:dir *; |
| 76 | |
| 77 | neverallow { |
| 78 | domain |
| 79 | -init |
| 80 | -gsid |
| 81 | -fastbootd |
| 82 | -vold |
| 83 | } gsi_metadata_file:notdevfile_class_set ~{ relabelto getattr }; |
| 84 | |
| 85 | neverallow { |
| 86 | domain |
| 87 | -init |
| 88 | -gsid |
| 89 | -fastbootd |
| 90 | -vold |
| 91 | } { gsi_data_file gsi_metadata_file }:notdevfile_class_set *; |
| 92 | |
| 93 | neverallow { |
| 94 | domain |
| 95 | -gsid |
| 96 | } gsi_data_file:dir ~{ open create read getattr setattr search relabelto ioctl }; |
| 97 | |
| 98 | neverallow { |
| 99 | domain |
| 100 | -init |
| 101 | -gsid |
| 102 | } gsi_data_file:dir *; |
| 103 | |
| 104 | neverallow { |
| 105 | domain |
| 106 | -gsid |
| 107 | } gsi_data_file:notdevfile_class_set ~{ relabelto getattr }; |