badblocks: avoid checking invalid range in badblocks_check()
Subsystems (2)
PATCH 1/1 badblocks: avoid checking invalid range in badblocks_check()
If prev_badblocks() returns '-1', it means no valid badblocks record before the checking range. It doesn't make sense to check whether the input checking range is overlapped with the non-existed invalid front range.
This patch checkes whether 'prev >= 0' is true before calling overlap_front(), to void such invalid operations.
--- block/badblocks.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
block/badblocks.c +4 -2
@@ -1312,12 +1312,14 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors, prev =prev_badblocks (bb, &bad, hint);/* start after all badblocks */ -if ((prev +1 ) >= bb->count && !overlap_front (bb, prev, &bad)) { +if ((prev >=0 ) && + ((prev +1 ) >= bb->count) && !overlap_front (bb, prev, &bad)) { len = sectors; goto update_sectors; } -if (overlap_front (bb, prev, &bad)) { +/* Overlapped with front badblocks record */ +if ((prev >=0 ) &&overlap_front (bb, prev, &bad)) {if (BB_ACK (p[prev])) acked_badblocks++;else
Signature · 1 line
2.35.3
Quoted 23 lines
2023年12月24日 08:28,Coly Li <[email protected]> 写道:
If
prev_badblocks()returns '-1', it means no valid badblocks record before the checking range. It doesn't make sense to check whether the input checking range is overlapped with the non-existed invalid front range.This patch checkes whether 'prev >= 0' is true before calling
overlap_front(), to void such invalid operations.Fixes 3ea3354cb9f0 ("badblocks: improve badblocks_check() for multiple ranges handling")Reported-and-tested-by Ira Weiny <[email protected]>Signed-off-by Coly Li <[email protected]>Cc Dan Williams <[email protected]>Cc Geliang Tang <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Jens Axboe <[email protected]>Cc NeilBrown <[email protected]>Cc Vishal L Verma <[email protected]>Cc Xiao Ni <[email protected]>
Quoted 3 lines
---
block/badblocks.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)
Hi Jens,
Is it possible to take this fix into 6.7 still? Thanks in advance.
Coly Li
[snipped]
Jens Axboe
maintainerQuoted 25 lines · Coly Li
Quoted 21 lines
2023?12?24? 08:28?Coly Li <[email protected]> ???
If
prev_badblocks()returns '-1', it means no valid badblocks record before the checking range. It doesn't make sense to check whether the input checking range is overlapped with the non-existed invalid front range.This patch checkes whether 'prev >= 0' is true before calling
overlap_front(), to void such invalid operations.Fixes 3ea3354cb9f0 ("badblocks: improve badblocks_check() for multiple ranges handling")Reported-and-tested-by Ira Weiny <[email protected]>Signed-off-by Coly Li <[email protected]>Cc Dan Williams <[email protected]>Cc Geliang Tang <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Jens Axboe <[email protected]>Cc NeilBrown <[email protected]>Cc Vishal L Verma <[email protected]>Cc Xiao Ni <[email protected]>Quoted 3 lines
---
block/badblocks.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 3 lines
Hi Jens,
Is it possible to take this fix into 6.7 still? Thanks in advance.
Yep, we're still a few weeks out, so not a problem.
Signature · 1 line
Jens Axboe
Quoted 30 lines
2023年12月24日 09:38,Jens Axboe <[email protected]> 写道:
Quoted 25 lines · Coly Li
Quoted 24 lines
2023?12?24? 08:28?Coly Li <[email protected]> ???
If
prev_badblocks()returns '-1', it means no valid badblocks record before the checking range. It doesn't make sense to check whether the input checking range is overlapped with the non-existed invalid front range.This patch checkes whether 'prev >= 0' is true before calling
overlap_front(), to void such invalid operations.Fixes 3ea3354cb9f0 ("badblocks: improve badblocks_check() for multiple ranges handling")Reported-and-tested-by Ira Weiny <[email protected]>Signed-off-by Coly Li <[email protected]>Cc Dan Williams <[email protected]>Cc Geliang Tang <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Jens Axboe <[email protected]>Cc NeilBrown <[email protected]>Cc Vishal L Verma <[email protected]>Cc Xiao Ni <[email protected]>---
block/badblocks.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 3 lines
Hi Jens,
Is it possible to take this fix into 6.7 still? Thanks in advance.
Yep, we're still a few weeks out, so not a problem.
Jes and Ira,
Thank you all for fast response during holidays.
Happy holidays and merry Christmas!
Coly Li
Quoted 9 lines · Coly Li
If
prev_badblocks()returns '-1', it means no valid badblocks record before the checking range. It doesn't make sense to check whether the input checking range is overlapped with the non-existed invalid front range.This patch checkes whether 'prev >= 0' is true before calling
overlap_front(), to void such invalid operations.[...]
Applied, thanks!
[1/1] badblocks: avoid checking invalid range in badblocks_check()
commit: 146e843f6b09271233c021b1677e561b7dc16303
Best regards,
Signature · 1 line
Jens Axboe