mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] md/raid10: fix divide-by-zero in setup_geo() with zero far_copies
@ 2026-04-16  3:39 Junrui Luo
  2026-04-16  6:17 ` Paul Menzel
  2026-04-19  5:43 ` Yu Kuai
  0 siblings, 2 replies; 9+ messages in thread
From: Junrui Luo @ 2026-04-16  3:39 UTC (permalink / raw)
  To: Song Liu, Yu Kuai, Li Nan, NeilBrown, Jonathan Brassow
  Cc: linux-raid, linux-kernel, Yuhao Jiang, stable, Junrui Luo

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: 475901aff158 ("MD RAID10: Improve redundancy for 'far' and 'offset' algorithms (part 1)")
Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
---
 drivers/md/raid10.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 0653b5d8545a..811ea3d23b80 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3791,6 +3791,8 @@ static int setup_geo(struct geom *geo, struct mddev *mddev, enum geo_type new)
 	nc = layout & 255;
 	fc = (layout >> 8) & 255;
 	fo = layout & (1<<16);
+	if (!nc || !fc)
+		return -1;
 	geo->raid_disks = disks;
 	geo->near_copies = nc;
 	geo->far_copies = fc;

---
base-commit: 7aaa8047eafd0bd628065b15757d9b48c5f9c07d
change-id: 20260416-fixes-6ba978713ab3

Best regards,
-- 
Junrui Luo <moonafterrain@outlook.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-05-20 16:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-16  3:39 [PATCH] md/raid10: fix divide-by-zero in setup_geo() with zero far_copies Junrui Luo
2026-04-16  6:17 ` Paul Menzel
2026-04-16 10:08   ` Junrui Luo
2026-04-19  5:43 ` Yu Kuai
2026-04-19  6:01   ` Yuhao Jiang
     [not found]   ` <CAHYQsXRN6uof4yyDR6qGteQ=wZTt86VUx7km6k=LbNAQ3wxGiQ@mail.gmail.com>
2026-04-28  8:32     ` Yu Kuai
2026-04-28  8:37       ` Yuhao Jiang
2026-05-20 11:52         ` Yu Kuai
2026-05-20 16:43           ` Yuhao Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®