Skip to content

Commit 4399f07

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 ed2ad73 commit 4399f07

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
@@ -625,7 +625,7 @@ int verity_fec_ctr(struct dm_verity *v)
625625
{
626626
struct dm_verity_fec *f = v->fec;
627627
struct dm_target *ti = v->ti;
628-
u64 hash_blocks, fec_blocks;
628+
u64 hash_blocks;
629629
int ret;
630630

631631
if (!verity_fec_is_enabled(v)) {
@@ -706,8 +706,7 @@ int verity_fec_ctr(struct dm_verity *v)
706706

707707
dm_bufio_set_sector_offset(f->bufio, f->start << (v->data_dev_block_bits - SECTOR_SHIFT));
708708

709-
fec_blocks = div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT);
710-
if (dm_bufio_get_device_size(f->bufio) < fec_blocks) {
709+
if (dm_bufio_get_device_size(f->bufio) < f->rounds * f->roots) {
711710
ti->error = "FEC device is too small";
712711
return -E2BIG;
713712
}

0 commit comments

Comments
 (0)