veritysetup: do not increase hash image size if hash area is not used.

Do not write more than needed header if hash area is not used later.

All space in hash area is then used in FEC calculation, so it makes
no sense to add unused area.
This commit is contained in:
Milan Broz
2021-02-23 12:23:20 +01:00
parent 284a49443e
commit 8e564bbb5c

View File

@@ -162,6 +162,7 @@ int VERITY_write_sb(struct crypt_device *cd,
struct device *device = crypt_metadata_device(cd); struct device *device = crypt_metadata_device(cd);
struct verity_sb sb = {}; struct verity_sb sb = {};
ssize_t hdr_size = sizeof(struct verity_sb); ssize_t hdr_size = sizeof(struct verity_sb);
size_t block_size;
char *algorithm; char *algorithm;
uuid_t uuid; uuid_t uuid;
int r, devfd; int r, devfd;
@@ -181,6 +182,13 @@ int VERITY_write_sb(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
} }
/* Avoid possible increasing of image size - FEC could fail later because of it */
block_size = device_block_size(cd, device);
if (block_size > params->hash_block_size) {
device_disable_direct_io(device);
block_size = params->hash_block_size;
}
devfd = device_open(cd, device, O_RDWR); devfd = device_open(cd, device, O_RDWR);
if (devfd < 0) { if (devfd < 0) {
log_err(cd, _("Cannot open device %s."), device_path(device)); log_err(cd, _("Cannot open device %s."), device_path(device));
@@ -204,7 +212,7 @@ int VERITY_write_sb(struct crypt_device *cd,
memcpy(sb.salt, params->salt, params->salt_size); memcpy(sb.salt, params->salt, params->salt_size);
memcpy(sb.uuid, uuid, sizeof(sb.uuid)); memcpy(sb.uuid, uuid, sizeof(sb.uuid));
r = write_lseek_blockwise(devfd, device_block_size(cd, device), device_alignment(device), r = write_lseek_blockwise(devfd, block_size, device_alignment(device),
(char*)&sb, hdr_size, sb_offset) < hdr_size ? -EIO : 0; (char*)&sb, hdr_size, sb_offset) < hdr_size ? -EIO : 0;
if (r) if (r)
log_err(cd, _("Error during update of verity header on device %s."), log_err(cd, _("Error during update of verity header on device %s."),