From: Michael Schmitz <schmitzmic@gmail.com>
To: linux-scsi@vger.kernel.org, jejb@linux.ibm.com,
martin.petersen@oracle.com
Cc: schmitz@debian.org, Michael Schmitz <schmitzmic@gmail.com>,
Finn Thain <fthain@telegraphics.com.au>
Subject: [PATCH] scsi: scsi-lib.c: increase cmd_size by sizeof(struct scatterlist)
Date: Tue, 5 Nov 2019 15:49:10 +1300 [thread overview]
Message-ID: <1572922150-4358-1-git-send-email-schmitzmic@gmail.com> (raw)
In-Reply-To: <cover.1572656814.git.fthain@telegraphics.com.au>
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 68ab2d76e4be for the
cxflash driver, 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 caculating 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.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
CC: Finn Thain <fthain@telegraphics.com.au>
---
drivers/scsi/scsi_lib.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index d47d637..d38b0e1 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1867,7 +1867,8 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost)
{
unsigned int cmd_size, sgl_size;
- sgl_size = scsi_mq_inline_sgl_size(shost);
+ sgl_size = max_t(unsigned int, sizeof(struct scatterlist),
+ scsi_mq_inline_sgl_size(shost));
cmd_size = sizeof(struct scsi_cmnd) + shost->hostt->cmd_size + sgl_size;
if (scsi_host_get_prot(shost))
cmd_size += sizeof(struct scsi_data_buffer) +
--
1.7.0.4
next prev parent reply other threads:[~2019-11-05 2:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-02 1:06 [PATCH 0/2] SG_NONE fix and cleanup Finn Thain
2019-11-02 1:06 ` [PATCH 2/2] scsi: Clean up SG_NONE Finn Thain
2019-11-02 1:06 ` [PATCH 1/2] atari_scsi, sun3_scsi: Set sg_tablesize to 1 instead of SG_NONE Finn Thain
2019-11-05 2:49 ` Michael Schmitz [this message]
2019-11-05 5:54 ` [PATCH] scsi: scsi-lib.c: increase cmd_size by sizeof(struct scatterlist) Finn Thain
2019-11-06 5:46 ` Martin K. Petersen
2019-11-06 7:21 ` Michael Schmitz
2019-11-13 3:12 ` [PATCH 0/2] SG_NONE fix and cleanup Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1572922150-4358-1-git-send-email-schmitzmic@gmail.com \
--to=schmitzmic@gmail.com \
--cc=fthain@telegraphics.com.au \
--cc=jejb@linux.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=schmitz@debian.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox