.. | .. |
---|
72 | 72 | * |
---|
73 | 73 | * |
---|
74 | 74 | * +-------------------------------------------+ |
---|
75 | | - * | incfs_super_block |]---+ |
---|
| 75 | + * | incfs_file_header |]---+ |
---|
76 | 76 | * +-------------------------------------------+ | |
---|
77 | 77 | * | metadata |<---+ |
---|
78 | 78 | * | incfs_file_signature |]---+ |
---|
.. | .. |
---|
118 | 118 | INCFS_MD_NONE = 0, |
---|
119 | 119 | INCFS_MD_BLOCK_MAP = 1, |
---|
120 | 120 | INCFS_MD_FILE_ATTR = 2, |
---|
121 | | - INCFS_MD_SIGNATURE = 3 |
---|
| 121 | + INCFS_MD_SIGNATURE = 3, |
---|
| 122 | + INCFS_MD_STATUS = 4, |
---|
| 123 | + INCFS_MD_VERITY_SIGNATURE = 5, |
---|
122 | 124 | }; |
---|
123 | 125 | |
---|
124 | 126 | enum incfs_file_header_flags { |
---|
125 | | - INCFS_FILE_COMPLETE = 1 << 0, |
---|
| 127 | + INCFS_FILE_MAPPED = 1 << 1, |
---|
126 | 128 | }; |
---|
127 | 129 | |
---|
128 | 130 | /* Header included at the beginning of all metadata records on the disk. */ |
---|
.. | .. |
---|
136 | 138 | __le16 h_record_size; |
---|
137 | 139 | |
---|
138 | 140 | /* |
---|
139 | | - * CRC32 of the metadata record. |
---|
| 141 | + * Was: CRC32 of the metadata record. |
---|
140 | 142 | * (e.g. inode, dir entry etc) not just this struct. |
---|
141 | 143 | */ |
---|
142 | | - __le32 h_record_crc; |
---|
| 144 | + __le32 h_unused1; |
---|
143 | 145 | |
---|
144 | 146 | /* Offset of the next metadata entry if any */ |
---|
145 | 147 | __le64 h_next_md_offset; |
---|
146 | 148 | |
---|
147 | | - /* Offset of the previous metadata entry if any */ |
---|
148 | | - __le64 h_prev_md_offset; |
---|
| 149 | + /* Was: Offset of the previous metadata entry if any */ |
---|
| 150 | + __le64 h_unused2; |
---|
149 | 151 | |
---|
150 | 152 | } __packed; |
---|
151 | 153 | |
---|
.. | .. |
---|
164 | 166 | __le16 fh_data_block_size; |
---|
165 | 167 | |
---|
166 | 168 | /* File flags, from incfs_file_header_flags */ |
---|
167 | | - __le32 fh_file_header_flags; |
---|
| 169 | + __le32 fh_flags; |
---|
168 | 170 | |
---|
169 | | - /* Offset of the first metadata record */ |
---|
170 | | - __le64 fh_first_md_offset; |
---|
| 171 | + union { |
---|
| 172 | + /* Standard incfs file */ |
---|
| 173 | + struct { |
---|
| 174 | + /* Offset of the first metadata record */ |
---|
| 175 | + __le64 fh_first_md_offset; |
---|
171 | 176 | |
---|
172 | | - /* |
---|
173 | | - * Put file specific information after this point |
---|
174 | | - */ |
---|
| 177 | + /* Full size of the file's content */ |
---|
| 178 | + __le64 fh_file_size; |
---|
175 | 179 | |
---|
176 | | - /* Full size of the file's content */ |
---|
177 | | - __le64 fh_file_size; |
---|
| 180 | + /* File uuid */ |
---|
| 181 | + incfs_uuid_t fh_uuid; |
---|
| 182 | + }; |
---|
178 | 183 | |
---|
179 | | - /* File uuid */ |
---|
180 | | - incfs_uuid_t fh_uuid; |
---|
| 184 | + /* Mapped file - INCFS_FILE_MAPPED set in fh_flags */ |
---|
| 185 | + struct { |
---|
| 186 | + /* Offset in original file */ |
---|
| 187 | + __le64 fh_original_offset; |
---|
| 188 | + |
---|
| 189 | + /* Full size of the file's content */ |
---|
| 190 | + __le64 fh_mapped_file_size; |
---|
| 191 | + |
---|
| 192 | + /* Original file's uuid */ |
---|
| 193 | + incfs_uuid_t fh_original_uuid; |
---|
| 194 | + }; |
---|
| 195 | + }; |
---|
181 | 196 | } __packed; |
---|
182 | 197 | |
---|
183 | 198 | enum incfs_block_map_entry_flags { |
---|
184 | | - INCFS_BLOCK_COMPRESSED_LZ4 = (1 << 0), |
---|
185 | | - INCFS_BLOCK_HASH = (1 << 1), |
---|
| 199 | + INCFS_BLOCK_COMPRESSED_LZ4 = 1, |
---|
| 200 | + INCFS_BLOCK_COMPRESSED_ZSTD = 2, |
---|
| 201 | + |
---|
| 202 | + /* Reserve 3 bits for compression alg */ |
---|
| 203 | + INCFS_BLOCK_COMPRESSED_MASK = 7, |
---|
186 | 204 | }; |
---|
187 | 205 | |
---|
188 | 206 | /* Block map entry pointing to an actual location of the data block. */ |
---|
.. | .. |
---|
211 | 229 | __le32 m_block_count; |
---|
212 | 230 | } __packed; |
---|
213 | 231 | |
---|
214 | | -/* Metadata record for file attribute. Type = INCFS_MD_FILE_ATTR */ |
---|
215 | | -struct incfs_file_attr { |
---|
216 | | - struct incfs_md_header fa_header; |
---|
217 | | - |
---|
218 | | - __le64 fa_offset; |
---|
219 | | - |
---|
220 | | - __le16 fa_size; |
---|
221 | | - |
---|
222 | | - __le32 fa_crc; |
---|
223 | | -} __packed; |
---|
224 | | - |
---|
225 | | -/* Metadata record for file signature. Type = INCFS_MD_SIGNATURE */ |
---|
| 232 | +/* |
---|
| 233 | + * Metadata record for file signature. Type = INCFS_MD_SIGNATURE |
---|
| 234 | + * |
---|
| 235 | + * The signature stored here is the APK V4 signature data blob. See the |
---|
| 236 | + * definition of incfs_new_file_args::signature_info for an explanation of this |
---|
| 237 | + * blob. Specifically, it contains the root hash, but it does *not* contain |
---|
| 238 | + * anything that the kernel treats as a signature. |
---|
| 239 | + * |
---|
| 240 | + * When FS_IOC_ENABLE_VERITY is called on a file without this record, an APK V4 |
---|
| 241 | + * signature blob and a hash tree are added to the file, and then this metadata |
---|
| 242 | + * record is created to record their locations. |
---|
| 243 | + */ |
---|
226 | 244 | struct incfs_file_signature { |
---|
227 | 245 | struct incfs_md_header sg_header; |
---|
228 | 246 | |
---|
.. | .. |
---|
241 | 259 | u64 sig_offset; |
---|
242 | 260 | u32 hash_size; |
---|
243 | 261 | u64 hash_offset; |
---|
| 262 | +}; |
---|
| 263 | + |
---|
| 264 | +struct incfs_status { |
---|
| 265 | + struct incfs_md_header is_header; |
---|
| 266 | + |
---|
| 267 | + __le32 is_data_blocks_written; /* Number of data blocks written */ |
---|
| 268 | + |
---|
| 269 | + __le32 is_hash_blocks_written; /* Number of hash blocks written */ |
---|
| 270 | + |
---|
| 271 | + __le32 is_dummy[6]; /* Spare fields */ |
---|
| 272 | +} __packed; |
---|
| 273 | + |
---|
| 274 | +/* |
---|
| 275 | + * Metadata record for verity signature. Type = INCFS_MD_VERITY_SIGNATURE |
---|
| 276 | + * |
---|
| 277 | + * This record will only exist for verity-enabled files with signatures. Verity |
---|
| 278 | + * enabled files without signatures do not have this record. This signature is |
---|
| 279 | + * checked by fs-verity identically to any other fs-verity signature. |
---|
| 280 | + */ |
---|
| 281 | +struct incfs_file_verity_signature { |
---|
| 282 | + struct incfs_md_header vs_header; |
---|
| 283 | + |
---|
| 284 | + /* The size of the signature */ |
---|
| 285 | + __le32 vs_size; |
---|
| 286 | + |
---|
| 287 | + /* Signature's offset in the backing file */ |
---|
| 288 | + __le64 vs_offset; |
---|
| 289 | +} __packed; |
---|
| 290 | + |
---|
| 291 | +/* In memory version of above */ |
---|
| 292 | +struct incfs_df_verity_signature { |
---|
| 293 | + u32 size; |
---|
| 294 | + u64 offset; |
---|
244 | 295 | }; |
---|
245 | 296 | |
---|
246 | 297 | /* State of the backing file. */ |
---|
.. | .. |
---|
273 | 324 | union { |
---|
274 | 325 | struct incfs_md_header md_header; |
---|
275 | 326 | struct incfs_blockmap blockmap; |
---|
276 | | - struct incfs_file_attr file_attr; |
---|
277 | 327 | struct incfs_file_signature signature; |
---|
| 328 | + struct incfs_status status; |
---|
| 329 | + struct incfs_file_verity_signature verity_signature; |
---|
278 | 330 | } md_buffer; |
---|
279 | 331 | |
---|
280 | 332 | int (*handle_blockmap)(struct incfs_blockmap *bm, |
---|
281 | 333 | struct metadata_handler *handler); |
---|
282 | | - int (*handle_file_attr)(struct incfs_file_attr *fa, |
---|
283 | | - struct metadata_handler *handler); |
---|
284 | 334 | int (*handle_signature)(struct incfs_file_signature *sig, |
---|
285 | 335 | struct metadata_handler *handler); |
---|
| 336 | + int (*handle_status)(struct incfs_status *sig, |
---|
| 337 | + struct metadata_handler *handler); |
---|
| 338 | + int (*handle_verity_signature)(struct incfs_file_verity_signature *s, |
---|
| 339 | + struct metadata_handler *handler); |
---|
286 | 340 | }; |
---|
287 | 341 | #define INCFS_MAX_METADATA_RECORD_SIZE \ |
---|
288 | | - FIELD_SIZEOF(struct metadata_handler, md_buffer) |
---|
289 | | - |
---|
290 | | -loff_t incfs_get_end_offset(struct file *f); |
---|
| 342 | + sizeof_field(struct metadata_handler, md_buffer) |
---|
291 | 343 | |
---|
292 | 344 | /* Backing file context management */ |
---|
293 | 345 | struct mount_info; |
---|
.. | .. |
---|
303 | 355 | int incfs_write_fh_to_backing_file(struct backing_file_context *bfc, |
---|
304 | 356 | incfs_uuid_t *uuid, u64 file_size); |
---|
305 | 357 | |
---|
| 358 | +int incfs_write_mapping_fh_to_backing_file(struct backing_file_context *bfc, |
---|
| 359 | + incfs_uuid_t *uuid, u64 file_size, u64 offset); |
---|
| 360 | + |
---|
306 | 361 | int incfs_write_data_block_to_backing_file(struct backing_file_context *bfc, |
---|
307 | 362 | struct mem_range block, |
---|
308 | 363 | int block_index, loff_t bm_base_off, |
---|
.. | .. |
---|
315 | 370 | loff_t bm_base_off, |
---|
316 | 371 | loff_t file_size); |
---|
317 | 372 | |
---|
318 | | -int incfs_write_file_attr_to_backing_file(struct backing_file_context *bfc, |
---|
319 | | - struct mem_range value, struct incfs_file_attr *attr); |
---|
320 | | - |
---|
321 | 373 | int incfs_write_signature_to_backing_file(struct backing_file_context *bfc, |
---|
322 | | - struct mem_range sig, u32 tree_size); |
---|
| 374 | + struct mem_range sig, u32 tree_size, |
---|
| 375 | + loff_t *tree_offset, loff_t *sig_offset); |
---|
323 | 376 | |
---|
324 | | -int incfs_write_file_header_flags(struct backing_file_context *bfc, u32 flags); |
---|
325 | | - |
---|
326 | | -int incfs_make_empty_backing_file(struct backing_file_context *bfc, |
---|
327 | | - incfs_uuid_t *uuid, u64 file_size); |
---|
| 377 | +int incfs_write_status_to_backing_file(struct backing_file_context *bfc, |
---|
| 378 | + loff_t status_offset, |
---|
| 379 | + u32 data_blocks_written, |
---|
| 380 | + u32 hash_blocks_written); |
---|
| 381 | +int incfs_write_verity_signature_to_backing_file( |
---|
| 382 | + struct backing_file_context *bfc, struct mem_range signature, |
---|
| 383 | + loff_t *offset); |
---|
328 | 384 | |
---|
329 | 385 | /* Reading stuff */ |
---|
330 | 386 | int incfs_read_file_header(struct backing_file_context *bfc, |
---|