blob: 0c2e50c78017f344870e27adbc1433d40b04b1b5 [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 Andersondb90b912019-01-22 19:05:29 -080012
13# Needed to create/delete device-mapper nodes, and read/write to them.
14allow gsid dm_device:chr_file rw_file_perms;
15allow gsid dm_device:blk_file rw_file_perms;
16allow gsid self:global_capability_class_set sys_admin;
17dontaudit 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.
22allow gsid sysfs_dm:dir r_dir_perms;
23
24# Needed to stat /data/gsi/* and realpath on /dev/block/by-name/*
25allow gsid block_device:dir r_dir_perms;
26
27# liblp queries these block alignment properties.
28allowxperm 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.
34allow 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.
48allow 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#
61allow gsid metadata_file:dir search;
62allow gsid gsi_metadata_file:dir rw_dir_perms;
63allow gsid gsi_metadata_file:file create_file_perms;
64
65allow gsid gsi_data_file:dir rw_dir_perms;
66allow gsid gsi_data_file:file create_file_perms;
67allowxperm gsid gsi_data_file:file ioctl FS_IOC_FIEMAP;
68
69neverallow {
70 domain
71 -init
72 -gsid
73 -fastbootd
74 -vold
75} gsi_metadata_file:dir *;
76
77neverallow {
78 domain
79 -init
80 -gsid
81 -fastbootd
82 -vold
83} gsi_metadata_file:notdevfile_class_set ~{ relabelto getattr };
84
85neverallow {
86 domain
87 -init
88 -gsid
89 -fastbootd
90 -vold
91} { gsi_data_file gsi_metadata_file }:notdevfile_class_set *;
92
93neverallow {
94 domain
95 -gsid
96} gsi_data_file:dir ~{ open create read getattr setattr search relabelto ioctl };
97
98neverallow {
99 domain
100 -init
101 -gsid
102} gsi_data_file:dir *;
103
104neverallow {
105 domain
106 -gsid
107} gsi_data_file:notdevfile_class_set ~{ relabelto getattr };