From 3dcb532bd3f3346a4ceac26bd1d9d2271bbee752 Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Thu, 15 May 2025 16:23:42 +0200 Subject: [PATCH] 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 --- lib/verity/verity_hash.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/verity/verity_hash.c b/lib/verity/verity_hash.c index e9962c54..02333def 100644 --- a/lib/verity/verity_hash.c +++ b/lib/verity/verity_hash.c @@ -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."),