gsid.te 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # gsid - Manager for GSI Installation
  2. type gsid, domain;
  3. type gsid_exec, exec_type, file_type, system_file_type;
  4. typeattribute gsid coredomain;
  5. init_daemon_domain(gsid)
  6. binder_use(gsid)
  7. binder_service(gsid)
  8. add_service(gsid, gsi_service)
  9. set_prop(gsid, gsid_prop)
  10. # Needed to create/delete device-mapper nodes, and read/write to them.
  11. allow gsid dm_device:chr_file rw_file_perms;
  12. allow gsid dm_device:blk_file rw_file_perms;
  13. allow gsid self:global_capability_class_set sys_admin;
  14. dontaudit gsid self:global_capability_class_set dac_override;
  15. # libfiemap_writer uses sysfs to derive the bottom of a device-mapper stacking.
  16. # This requires traversing /sys/block/dm-N/slaves/* and reading the list of
  17. # file names.
  18. allow gsid sysfs_dm:dir r_dir_perms;
  19. # Needed to read fstab, which is used to validate that system verity does not
  20. # use check_once_at_most for sdcard installs. (Note: proc_cmdline is needed
  21. # to get the A/B slot suffix).
  22. allow gsid proc_cmdline:file r_file_perms;
  23. allow gsid sysfs_dt_firmware_android:dir r_dir_perms;
  24. allow gsid sysfs_dt_firmware_android:file r_file_perms;
  25. # Needed to stat /data/gsi/* and realpath on /dev/block/by-name/*
  26. allow gsid block_device:dir r_dir_perms;
  27. # liblp queries these block alignment properties.
  28. allowxperm gsid { userdata_block_device sdcard_block_device }:blk_file ioctl {
  29. BLKIOMIN
  30. BLKALIGNOFF
  31. };
  32. # When installing images to an sdcard, gsid needs to be able to stat() the
  33. # block device. gsid also calls realpath() to remove symlinks.
  34. allow gsid mnt_media_rw_file:dir r_dir_perms;
  35. # When installing images to an sdcard, gsid must bypass sdcardfs and install
  36. # directly to vfat, which supports the FIBMAP ioctl.
  37. allow gsid vfat:dir rw_dir_perms;
  38. allow gsid vfat:file create_file_perms;
  39. allow gsid sdcard_block_device:blk_file r_file_perms;
  40. # This is needed for FIBMAP unfortunately. Oddly FIEMAP does not carry this
  41. # requirement, but the kernel does not implement FIEMAP support for VFAT.
  42. allow gsid self:global_capability_class_set sys_rawio;
  43. # gsi_tool passes the system image over the adb connection, via stdin.
  44. allow gsid adbd:fd use;
  45. # Needed when running gsi_tool through "su root" rather than adb root.
  46. allow gsid adbd:unix_stream_socket rw_socket_perms;
  47. neverallow { domain -gsid -init } gsid_prop:property_service set;
  48. # gsid needs to store images on /data, but cannot use file I/O. If it did, the
  49. # underlying blocks would be encrypted, and we couldn't mount the GSI image in
  50. # first-stage init. So instead of directly writing to /data, we:
  51. #
  52. # 1. fallocate a file large enough to hold the signed GSI
  53. # 2. extract its block layout with FIEMAP
  54. # 3. create a dm-linear device using the FIEMAP, targeting /dev/block/by-name/userdata
  55. # 4. write system_gsi into that dm device
  56. #
  57. # To make this process work, we need to unwrap the device-mapper stacking for
  58. # userdata to reach the underlying block device. To verify the result we use
  59. # stat(), which requires read access.
  60. allow gsid userdata_block_device:blk_file r_file_perms;
  61. # gsid uses /metadata/gsi to communicate GSI boot information to first-stage
  62. # init. It cannot use userdata since data cannot be decrypted during this
  63. # stage.
  64. #
  65. # gsid uses /metadata/gsi to store three files:
  66. # install_status - A short string indicating whether a GSI image is bootable.
  67. # lp_metadata - LpMetadata blob describing the block ranges on userdata
  68. # where system_gsi resides.
  69. # booted - An empty file that, if exists, indicates that a GSI is
  70. # currently running.
  71. #
  72. allow gsid metadata_file:dir search;
  73. allow gsid gsi_metadata_file:dir rw_dir_perms;
  74. allow gsid gsi_metadata_file:file create_file_perms;
  75. allow gsid gsi_data_file:dir rw_dir_perms;
  76. allow gsid gsi_data_file:file create_file_perms;
  77. allowxperm gsid gsi_data_file:file ioctl FS_IOC_FIEMAP;
  78. neverallow {
  79. domain
  80. -init
  81. -gsid
  82. -fastbootd
  83. -vold
  84. } gsi_metadata_file:dir *;
  85. neverallow {
  86. domain
  87. -init
  88. -gsid
  89. -fastbootd
  90. -vold
  91. } gsi_metadata_file:notdevfile_class_set ~{ relabelto getattr };
  92. neverallow {
  93. domain
  94. -init
  95. -gsid
  96. -fastbootd
  97. -vold
  98. } { gsi_data_file gsi_metadata_file }:notdevfile_class_set *;
  99. neverallow {
  100. domain
  101. -gsid
  102. -init
  103. } gsi_data_file:dir ~{ open create read getattr setattr search relabelto ioctl };
  104. neverallow {
  105. domain
  106. -init
  107. -gsid
  108. } gsi_data_file:dir *;
  109. neverallow {
  110. domain
  111. -gsid
  112. } gsi_data_file:notdevfile_class_set ~{ relabelto getattr };