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 --- 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