verity: Check hash device size in advance

Let's check block device size required for Merkle tree and superblock.
If it is a file, allocate the size in advance with fallocate.

This should print better error message if hash device is too small.

Fixes: #808
This commit is contained in:
Milan Broz
2025-05-15 16:23:42 +02:00
parent 02a48caf7e
commit 3dcb532bd3

View File

@@ -302,6 +302,11 @@ static int VERITY_create_or_verify_hash(struct crypt_device *cd, bool verify,
hash_device_offset_max - params->hash_area_offset);
log_dbg(cd, "Using %d hash levels.", levels);
r = device_check_size(cd, crypt_metadata_device(cd),
hash_device_offset_max - params->hash_area_offset, 1);
if (r < 0)
return r;
data_file = fopen(device_path(crypt_data_device(cd)), "r");
if (!data_file) {
log_err(cd, _("Cannot open device %s."),