scsi_debug: Fix off-by-one bug when unmapping region
PATCH 1/1 scsi_debug: Fix off-by-one bug when unmapping region
Currently it is possible to unmap one more block than user requested to due to the off-by-one error in unmap_region(). This is probably due to the fact that the end variable despite its name actually points to the last block to unmap + 1. However in the condition it is handled as the last block of the region to unmap.
The bug was not previously spotted probably due to the fact that the region was not zeroed, which has changed with commit be1dd78de5686c062bb3103f9e86d444a10ed783. With that commit we were able to corrupt the ext4 file system on 256M scsi_debug device with LBPRZ enabled using fstrim.
Since the 'end' semantic is the same in several functions there this commit just fixes the condition to use the 'end' variable correctly in that context.
--- drivers/scsi/scsi_debug.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/scsi/scsi_debug.c +1 -1
@@ -2054,7 +2054,7 @@ static void unmap_region(sector_t lba, unsigned int len) block = lba + alignment; rem =do_div (block, granularity); -if (rem ==0 && lba + granularity <= end && block < map_size) { +if (rem ==0 && lba + granularity < end && block < map_size) {clear_bit (block, map_storep);if (scsi_debug_lbprz) memset(fake_storep +
Signature · 1 line
1.7.7.6
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Lukas" == Lukas Czerner <[email protected]> writes:
Lukas> Currently it is possible to unmap one more block than user Lukas> requested to due to the off-by-one error in unmap_region(). This Lukas> is probably due to the fact that the end variable despite its Lukas> name actually points to the last block to unmap + 1. However in Lukas> the condition it is handled as the last block of the region to Lukas> unmap.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 9 lines · Martin K. Petersen
Date: Fri, 17 Aug 2012 12:11:50 -0400
From: Martin K. Petersen <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected], [email protected], [email protected],
[email protected], [email protected]
Subject: Re: [PATCH]scsi_debug: Fix off-by-one bug when unmapping regionQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Lukas" == Lukas Czerner <[email protected]> writes:
Quoted 9 lines
Lukas> Currently it is possible to unmap one more block than user Lukas> requested to due to the off-by-one error in
unmap_region(). This Lukas> is probably due to the fact that the end variable despite its Lukas> name actually points to the last block to unmap + 1. However in Lukas> the condition it is handled as the last block of the region to Lukas> unmap.
I am still not seeing it in anywhere, is this going in any time soon ?
Thanks!
-Lukas
Douglas Gilbert
Acked-byQuoted 10 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Lukas" == Lukas Czerner <[email protected]> writes:
Lukas> Currently it is possible to unmap one more block than user Lukas> requested to due to the off-by-one error in
unmap_region(). This Lukas> is probably due to the fact that the end variable despite its Lukas> name actually points to the last block to unmap + 1. However in Lukas> the condition it is handled as the last block of the region to Lukas> unmap.
Quoted 18 lines · Douglas Gilbert
Date: Wed, 05 Sep 2012 15:41:13 -0400
From: Douglas Gilbert <[email protected]>
To: Martin K. Petersen <[email protected]>
Cc: Lukas Czerner <[email protected]>, [email protected],
[email protected], [email protected], [email protected], [email protected]
Subject: Re: [PATCH]scsi_debug: Fix off-by-one bug when unmapping regionQuoted 9 lines · Martin K. Petersen
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Lukas" == Lukas Czerner <[email protected]> writes:
Lukas> Currently it is possible to unmap one more block than user Lukas> requested to due to the off-by-one error in
unmap_region(). This Lukas> is probably due to the fact that the end variable despite its Lukas> name actually points to the last block to unmap + 1. However in Lukas> the condition it is handled as the last block of the region to Lukas> unmap.
Quoted 3 lines
Quoted 1 line
Acked-by Douglas Gilbert <[email protected]>
James, could you please pick this one ?
Thanks!
-Lukas