scsi: scsi_debug: fix one-partition tape setup bounds
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.
--- drivers/scsi/scsi_debug.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/scsi/scsi_debug.c +7 -3
@@ -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
James Bottomley
maintainerQuoted 3 lines · Samuel Moelius
The tape setup path writes partition metadata one element past the allocated
tape_blocksarray 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
Quoted 6 lines · James Bottomley
Quoted 3 lines · Samuel Moelius
The tape setup path writes partition metadata one element past the allocated
tape_blocksarray when a one-partition configuration is selected.
Quoted 7 lines
I don't think that's correct.
tape_blocksis defined in structsdebug_dev_infoasstruct 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.