mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Detect DAX devices and and warn in LUKS format.
DAX / persistent memory devices do not provide atomic sector updates, any single modification can corrupt the whole encryption block.
This commit is contained in:
@@ -113,6 +113,7 @@ void device_release_excl(struct crypt_device *cd, struct device *device);
|
|||||||
void device_disable_direct_io(struct device *device);
|
void device_disable_direct_io(struct device *device);
|
||||||
int device_is_identical(struct device *device1, struct device *device2);
|
int device_is_identical(struct device *device1, struct device *device2);
|
||||||
int device_is_rotational(struct device *device);
|
int device_is_rotational(struct device *device);
|
||||||
|
int device_is_dax(struct device *device);
|
||||||
size_t device_alignment(struct device *device);
|
size_t device_alignment(struct device *device);
|
||||||
int device_direct_io(const struct device *device);
|
int device_direct_io(const struct device *device);
|
||||||
int device_fallocate(struct device *device, uint64_t size);
|
int device_fallocate(struct device *device, uint64_t size);
|
||||||
@@ -157,6 +158,7 @@ int crypt_confirm(struct crypt_device *cd, const char *msg);
|
|||||||
|
|
||||||
char *crypt_lookup_dev(const char *dev_id);
|
char *crypt_lookup_dev(const char *dev_id);
|
||||||
int crypt_dev_is_rotational(int major, int minor);
|
int crypt_dev_is_rotational(int major, int minor);
|
||||||
|
int crypt_dev_is_dax(int major, int minor);
|
||||||
int crypt_dev_is_partition(const char *dev_path);
|
int crypt_dev_is_partition(const char *dev_path);
|
||||||
char *crypt_get_partition_device(const char *dev_path, uint64_t offset, uint64_t size);
|
char *crypt_get_partition_device(const char *dev_path, uint64_t offset, uint64_t size);
|
||||||
char *crypt_get_base_device(const char *dev_path);
|
char *crypt_get_base_device(const char *dev_path);
|
||||||
|
|||||||
@@ -1733,6 +1733,9 @@ static int _crypt_format_luks1(struct crypt_device *cd,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device_is_dax(crypt_data_device(cd)) > 0)
|
||||||
|
log_std(cd, _("WARNING: DAX device can corrupt data as it does not guarantee atomic sector updates.\n"));
|
||||||
|
|
||||||
if (params && cd->metadata_device) {
|
if (params && cd->metadata_device) {
|
||||||
/* For detached header the alignment is used directly as data offset */
|
/* For detached header the alignment is used directly as data offset */
|
||||||
if (!cd->data_offset)
|
if (!cd->data_offset)
|
||||||
@@ -1835,6 +1838,9 @@ static int _crypt_format_luks2(struct crypt_device *cd,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device_is_dax(crypt_data_device(cd)) > 0)
|
||||||
|
log_std(cd, _("WARNING: DAX device can corrupt data as it does not guarantee atomic sector updates.\n"));
|
||||||
|
|
||||||
if (sector_size_autodetect) {
|
if (sector_size_autodetect) {
|
||||||
sector_size = device_optimal_encryption_sector_size(cd, crypt_data_device(cd));
|
sector_size = device_optimal_encryption_sector_size(cd, crypt_data_device(cd));
|
||||||
log_dbg(cd, "Auto-detected optimal encryption sector size for device %s is %d bytes.",
|
log_dbg(cd, "Auto-detected optimal encryption sector size for device %s is %d bytes.",
|
||||||
|
|||||||
@@ -985,6 +985,22 @@ int device_is_rotational(struct device *device)
|
|||||||
return crypt_dev_is_rotational(major(st.st_rdev), minor(st.st_rdev));
|
return crypt_dev_is_rotational(major(st.st_rdev), minor(st.st_rdev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int device_is_dax(struct device *device)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (!device)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (stat(device_path(device), &st) < 0)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (!S_ISBLK(st.st_mode))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return crypt_dev_is_dax(major(st.st_rdev), minor(st.st_rdev));
|
||||||
|
}
|
||||||
|
|
||||||
size_t device_alignment(struct device *device)
|
size_t device_alignment(struct device *device)
|
||||||
{
|
{
|
||||||
int devfd;
|
int devfd;
|
||||||
|
|||||||
@@ -220,6 +220,16 @@ int crypt_dev_is_rotational(int major, int minor)
|
|||||||
return val ? 1 : 0;
|
return val ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int crypt_dev_is_dax(int major, int minor)
|
||||||
|
{
|
||||||
|
uint64_t val;
|
||||||
|
|
||||||
|
if (!_sysfs_get_uint64(major, minor, &val, "queue/dax"))
|
||||||
|
return 0; /* if failed, expect non-DAX device */
|
||||||
|
|
||||||
|
return val ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
int crypt_dev_is_partition(const char *dev_path)
|
int crypt_dev_is_partition(const char *dev_path)
|
||||||
{
|
{
|
||||||
uint64_t val;
|
uint64_t val;
|
||||||
|
|||||||
Reference in New Issue
Block a user