From: Jiri Slaby <jirislaby@gmail.com>
To: James.Bottomley@suse.de
Cc: aacraid@adaptec.com, james.smart@emulex.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Jiri Slaby <jirislaby@gmail.com>
Subject: [PATCH -2nd repost 4/4] SCSI: scsi_lib, fix potential NULL dereference
Date: Wed, 4 Nov 2009 17:15:21 +0100 [thread overview]
Message-ID: <1257351321-8281-4-git-send-email-jirislaby@gmail.com> (raw)
In-Reply-To: <1257351321-8281-1-git-send-email-jirislaby@gmail.com>
Stanse found a potential NULL dereference in scsi_kill_request.
Instead of triggering BUG() in 'if (unlikely(cmd == NULL))' branch,
the kernel will Oops earlier on cmd dereference.
Move the dereferences after the if.
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Cc: James E.J. Bottomley <James.Bottomley@suse.de>
---
drivers/scsi/scsi_lib.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ed98279..47ee130 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1359,9 +1359,9 @@ static int scsi_lld_busy(struct request_queue *q)
static void scsi_kill_request(struct request *req, struct request_queue *q)
{
struct scsi_cmnd *cmd = req->special;
- struct scsi_device *sdev = cmd->device;
- struct scsi_target *starget = scsi_target(sdev);
- struct Scsi_Host *shost = sdev->host;
+ struct scsi_device *sdev;
+ struct scsi_target *starget;
+ struct Scsi_Host *shost;
blk_start_request(req);
@@ -1371,6 +1371,9 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
BUG();
}
+ sdev = cmd->device;
+ starget = scsi_target(sdev);
+ shost = sdev->host;
scsi_init_cmd_errh(cmd);
cmd->result = DID_NO_CONNECT << 16;
atomic_inc(&cmd->device->iorequest_cnt);
--
1.6.4.2
prev parent reply other threads:[~2009-11-04 16:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-04 16:15 [PATCH -2nd repost 1/4] SCSI: aacraid, fix memory leak Jiri Slaby
2009-11-04 16:15 ` [PATCH -2nd repost 2/4] SCSI: remove unnecessary NULL test Jiri Slaby
2009-11-04 16:22 ` Mike Christie
2009-11-04 18:18 ` Karen Xie
2009-11-04 16:15 ` [PATCH -2nd repost 3/4] SCSI: lpfc, fix memory leak Jiri Slaby
2009-11-04 16:15 ` Jiri Slaby [this message]
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=1257351321-8281-4-git-send-email-jirislaby@gmail.com \
--to=jirislaby@gmail.com \
--cc=James.Bottomley@suse.de \
--cc=aacraid@adaptec.com \
--cc=james.smart@emulex.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.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