Skip to content

Commit 2e28bb9

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 ae9cd0b commit 2e28bb9

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
@@ -688,7 +688,7 @@ int verity_fec_ctr(struct dm_verity *v)
688688
{
689689
struct dm_verity_fec *f = v->fec;
690690
struct dm_target *ti = v->ti;
691-
u64 hash_blocks, fec_blocks;
691+
u64 hash_blocks;
692692
int ret;
693693

694694
if (!verity_fec_is_enabled(v)) {
@@ -769,8 +769,7 @@ int verity_fec_ctr(struct dm_verity *v)
769769

770770
dm_bufio_set_sector_offset(f->bufio, f->start << (v->data_dev_block_bits - SECTOR_SHIFT));
771771

772-
fec_blocks = div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT);
773-
if (dm_bufio_get_device_size(f->bufio) < fec_blocks) {
772+
if (dm_bufio_get_device_size(f->bufio) < f->rounds * f->roots) {
774773
ti->error = "FEC device is too small";
775774
return -E2BIG;
776775
}

0 commit comments

Comments
 (0)