Skip to content

Commit 02d2577

Browse files
SilentSobskawasaki
authored andcommitted
block: fix infinite loop in badblocks_clear()
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 <[email protected]>
1 parent 857ada9 commit 02d2577

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

block/badblocks.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,10 @@ static bool _badblocks_clear(struct badblocks *bb, sector_t s, sector_t sectors)
11511151
/* Not front overlap, but behind overlap */
11521152
if ((prev + 1) < bb->count && overlap_behind(bb, &bad, prev + 1)) {
11531153
len = BB_OFFSET(p[prev + 1]) - bad.start;
1154+
if (len == 0) {
1155+
pr_warn_once("badblocks_clear: zero-length segment detected\n");
1156+
len = 1;
1157+
}
11541158
hint = prev + 1;
11551159
/* Clear non-bad range should be treated as successful */
11561160
cleared++;

0 commit comments

Comments
 (0)