Skip to content

Commit 9a484c8

Browse files
Eric Biggersgregkh
authored andcommitted
dm-verity-fec: correctly reject too-small FEC devices
commit 2b14e0b upstream. Fix verity_fec_ctr() to reject too-small FEC devices by correctly computing the number of parity blocks as 'f->rounds * f->roots'. Previously it incorrectly used 'div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT)' which is a much smaller value. Note that the units of 'rounds' are blocks, not bytes. This matches the units of the value returned by dm_bufio_get_device_size(), which are also blocks. A later commit will give 'rounds' a clearer name. Fixes: a739ff3 ("dm verity: add support for forward error correction") Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 52b109f commit 9a484c8

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/md/dm-verity-fec.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ int verity_fec_ctr(struct dm_verity *v)
657657
{
658658
struct dm_verity_fec *f = v->fec;
659659
struct dm_target *ti = v->ti;
660-
u64 hash_blocks, fec_blocks;
660+
u64 hash_blocks;
661661
int ret;
662662

663663
if (!verity_fec_is_enabled(v)) {
@@ -738,8 +738,7 @@ int verity_fec_ctr(struct dm_verity *v)
738738

739739
dm_bufio_set_sector_offset(f->bufio, f->start << (v->data_dev_block_bits - SECTOR_SHIFT));
740740

741-
fec_blocks = div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT);
742-
if (dm_bufio_get_device_size(f->bufio) < fec_blocks) {
741+
if (dm_bufio_get_device_size(f->bufio) < f->rounds * f->roots) {
743742
ti->error = "FEC device is too small";
744743
return -E2BIG;
745744
}

0 commit comments

Comments
 (0)