st.c: possible memory use after free after MTSETBLK ioctl
Subsystems (2)
Quoted 11 lines · Kai Makisara
Having thought this a little more, it would probably be best to remove the
call tonormalize_buffer()instead of trying to cope with it failing. This
just means that some memory may stay allocated longer. In the usage scenarios coming into my mind, the buffer is either small or it will be
reallocated.
Quoted 4 lines
Would you like to make the patch?
Thanks,
Kai
How does this look? Compiles and passes initial tests. I'd left the normalize_buffer() in originally thinking there must be a reason for it, but you're right it just seems to make buffer handling problematic. This patch removes the normalize_buffer() call and the specialness of changing from a 0 to non-zero blocksize to fix the possible use of memory after it has been freed by the st driver.
drivers/scsi/st.c +0 -3
@@ -2859,11 +2859,8 @@ ioctl_result =st_int_ioctl (STp,MTBSF ,1 );if (cmd_in ==MTSETBLK || cmd_in ==SET_DENS_AND_BLK ) { -int old_block_size = STp->block_size; STp->block_size = arg &MT_ST_BLKSIZE_MASK ;if (STp->block_size !=0 ) { -if (old_block_size ==0 ) -normalize_buffer (STp->buffer); (STp->buffer)->buffer_blocks = (STp->buffer)->buffer_size / STp->block_size; }
Kai Makisara
Acked-byQuoted 30 lines · David Jeffery
Quoted 11 lines · Kai Makisara
Having thought this a little more, it would probably be best to remove the
call tonormalize_buffer()instead of trying to cope with it failing. This
just means that some memory may stay allocated longer. In the usage scenarios coming into my mind, the buffer is either small or it will be
reallocated.Quoted 4 lines
Would you like to make the patch?
Thanks,
KaiHow does this look? Compiles and passes initial tests. I'd left the
normalize_buffer()in originally thinking there must be a reason for it, but you're right it just seems to make buffer handling problematic. This patch removes thenormalize_buffer()call and the specialness of changing from a 0 to non-zero blocksize to fix the possible use of memory after it has been freed by the st driver.Signed-off-by David Jeffery <[email protected]>drivers/scsi/st.c +0
-0@@ -2859,11 +2859,8 @@ ioctl_result =st_int_ioctl (STp,MTBSF ,1 );
drivers/scsi/st.c line 2866
Quoted 10 lines
drivers/scsi/st.c +0
-3if (cmd_in ==MTSETBLK || cmd_in ==SET_DENS_AND_BLK ) { -int old_block_size = STp->block_size; STp->block_size = arg &MT_ST_BLKSIZE_MASK ;if (STp->block_size !=0 ) { -if (old_block_size ==0 ) -normalize_buffer (STp->buffer); (STp->buffer)->buffer_blocks = (STp->buffer)->buffer_size / STp->block_size; }
Looks good to me. There were reasons when it was inserted, but many things have changed since then: memory was expensive, I/O always used the buffer, normalize_buffer() did not free the last segment, etc.
Thanks,
Kai