Fail encryption initialization when data device too small.

This commit is contained in:
Ondrej Kozina
2019-07-26 15:11:47 +02:00
parent c033643f07
commit e16319a290

View File

@@ -2299,7 +2299,10 @@ static int _reencrypt_init(struct crypt_device *cd,
* encryption initialization (or mount)
*/
if (move_first_segment) {
/* TODO: api test */
if (dev_size < 2 * (params->data_shift << SECTOR_SHIFT)) {
log_err(cd, _("Device %s is too small."), device_path(crypt_data_device(cd)));
return -EINVAL;
}
if (params->data_shift < LUKS2_get_data_offset(hdr)) {
log_err(cd, _("Data shift (%" PRIu64 " sectors) is less than future data offset (%" PRIu64 " sectors)."), params->data_shift, LUKS2_get_data_offset(hdr));
return -EINVAL;