]> www.infradead.org Git - users/hch/misc.git/commitdiff
dm-unstriped: cast an operand to sector_t to prevent potential uint32_t overflow
authorZichen Xie <zichenxie0106@gmail.com>
Mon, 21 Oct 2024 19:54:45 +0000 (14:54 -0500)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 4 Nov 2024 16:34:56 +0000 (17:34 +0100)
This was found by a static analyzer.
There may be a potential integer overflow issue in
unstripe_ctr(). uc->unstripe_offset and uc->unstripe_width are
defined as "sector_t"(uint64_t), while uc->unstripe,
uc->chunk_size and uc->stripes are all defined as "uint32_t".
The result of the calculation will be limited to "uint32_t"
without correct casting.
So, we recommend adding an extra cast to prevent potential
integer overflow.

Fixes: 18a5bf270532 ("dm: add unstriped target")
Signed-off-by: Zichen Xie <zichenxie0106@gmail.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
drivers/md/dm-unstripe.c

index 48587c16c44570b6e0880172ad979aaa2cf10c58..e8a9432057dce14cad575994d5def323d84f09a4 100644 (file)
@@ -85,8 +85,8 @@ static int unstripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
        }
        uc->physical_start = start;
 
-       uc->unstripe_offset = uc->unstripe * uc->chunk_size;
-       uc->unstripe_width = (uc->stripes - 1) * uc->chunk_size;
+       uc->unstripe_offset = (sector_t)uc->unstripe * uc->chunk_size;
+       uc->unstripe_width = (sector_t)(uc->stripes - 1) * uc->chunk_size;
        uc->chunk_shift = is_power_of_2(uc->chunk_size) ? fls(uc->chunk_size) - 1 : 0;
 
        tmp_len = ti->len;