]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dm-verity-fec: correctly reject too-small FEC devices
authorEric Biggers <ebiggers@kernel.org>
Fri, 6 Feb 2026 04:59:20 +0000 (20:59 -0800)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 9 Mar 2026 14:10:48 +0000 (15:10 +0100)
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: a739ff3f543a ("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>
drivers/md/dm-verity-fec.c

index 14be4d888af388257b7936b3a5e540f4ee612b5f..9d5dace7d4200f45c2aed9dbd36bc557082b7124 100644 (file)
@@ -625,7 +625,7 @@ int verity_fec_ctr(struct dm_verity *v)
 {
        struct dm_verity_fec *f = v->fec;
        struct dm_target *ti = v->ti;
-       u64 hash_blocks, fec_blocks;
+       u64 hash_blocks;
        int ret;
 
        if (!verity_fec_is_enabled(v)) {
@@ -706,8 +706,7 @@ int verity_fec_ctr(struct dm_verity *v)
 
        dm_bufio_set_sector_offset(f->bufio, f->start << (v->data_dev_block_bits - SECTOR_SHIFT));
 
-       fec_blocks = div64_u64(f->rounds * f->roots, v->fec->roots << SECTOR_SHIFT);
-       if (dm_bufio_get_device_size(f->bufio) < fec_blocks) {
+       if (dm_bufio_get_device_size(f->bufio) < f->rounds * f->roots) {
                ti->error = "FEC device is too small";
                return -E2BIG;
        }