Skip to contentSkip to conversation

scsi_debug: Fix off-by-one bug when unmapping region

PATCH In review Lukas Czerner 3 participants 5 messages Aug 16, 2012 – Oct 3, 2012 SCSI

lore
Share & tools
lore
#0 lore raw

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
index 182d5a5..f4cc413 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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
#2 lore raw
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 region

Quoted 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

#3 lore raw
In reply to Martin K. Petersen
Quoted 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.

#4 lore raw
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 region

Quoted 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

James, could you please pick this one ?

Thanks!
-Lukas