mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Fix crypt_wipe to allocate space and not silently fail.
This change will allocate space if underlying device is smaller file and fail if it is block device. Previously smaller device was quietly ignored, leading to keyslot access failure with older dm-crypt mapped keyslot encryption (disabled kernel user crypto API).
This commit is contained in:
@@ -161,19 +161,16 @@ int crypt_wipe_device(struct crypt_device *cd,
|
||||
if (devfd < 0)
|
||||
return errno ? -errno : -EINVAL;
|
||||
|
||||
r = device_size(device, &dev_size);
|
||||
if (r || dev_size == 0)
|
||||
goto out;
|
||||
|
||||
if (dev_size < length)
|
||||
length = 0;
|
||||
|
||||
if (length) {
|
||||
if ((dev_size <= offset) || (dev_size - offset) < length) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (length)
|
||||
dev_size = offset + length;
|
||||
else {
|
||||
r = device_size(device, &dev_size);
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
if (dev_size <= offset)
|
||||
return -EINVAL;
|
||||
length = dev_size - offset;
|
||||
}
|
||||
|
||||
r = posix_memalign((void **)&sf, alignment, wipe_block_size);
|
||||
|
||||
Reference in New Issue
Block a user