mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-07 00:40:01 +01:00
Disable DIRECT_IO for LUKS header with unaligned keyslots.
Fixes issue#287. Such a header is very rare, it is not worth to do more detection here.
This commit is contained in:
@@ -75,6 +75,8 @@ int device_block_size(struct device *device);
|
|||||||
int device_read_ahead(struct device *device, uint32_t *read_ahead);
|
int device_read_ahead(struct device *device, uint32_t *read_ahead);
|
||||||
int device_size(struct device *device, uint64_t *size);
|
int device_size(struct device *device, uint64_t *size);
|
||||||
int device_open(struct device *device, int flags);
|
int device_open(struct device *device, int flags);
|
||||||
|
void device_disable_direct_io(struct device *device);
|
||||||
|
|
||||||
|
|
||||||
enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 };
|
enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 };
|
||||||
int device_block_adjust(struct crypt_device *cd,
|
int device_block_adjust(struct crypt_device *cd,
|
||||||
|
|||||||
@@ -545,6 +545,16 @@ int LUKS_read_phdr(struct luks_phdr *hdr,
|
|||||||
if (!r)
|
if (!r)
|
||||||
r = LUKS_check_device_size(ctx, hdr->keyBytes);
|
r = LUKS_check_device_size(ctx, hdr->keyBytes);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cryptsetup 1.0.0 did not align keyslots to 4k (very rare version).
|
||||||
|
* Disable direct-io to avoid possible IO errors if underlying device
|
||||||
|
* has bigger sector size.
|
||||||
|
*/
|
||||||
|
if (!r && hdr->keyblock[0].keyMaterialOffset * SECTOR_SIZE < LUKS_ALIGN_KEYSLOTS) {
|
||||||
|
log_dbg("Old unaligned LUKS keyslot detected, disabling direct-io.");
|
||||||
|
device_disable_direct_io(device);
|
||||||
|
}
|
||||||
|
|
||||||
close(devfd);
|
close(devfd);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -530,3 +530,8 @@ size_t size_round_up(size_t size, unsigned int block)
|
|||||||
size_t s = (size + (block - 1)) / block;
|
size_t s = (size + (block - 1)) / block;
|
||||||
return s * block;
|
return s * block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void device_disable_direct_io(struct device *device)
|
||||||
|
{
|
||||||
|
device->o_direct = 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user