Skip to contentSkip to conversation

scsi: scsi_debug: fix one-partition tape setup bounds

PATCH Superseded Samuel Moelius 2 participants 3 messages Jun 3 SCSI

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: scsi_debug: fix one-partition tape setup bounds

The tape setup path writes partition metadata one element past the allocated tape_blocks array when a one-partition configuration is selected.

That corrupts adjacent state during device initialization before any command is issued.

Use the allocated partition bounds when initializing the tape block array.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 drivers/scsi/scsi_debug.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/scsi/scsi_debug.c +7 -3
index 1515495fd9ea..dda19793862d 100644
@@ -3664,9 +3664,13 @@ static int partition_tape(struct sdebug_dev_info *devip, int nbr_partitions,
 	devip->tape_eop[0] = part_0_size;
 	devip->tape_blocks[0]->fl_size = TAPE_BLOCK_EOD_FLAG;
 	devip->tape_eop[1] = part_1_size;
-	devip->tape_blocks[1] = devip->tape_blocks[0] +
-			devip->tape_eop[0];
-	devip->tape_blocks[1]->fl_size = TAPE_BLOCK_EOD_FLAG;
+	if (nbr_partitions > 1 && part_1_size > 0) {
+		devip->tape_blocks[1] = devip->tape_blocks[0] +
+				devip->tape_eop[0];
+		devip->tape_blocks[1]->fl_size = TAPE_BLOCK_EOD_FLAG;
+	} else {
+		devip->tape_blocks[1] = NULL;
+	}
 
 	for (i = 0 ; i < TAPE_MAX_PARTITIONS; i++)
 		devip->tape_location[i] = 0;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 3 lines · Samuel Moelius

The tape setup path writes partition metadata one element past the allocated tape_blocks array when a one-partition configuration is selected.

I don't think that's correct. tape_blocks is defined in struct sdebug_dev_info as

	struct tape_block *tape_blocks[TAPE_MAX_PARTITIONS];

so tape_blocks[1] is always allocated. You can argue it shouldn't be written to even though it is allocated, but that's not what you wrote.

Regards,

James

#2 lore raw
Quoted 6 lines · James Bottomley
Quoted 3 lines · Samuel Moelius

The tape setup path writes partition metadata one element past the allocated tape_blocks array when a one-partition configuration is selected.

Quoted 7 lines

I don't think that's correct. tape_blocks is defined in struct sdebug_dev_info as

        struct tape_block *tape_blocks[TAPE_MAX_PARTITIONS];

so tape_blocks[1] is always allocated. You can argue it shouldn't be written to even though it is allocated, but that's not what you wrote.

Please disregard this patch. I will submit a new one.