Skip to content

Commit f9ddb62

Browse files
avasummergregkh
authored andcommitted
md/raid10: fix divide-by-zero in setup_geo() with zero far_copies
commit 9aa6d86 upstream. setup_geo() extracts near_copies (nc) and far_copies (fc) from the user-provided layout parameter without checking for zero. When fc=0 with the "improved" far set layout selected, 'geo->far_set_size = disks / fc' triggers a divide-by-zero. Validate nc and fc immediately after extraction, returning -1 if either is zero. Fixes: 475901a ("MD RAID10: Improve redundancy for 'far' and 'offset' algorithms (part 1)") Cc: stable@vger.kernel.org Signed-off-by: Junrui Luo <moonafterrain@outlook.com> Link: https://lore.kernel.org/linux-raid/SYBPR01MB7881A5E2556806CC1D318582AF232@SYBPR01MB7881.ausprd01.prod.outlook.com Signed-off-by: Yu Kuai <yukuai@fnnas.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8517b6c commit f9ddb62

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

drivers/md/raid10.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,6 +3791,8 @@ static int setup_geo(struct geom *geo, struct mddev *mddev, enum geo_type new)
37913791
nc = layout & 255;
37923792
fc = (layout >> 8) & 255;
37933793
fo = layout & (1<<16);
3794+
if (!nc || !fc)
3795+
return -1;
37943796
geo->raid_disks = disks;
37953797
geo->near_copies = nc;
37963798
geo->far_copies = fc;

0 commit comments

Comments
 (0)