blob: 3d91eb80c6f1516ffde2658c8d1baed0c7dbf8e6 [file] [log] [blame]
David Anderson6d53efc2019-01-14 14:38:17 -08001# gsid - Manager for GSI Installation
2
3type gsid, domain;
4type gsid_exec, exec_type, file_type, system_file_type;
5typeattribute gsid coredomain;
6
7init_daemon_domain(gsid)
8
9binder_use(gsid)
David Andersondb90b912019-01-22 19:05:29 -080010binder_service(gsid)
David Anderson6d53efc2019-01-14 14:38:17 -080011add_service(gsid, gsi_service)
David Anderson8fe3c742019-02-07 13:14:20 -080012set_prop(gsid, gsid_prop)
David Andersondb90b912019-01-22 19:05:29 -080013
14# Needed to create/delete device-mapper nodes, and read/write to them.
15allow gsid dm_device:chr_file rw_file_perms;
16allow gsid dm_device:blk_file rw_file_perms;
17allow gsid self:global_capability_class_set sys_admin;
18dontaudit gsid self:global_capability_class_set dac_override;
19
David Anderson53ea5132019-07-08 18:59:58 -070020# On FBE devices (not using dm-default-key), gsid will use loop devices to map
21# images rather than device-mapper.
22allow gsid loop_control_device:chr_file rw_file_perms;
23allow gsid loop_device:blk_file rw_file_perms;
24allowxperm 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 Andersondb90b912019-01-22 19:05:29 -080034# 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 Anderson95fbedd2019-06-07 14:28:37 -070037r_dir_file(gsid, sysfs_dm)
David Andersondb90b912019-01-22 19:05:29 -080038
David Andersond2a70f12019-12-10 16:23:59 -080039# libfiemap_writer needs to read /sys/fs/f2fs/<dev>/features to determine
40# whether pin_file support is enabled.
41r_dir_file(gsid, sysfs_fs_f2fs)
42
David Anderson6557d872019-03-15 16:41:15 -070043# Needed to read fstab, which is used to validate that system verity does not
44# use check_once_at_most for sdcard installs. (Note: proc_cmdline is needed
45# to get the A/B slot suffix).
46allow gsid proc_cmdline:file r_file_perms;
47allow gsid sysfs_dt_firmware_android:dir r_dir_perms;
48allow gsid sysfs_dt_firmware_android:file r_file_perms;
49
David Andersondb90b912019-01-22 19:05:29 -080050# Needed to stat /data/gsi/* and realpath on /dev/block/by-name/*
51allow gsid block_device:dir r_dir_perms;
52
53# liblp queries these block alignment properties.
David Anderson6557d872019-03-15 16:41:15 -070054allowxperm gsid { userdata_block_device sdcard_block_device }:blk_file ioctl {
David Andersondb90b912019-01-22 19:05:29 -080055 BLKIOMIN
56 BLKALIGNOFF
57};
58
David Anderson6557d872019-03-15 16:41:15 -070059# When installing images to an sdcard, gsid needs to be able to stat() the
60# block device. gsid also calls realpath() to remove symlinks.
61allow gsid mnt_media_rw_file:dir r_dir_perms;
62
63# When installing images to an sdcard, gsid must bypass sdcardfs and install
64# directly to vfat, which supports the FIBMAP ioctl.
65allow gsid vfat:dir rw_dir_perms;
66allow gsid vfat:file create_file_perms;
67allow gsid sdcard_block_device:blk_file r_file_perms;
68# This is needed for FIBMAP unfortunately. Oddly FIEMAP does not carry this
69# requirement, but the kernel does not implement FIEMAP support for VFAT.
70allow gsid self:global_capability_class_set sys_rawio;
71
Yo Chiang45fb38b2020-08-28 22:07:09 +080072# Allow rules for gsi_tool.
73userdebug_or_eng(`
74 # gsi_tool passes the system image over the adb connection, via stdin.
75 allow gsid adbd:fd use;
76 # Needed when running gsi_tool through "su root" rather than adb root.
77 allow gsid adbd:unix_stream_socket rw_socket_perms;
78 # gsi_tool passes a FIFO to gsid if invoked with pipe redirection.
79 allow gsid { shell su }:fifo_file r_file_perms;
Yo Chiang04429cc2020-08-31 16:30:55 +080080 # Allow installing images from /storage/emulated/...
81 allow gsid sdcard_type:file r_file_perms;
Yo Chiang45fb38b2020-08-28 22:07:09 +080082')
David Andersondb90b912019-01-22 19:05:29 -080083
Yifan Hong07a99e12019-08-07 13:01:15 -070084neverallow {
85 domain
86 -gsid
87 -init
88 -update_engine_common
David Andersonb45bbe22019-10-17 19:07:52 -070089 -recovery
90 -fastbootd
Yifan Hong07a99e12019-08-07 13:01:15 -070091} gsid_prop:property_service set;
David Anderson8fe3c742019-02-07 13:14:20 -080092
David Andersondb90b912019-01-22 19:05:29 -080093# gsid needs to store images on /data, but cannot use file I/O. If it did, the
94# underlying blocks would be encrypted, and we couldn't mount the GSI image in
95# first-stage init. So instead of directly writing to /data, we:
96#
97# 1. fallocate a file large enough to hold the signed GSI
98# 2. extract its block layout with FIEMAP
99# 3. create a dm-linear device using the FIEMAP, targeting /dev/block/by-name/userdata
100# 4. write system_gsi into that dm device
101#
102# To make this process work, we need to unwrap the device-mapper stacking for
103# userdata to reach the underlying block device. To verify the result we use
104# stat(), which requires read access.
105allow gsid userdata_block_device:blk_file r_file_perms;
106
107# gsid uses /metadata/gsi to communicate GSI boot information to first-stage
108# init. It cannot use userdata since data cannot be decrypted during this
109# stage.
110#
111# gsid uses /metadata/gsi to store three files:
112# install_status - A short string indicating whether a GSI image is bootable.
113# lp_metadata - LpMetadata blob describing the block ranges on userdata
114# where system_gsi resides.
115# booted - An empty file that, if exists, indicates that a GSI is
116# currently running.
117#
David Anderson53ea5132019-07-08 18:59:58 -0700118allow gsid metadata_file:dir { search getattr };
Yifan Hong07a99e12019-08-07 13:01:15 -0700119allow gsid {
120 gsi_metadata_file
Howard Chene9789472020-01-17 14:19:56 +0800121}:dir create_dir_perms;
122
123allow gsid {
Yifan Hong07a99e12019-08-07 13:01:15 -0700124 ota_metadata_file
125}:dir rw_dir_perms;
Howard Chene9789472020-01-17 14:19:56 +0800126
Yifan Hong07a99e12019-08-07 13:01:15 -0700127allow gsid {
128 gsi_metadata_file
129 ota_metadata_file
130}:file create_file_perms;
David Andersondb90b912019-01-22 19:05:29 -0800131
Yifan Hong07a99e12019-08-07 13:01:15 -0700132allow gsid {
133 gsi_data_file
134 ota_image_data_file
135}:dir rw_dir_perms;
136allow gsid {
137 gsi_data_file
138 ota_image_data_file
139}:file create_file_perms;
140allowxperm gsid {
141 gsi_data_file
142 ota_image_data_file
Yo Chianga5d25622020-08-19 14:28:06 +0800143}:file ioctl {
144 FS_IOC_FIEMAP
145 FS_IOC_GETFLAGS
146};
David Andersondb90b912019-01-22 19:05:29 -0800147
Howard Chen389bc7b2020-02-26 17:19:10 +0800148allow gsid system_server:binder call;
149
David Andersondb90b912019-01-22 19:05:29 -0800150neverallow {
151 domain
152 -init
153 -gsid
154 -fastbootd
David Andersonb45bbe22019-10-17 19:07:52 -0700155 -recovery
David Andersondb90b912019-01-22 19:05:29 -0800156 -vold
157} gsi_metadata_file:dir *;
158
159neverallow {
160 domain
161 -init
162 -gsid
163 -fastbootd
164 -vold
165} gsi_metadata_file:notdevfile_class_set ~{ relabelto getattr };
166
167neverallow {
168 domain
169 -init
170 -gsid
171 -fastbootd
172 -vold
173} { gsi_data_file gsi_metadata_file }:notdevfile_class_set *;
174
175neverallow {
176 domain
177 -gsid
David Anderson0b1094c2019-05-23 13:44:22 -0700178 -init
David Andersondb90b912019-01-22 19:05:29 -0800179} gsi_data_file:dir ~{ open create read getattr setattr search relabelto ioctl };
180
181neverallow {
182 domain
183 -init
184 -gsid
185} gsi_data_file:dir *;
186
187neverallow {
188 domain
189 -gsid
190} gsi_data_file:notdevfile_class_set ~{ relabelto getattr };