public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: fix infinite loop in badblocks_clear()
@ 2026-04-26 14:55 Ramesh Adhikari
  2026-04-26 17:11 ` [PATCH v2] " Ramesh Adhikari
  2026-04-26 17:26 ` [PATCH v3] block: fix infinite loop in badblocks_clear() and badblocks_check() Ramesh Adhikari
  0 siblings, 2 replies; 4+ messages in thread
From: Ramesh Adhikari @ 2026-04-26 14:55 UTC (permalink / raw)
  To: gregkh; +Cc: axboe, linux-block, security, Ramesh Adhikari

An infinite loop can occur in _badblocks_clear() when BB_OFFSET(p[prev + 1])
equals bad.start, resulting in len = 0. This causes the update_sectors loop
to spin forever without making progress:

    s += 0;         // no advancement
    sectors -= 0;   // stays positive
    goto re_clear;  // infinite loop

After approximately 21 seconds, the RCU stall detector triggers and the
system becomes completely unresponsive, requiring a hard reboot.

Add a check to ensure len is non-zero before entering the loop.

Signed-off-by: Ramesh Adhikari <adhikari.resume@gmail.com>
---
 block/badblocks.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/block/badblocks.c b/block/badblocks.c
index ece64e76fe8..9ea4a067710 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -1151,6 +1151,10 @@ static bool _badblocks_clear(struct badblocks *bb, sector_t s, sector_t sectors)
 	/* Not front overlap, but behind overlap */
 	if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) {
 		len = BB_OFFSET(p[prev + 1]) - bad.start;
+		if (len == 0) {
+			pr_warn_once("badblocks_clear: zero-length segment detected\n");
+			len = 1;
+		}
 		hint = prev + 1;
 		/* Clear non-bad range should be treated as successful */
 		cleared++;
-- 
2.43.0


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

end of thread, other threads:[~2026-04-26 17:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-26 14:55 [PATCH] block: fix infinite loop in badblocks_clear() Ramesh Adhikari
2026-04-26 17:11 ` [PATCH v2] " Ramesh Adhikari
2026-04-26 17:26 ` [PATCH v3] block: fix infinite loop in badblocks_clear() and badblocks_check() Ramesh Adhikari
2026-04-26 17:30   ` Jens Axboe

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