diff options
author | Milan Broz <gmazyland@gmail.com> | 2017-09-13 09:45:56 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2017-10-04 10:49:58 -0400 |
commit | 783874b050768d361239e444ba0fa396bb6d463f (patch) | |
tree | bc41ab9d2de82b5aedf85216eacdadd61b44d770 /drivers/md/dm-crypt.c | |
parent | bd86e32059526e2d0d13ca1e4447dfbbddb6e5cc (diff) |
dm crypt: reject sector_size feature if device length is not aligned to it
If a crypt mapping uses optional sector_size feature, additional
restrictions to mapped device segment size must be applied in
constructor, otherwise the device activation will fail later.
Fixes: 8f0009a225 ("dm crypt: optionally support larger encryption sector size")
Cc: stable@vger.kernel.org # 4.12+
Signed-off-by: Milan Broz <gmazyland@gmail.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Diffstat (limited to 'drivers/md/dm-crypt.c')
-rw-r--r-- | drivers/md/dm-crypt.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 75341fdca4b6..96ab46512e1f 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c | |||
@@ -2585,6 +2585,10 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar | |||
2585 | ti->error = "Invalid feature value for sector_size"; | 2585 | ti->error = "Invalid feature value for sector_size"; |
2586 | return -EINVAL; | 2586 | return -EINVAL; |
2587 | } | 2587 | } |
2588 | if (ti->len & ((cc->sector_size >> SECTOR_SHIFT) - 1)) { | ||
2589 | ti->error = "Device size is not multiple of sector_size feature"; | ||
2590 | return -EINVAL; | ||
2591 | } | ||
2588 | cc->sector_shift = __ffs(cc->sector_size) - SECTOR_SHIFT; | 2592 | cc->sector_shift = __ffs(cc->sector_size) - SECTOR_SHIFT; |
2589 | } else if (!strcasecmp(opt_string, "iv_large_sectors")) | 2593 | } else if (!strcasecmp(opt_string, "iv_large_sectors")) |
2590 | set_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); | 2594 | set_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags); |