Pass device size inside reencryption parameters in sectors.

it was mistake in reencryption API. All other device sizes
related to device mapper devices are always in 512b setctors.
This commit is contained in:
Ondrej Kozina
2019-07-09 12:56:03 +02:00
parent 61dff96474
commit 4a232bc868
2 changed files with 14 additions and 12 deletions

View File

@@ -887,14 +887,14 @@ static int _reenc_load(struct crypt_device *cd, struct luks2_hdr *hdr, struct lu
log_dbg(cd, "Requested hotzone size: %" PRIu64 ", requested device size: %" PRIu64 log_dbg(cd, "Requested hotzone size: %" PRIu64 ", requested device size: %" PRIu64
", calculated alignment: %zu", params->max_hotzone_size, ", calculated alignment: %zu", params->max_hotzone_size,
params->device_size, rh->alignment); params->device_size << SECTOR_SHIFT, rh->alignment);
if (params->max_hotzone_size % rh->alignment) { if (params->max_hotzone_size % rh->alignment) {
log_err(cd, _("Hotzone size must be multiple of calculated zone alignment (%zu bytes)."), rh->alignment); log_err(cd, _("Hotzone size must be multiple of calculated zone alignment (%zu bytes)."), rh->alignment);
return -EINVAL; return -EINVAL;
} }
if (params->device_size % rh->alignment) { if ((params->device_size << SECTOR_SHIFT) % rh->alignment) {
log_err(cd, _("Device size must be multiple of calculated zone alignment (%zu bytes)."), rh->alignment); log_err(cd, _("Device size must be multiple of calculated zone alignment (%zu bytes)."), rh->alignment);
return -EINVAL; return -EINVAL;
} }
@@ -947,7 +947,7 @@ static int _reenc_load(struct crypt_device *cd, struct luks2_hdr *hdr, struct lu
if (params->device_size) { if (params->device_size) {
log_dbg(cd, "Switching reencryption to fixed size mode."); log_dbg(cd, "Switching reencryption to fixed size mode.");
device_size = params->device_size; device_size = params->device_size << SECTOR_SHIFT;
rh->fixed_length = true; rh->fixed_length = true;
} else } else
rh->fixed_length = false; rh->fixed_length = false;
@@ -1106,7 +1106,7 @@ static int LUKS2_reenc_load_crashed(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
if (!dynamic) if (!dynamic)
params.device_size = minimal_size; params.device_size = minimal_size >> SECTOR_SHIFT;
r = _LUKS2_reenc_load(cd, hdr, device_size, rh, &params); r = _LUKS2_reenc_load(cd, hdr, device_size, rh, &params);
@@ -2651,6 +2651,8 @@ static int _reencrypt_load(struct crypt_device *cd,
goto err; goto err;
} }
minimal_size >>= SECTOR_SHIFT;
old_ss = LUKS2_reencrypt_get_sector_size_old(hdr); old_ss = LUKS2_reencrypt_get_sector_size_old(hdr);
new_ss = LUKS2_reencrypt_get_sector_size_new(hdr); new_ss = LUKS2_reencrypt_get_sector_size_new(hdr);
@@ -2669,7 +2671,7 @@ static int _reencrypt_load(struct crypt_device *cd,
free(CONST_CAST(void*)dmd.uuid); free(CONST_CAST(void*)dmd.uuid);
if (r < 0) if (r < 0)
goto err; goto err;
mapping_size = dmd.size << SECTOR_SHIFT; mapping_size = dmd.size;
} }
r = -EINVAL; r = -EINVAL;
@@ -2684,10 +2686,10 @@ static int _reencrypt_load(struct crypt_device *cd,
if (required_size) { if (required_size) {
/* TODO: Add support for chaning fixed minimal size in reencryption mda where possible */ /* TODO: Add support for chaning fixed minimal size in reencryption mda where possible */
if ((minimal_size && (required_size < minimal_size)) || if ((minimal_size && (required_size < minimal_size)) ||
(required_size > device_size) || (required_size > (device_size >> SECTOR_SHIFT)) ||
(!dynamic && (required_size != minimal_size)) || (!dynamic && (required_size != minimal_size)) ||
(old_ss > 0 && MISALIGNED(required_size, old_ss)) || (old_ss > 0 && MISALIGNED(required_size, old_ss >> SECTOR_SHIFT)) ||
(new_ss > 0 && MISALIGNED(required_size, new_ss))) { (new_ss > 0 && MISALIGNED(required_size, new_ss >> SECTOR_SHIFT))) {
log_err(cd, _("Illegal device size requested in reencryption parameters.")); log_err(cd, _("Illegal device size requested in reencryption parameters."));
goto err; goto err;
} }

View File

@@ -2547,7 +2547,7 @@ static int action_reencrypt_load(struct crypt_device *cd)
.resilience = opt_resilience_mode, .resilience = opt_resilience_mode,
.hash = opt_resilience_hash, .hash = opt_resilience_hash,
.max_hotzone_size = opt_hotzone_size, .max_hotzone_size = opt_hotzone_size,
.device_size = opt_device_size, .device_size = opt_device_size / SECTOR_SIZE,
.flags = CRYPT_REENCRYPT_RESUME_ONLY .flags = CRYPT_REENCRYPT_RESUME_ONLY
}; };
@@ -2591,7 +2591,7 @@ static int action_encrypt_luks2(struct crypt_device **cd)
.resilience = opt_resilience_mode, .resilience = opt_resilience_mode,
.hash = opt_resilience_hash, .hash = opt_resilience_hash,
.max_hotzone_size = opt_hotzone_size, .max_hotzone_size = opt_hotzone_size,
.device_size = opt_device_size, .device_size = opt_device_size / SECTOR_SIZE,
.luks2 = &luks2_params, .luks2 = &luks2_params,
.flags = CRYPT_REENCRYPT_INITIALIZE_ONLY .flags = CRYPT_REENCRYPT_INITIALIZE_ONLY
}; };
@@ -2753,7 +2753,7 @@ static int action_decrypt_luks2(struct crypt_device *cd)
.resilience = opt_data_shift ? "datashift" : opt_resilience_mode, .resilience = opt_data_shift ? "datashift" : opt_resilience_mode,
.hash = opt_resilience_hash, .hash = opt_resilience_hash,
.data_shift = imaxabs(opt_data_shift) / SECTOR_SIZE, .data_shift = imaxabs(opt_data_shift) / SECTOR_SIZE,
.device_size = opt_device_size, .device_size = opt_device_size / SECTOR_SIZE,
.max_hotzone_size = opt_hotzone_size, .max_hotzone_size = opt_hotzone_size,
}; };
size_t passwordLen; size_t passwordLen;
@@ -2967,7 +2967,7 @@ static int action_reencrypt_luks2(struct crypt_device *cd)
.hash = opt_resilience_hash, .hash = opt_resilience_hash,
.data_shift = imaxabs(opt_data_shift) / SECTOR_SIZE, .data_shift = imaxabs(opt_data_shift) / SECTOR_SIZE,
.max_hotzone_size = opt_hotzone_size, .max_hotzone_size = opt_hotzone_size,
.device_size = opt_device_size, .device_size = opt_device_size / SECTOR_SIZE,
.luks2 = &luks2_params, .luks2 = &luks2_params,
}; };