Skip to content

Commit 9393c8d

Browse files
Michael Schmitzmartinkpetersen
authored andcommitted
scsi: core: Handle drivers which set sg_tablesize to zero
In scsi_mq_setup_tags(), cmd_size is calculated based on zero size for the scatter-gather list in case the low level driver uses SG_NONE in its host template. cmd_size is passed on to the block layer for calculation of the request size, and we've seen NULL pointer dereference errors from the block layer in drivers where SG_NONE is used and a mq IO scheduler is active, apparently as a consequence of this (see commit 68ab2d7 ("scsi: cxlflash: Set sg_tablesize to 1 instead of SG_NONE"), and a recent patch by Finn Thain converting the three m68k NFR5380 drivers to avoid setting SG_NONE). Try to avoid these errors by accounting for at least one sg list entry when calculating cmd_size, regardless of whether the low level driver set a zero sg_tablesize. Tested on 030 m68k with the atari_scsi driver - setting sg_tablesize to SG_NONE no longer results in a crash when loading this driver. CC: Finn Thain <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael Schmitz <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 8b1062d commit 9393c8d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,8 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost)
18821882
{
18831883
unsigned int cmd_size, sgl_size;
18841884

1885-
sgl_size = scsi_mq_inline_sgl_size(shost);
1885+
sgl_size = max_t(unsigned int, sizeof(struct scatterlist),
1886+
scsi_mq_inline_sgl_size(shost));
18861887
cmd_size = sizeof(struct scsi_cmnd) + shost->hostt->cmd_size + sgl_size;
18871888
if (scsi_host_get_prot(shost))
18881889
cmd_size += sizeof(struct scsi_data_buffer) +

0 commit comments

Comments
 (0)