Workaround for dm-integrity kernel table bug.

Some kernels show invalid dm-integrity table if suberblock
contains "recalculate" bit.

We can workaround that by setting recalculate option in table
(kernel uses bits from superblock anyway), so the table displayed
is always correct.

Fixes: #538
This commit is contained in:
Milan Broz
2020-02-20 14:02:37 +01:00
parent 8f7e898341
commit 7b206fb13d
3 changed files with 9 additions and 4 deletions

View File

@@ -213,7 +213,7 @@ int INTEGRITY_create_dmd_device(struct crypt_device *cd,
struct volume_key *journal_crypt_key, struct volume_key *journal_crypt_key,
struct volume_key *journal_mac_key, struct volume_key *journal_mac_key,
struct crypt_dm_active_device *dmd, struct crypt_dm_active_device *dmd,
uint32_t flags) uint32_t flags, uint32_t sb_flags)
{ {
int r; int r;
@@ -224,6 +224,10 @@ int INTEGRITY_create_dmd_device(struct crypt_device *cd,
.flags = flags, .flags = flags,
}; };
/* Workaround for kernel dm-integrity table bug */
if (sb_flags & SB_FLAG_RECALCULATING)
dmd->flags |= CRYPT_ACTIVATE_RECALCULATE;
r = INTEGRITY_data_sectors(cd, crypt_metadata_device(cd), r = INTEGRITY_data_sectors(cd, crypt_metadata_device(cd),
crypt_get_data_offset(cd) * SECTOR_SIZE, &dmd->size); crypt_get_data_offset(cd) * SECTOR_SIZE, &dmd->size);
if (r < 0) if (r < 0)
@@ -287,7 +291,8 @@ int INTEGRITY_activate(struct crypt_device *cd,
uint32_t flags, uint32_t sb_flags) uint32_t flags, uint32_t sb_flags)
{ {
struct crypt_dm_active_device dmd = {}; struct crypt_dm_active_device dmd = {};
int r = INTEGRITY_create_dmd_device(cd, params, vk, journal_crypt_key, journal_mac_key, &dmd, flags); int r = INTEGRITY_create_dmd_device(cd, params, vk, journal_crypt_key,
journal_mac_key, &dmd, flags, sb_flags);
if (r < 0) if (r < 0)
return r; return r;

View File

@@ -91,7 +91,7 @@ int INTEGRITY_create_dmd_device(struct crypt_device *cd,
struct volume_key *journal_crypt_key, struct volume_key *journal_crypt_key,
struct volume_key *journal_mac_key, struct volume_key *journal_mac_key,
struct crypt_dm_active_device *dmd, struct crypt_dm_active_device *dmd,
uint32_t flags); uint32_t flags, uint32_t sb_flags);
int INTEGRITY_activate_dmd_device(struct crypt_device *cd, int INTEGRITY_activate_dmd_device(struct crypt_device *cd,
const char *name, const char *name,

View File

@@ -2156,7 +2156,7 @@ int LUKS2_activate(struct crypt_device *cd,
return -EINVAL; return -EINVAL;
} }
r = INTEGRITY_create_dmd_device(cd, NULL, NULL, NULL, NULL, &dmdi, dmd.flags); r = INTEGRITY_create_dmd_device(cd, NULL, NULL, NULL, NULL, &dmdi, dmd.flags, 0);
if (r) if (r)
return r; return r;