From: Daniel Palmer <daniel@0x0f.com>
To: linux-m68k@lists.linux-m68k.org, linux-scsi@vger.kernel.org,
geert@linux-m68k.org, James.Bottomley@HansenPartnership.com,
martin.petersen@oracle.com
Cc: linux-kernel@vger.kernel.org, Daniel Palmer <daniel@0x0f.com>
Subject: [PATCH 2/2] scsi: wd33c93: Avoid deferencing null pointer in interrupt handler
Date: Tue, 3 Sep 2024 22:58:57 +0900 [thread overview]
Message-ID: <20240903135857.455818-2-daniel@0x0f.com> (raw)
In-Reply-To: <20240903135857.455818-1-daniel@0x0f.com>
I have no idea if this fix is appropriate, the code in this driver
makes my brain hurt just looking at it, but sometimes when getting
scsi_pointer from cmd cmd itself is actually null and we get a weird
garbage pointer for scsi_pointer.
When this is accessed later on bad things happen. For my machine
this happens when the SCSI bus is initially scanned.
With this "fix" SCSI on my MVME147 is happy again.
[ 84.330000] wd33c93-0: chip=WD33c93B/13 no_sync=0xff no_dma=0
[ 84.330000] debug_flags=0x00
[ 84.350000] setup_args=
<snip>
[ 84.490000]
[ 84.510000] Version 1.26++ - 10/Feb/2007
[ 84.520000] scsi host0: MVME147 built-in SCSI
[ 85.480000] sending SDTR 0103015e00
[ 85.480000] 01
[ 85.490000] 03
[ 85.500000] 01
[ 85.510000] 00
[ 85.520000] 00
[ 85.520000] sync_xfer=30
[ 85.530000] scsi 0:0:5:0: Direct-Access BlueSCSI HARDDRIVE 2.0 PQ: 0 ANSI: 2
[ 85.820000] st: Version 20160209, fixed bufsize 32768, s/g segs 256
[ 85.900000] sd 0:0:5:0: Attached scsi generic sg0 type 0
Signed-off-by: Daniel Palmer <daniel@0x0f.com>
---
drivers/scsi/wd33c93.c | 10 +++++++---
drivers/scsi/wd33c93.h | 2 ++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index a44b60c9004a..9789d852d541 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -733,7 +733,7 @@ transfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd,
void
wd33c93_intr(struct Scsi_Host *instance)
{
- struct scsi_pointer *scsi_pointer;
+ struct scsi_pointer *scsi_pointer = NULL;
struct WD33C93_hostdata *hostdata =
(struct WD33C93_hostdata *) instance->hostdata;
const wd33c93_regs regs = hostdata->regs;
@@ -752,7 +752,9 @@ wd33c93_intr(struct Scsi_Host *instance)
#endif
cmd = (struct scsi_cmnd *) hostdata->connected; /* assume we're connected */
- scsi_pointer = WD33C93_scsi_pointer(cmd);
+ /* cmd could be null */
+ if (cmd)
+ scsi_pointer = WD33C93_scsi_pointer(cmd);
sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear the interrupt */
phs = read_wd33c93(regs, WD_COMMAND_PHASE);
@@ -828,8 +830,10 @@ wd33c93_intr(struct Scsi_Host *instance)
(struct scsi_cmnd *) hostdata->selecting;
hostdata->selecting = NULL;
- /* construct an IDENTIFY message with correct disconnect bit */
+ /* cmd should now be valid and we can get scsi_pointer */
+ scsi_pointer = WD33C93_scsi_pointer(cmd);
+ /* construct an IDENTIFY message with correct disconnect bit */
hostdata->outgoing_msg[0] = IDENTIFY(0, cmd->device->lun);
if (scsi_pointer->phase)
hostdata->outgoing_msg[0] |= 0x40;
diff --git a/drivers/scsi/wd33c93.h b/drivers/scsi/wd33c93.h
index e5e4254b1477..898c1c7d024d 100644
--- a/drivers/scsi/wd33c93.h
+++ b/drivers/scsi/wd33c93.h
@@ -259,6 +259,8 @@ struct WD33C93_hostdata {
static inline struct scsi_pointer *WD33C93_scsi_pointer(struct scsi_cmnd *cmd)
{
+ WARN_ON_ONCE(!cmd);
+
return scsi_cmd_priv(cmd);
}
--
2.43.0
next prev parent reply other threads:[~2024-09-03 13:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-03 13:58 [PATCH 1/2] m68k/mvme147: Fix SCSI IRQ numbers Daniel Palmer
2024-09-03 13:58 ` Daniel Palmer [this message]
2024-09-05 5:09 ` [PATCH 2/2] scsi: wd33c93: Avoid deferencing null pointer in interrupt handler Michael Schmitz
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=20240903135857.455818-2-daniel@0x0f.com \
--to=daniel@0x0f.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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