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