Check and allocate header early so wipe fails only for IO errors.

The device_check is done in header write functions,
but these are not recached in normal format path as wipe call
is called earlier.

Call the device check also from wipe function to get better error
description.

This situation happens for example when a block device is too small
(regular file can be enlarged by falloc(); block device cannot).
This commit is contained in:
Milan Broz
2022-11-18 00:23:16 +01:00
parent c31494abc6
commit e96588b8b5
2 changed files with 8 additions and 0 deletions

View File

@@ -1228,6 +1228,10 @@ int LUKS_wipe_header_areas(struct luks_phdr *hdr,
uint64_t offset, length;
size_t wipe_block;
r = LUKS_check_device_size(ctx, hdr, 1);
if (r)
return r;
/* Wipe complete header, keyslots and padding areas with zeroes. */
offset = 0;
length = (uint64_t)hdr->payloadOffset * SECTOR_SIZE;

View File

@@ -362,6 +362,10 @@ int LUKS2_wipe_header_areas(struct crypt_device *cd,
wipe_block = 4096;
}
r = device_check_size(cd, crypt_metadata_device(cd), length, 1);
if (r)
return r;
log_dbg(cd, "Wiping LUKS areas (0x%06" PRIx64 " - 0x%06" PRIx64") with zeroes.",
offset, length + offset);