Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Milan Broz and committed by
Mike Snitzer
783874b0 bd86e320

+4
+4
drivers/md/dm-crypt.c
··· 2585 2585 ti->error = "Invalid feature value for sector_size"; 2586 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 2592 cc->sector_shift = __ffs(cc->sector_size) - SECTOR_SHIFT; 2589 2593 } else if (!strcasecmp(opt_string, "iv_large_sectors")) 2590 2594 set_bit(CRYPT_IV_LARGE_SECTORS, &cc->cipher_flags);