All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi_lib: add NULL check to scsi_setup_blk_pc_cmnd
@ 2012-07-23 17:32 Jörn Engel
  2012-07-23 19:45 ` James Bottomley
  0 siblings, 1 reply; 5+ messages in thread
From: Jörn Engel @ 2012-07-23 17:32 UTC (permalink / raw)
  To: James Bottomley; +Cc: linux-scsi

At least two slightly different paths can lead to a NULL pointer
dereference in scsi_prep_state_check and have been hit in practice.
1.
Call Trace:
 [<ffffffff812f8c4b>] scsi_setup_blk_pc_cmnd+0x2b/0x170
 [<ffffffff81305108>] sd_prep_fn+0x568/0xdd0
 [<ffffffff8121c594>] blk_peek_request+0xb4/0x240
 [<ffffffff812f94fe>] scsi_request_fn+0x43e/0x4a0
 [<ffffffff8121621b>] __blk_run_queue+0x1b/0x20
 [<ffffffff81220638>] blk_execute_rq_nowait+0x68/0xc0
 [<ffffffff812206fd>] blk_execute_rq+0x6d/0x100
 [<ffffffff812f8f8c>] scsi_execute+0xfc/0x160
 [<ffffffff812f975a>] scsi_execute_req+0xca/0x140
 [<ffffffff81305a4e>] sd_revalidate_disk+0xde/0x1a00
 [<ffffffff8130749b>] sd_probe_async+0x12b/0x1d0
 ...
2.
Call Trace:
 [<ffffffff8130078b>] scsi_setup_blk_pc_cmnd+0x2b/0x170
 [<ffffffff8130091d>] scsi_prep_fn+0x4d/0x60
 [<ffffffff81227794>] blk_peek_request+0xb4/0x240
 [<ffffffff813010cd>] scsi_request_fn+0x47d/0x4b0
 [<ffffffff81223bff>] __blk_run_queue+0x1f/0x80
 [<ffffffff8122b808>] blk_execute_rq_nowait+0x68/0xc0
 ...

This patch should fix both cases.

Signed-off-by: Joern Engel <joern@logfs.org>
---
 drivers/scsi/scsi_lib.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index bb216ff..5fb5a1c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1079,8 +1079,11 @@ static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev,
 int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
 {
 	struct scsi_cmnd *cmd;
-	int ret = scsi_prep_state_check(sdev, req);
+	int ret;
 
+	if (!sdev)
+		return BLKPREP_KILL;
+	ret = scsi_prep_state_check(sdev, req);
 	if (ret != BLKPREP_OK)
 		return ret;
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi_lib: add NULL check to scsi_setup_blk_pc_cmnd
  2012-07-23 19:45 ` James Bottomley
@ 2012-07-23 19:24   ` Jörn Engel
  2012-07-24  5:01     ` James Bottomley
  0 siblings, 1 reply; 5+ messages in thread
From: Jörn Engel @ 2012-07-23 19:24 UTC (permalink / raw)
  To: James Bottomley; +Cc: linux-scsi

On Mon, 23 July 2012 23:45:55 +0400, James Bottomley wrote:
> On Mon, 2012-07-23 at 13:32 -0400, Jörn Engel wrote:
> > At least two slightly different paths can lead to a NULL pointer
> > dereference in scsi_prep_state_check and have been hit in practice.
> 
> Have you checked this with the patches in scsi-misc?  There's a series
> of patches in there that alters the way sdev handling is done.

I would have liked to, but the tree referenced in MAINTAINERS does not
appear to exist:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
Cloning into 'scsi-misc-2.6'...
fatal: The remote end hung up unexpectedly

Jörn

--
The object-oriented version of 'Spaghetti code' is, of course, 'Lasagna code'.
(Too many layers).
-- Roberto Waltman.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi_lib: add NULL check to scsi_setup_blk_pc_cmnd
  2012-07-23 17:32 [PATCH] scsi_lib: add NULL check to scsi_setup_blk_pc_cmnd Jörn Engel
@ 2012-07-23 19:45 ` James Bottomley
  2012-07-23 19:24   ` Jörn Engel
  0 siblings, 1 reply; 5+ messages in thread
From: James Bottomley @ 2012-07-23 19:45 UTC (permalink / raw)
  To: Jörn Engel; +Cc: linux-scsi

On Mon, 2012-07-23 at 13:32 -0400, Jörn Engel wrote:
> At least two slightly different paths can lead to a NULL pointer
> dereference in scsi_prep_state_check and have been hit in practice.

Have you checked this with the patches in scsi-misc?  There's a series
of patches in there that alters the way sdev handling is done.

James




--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi_lib: add NULL check to scsi_setup_blk_pc_cmnd
  2012-07-23 19:24   ` Jörn Engel
@ 2012-07-24  5:01     ` James Bottomley
  2012-07-25 19:13       ` Jörn Engel
  0 siblings, 1 reply; 5+ messages in thread
From: James Bottomley @ 2012-07-24  5:01 UTC (permalink / raw)
  To: Jörn Engel; +Cc: linux-scsi

On Mon, 2012-07-23 at 15:24 -0400, Jörn Engel wrote:
> On Mon, 23 July 2012 23:45:55 +0400, James Bottomley wrote:
> > On Mon, 2012-07-23 at 13:32 -0400, Jörn Engel wrote:
> > > At least two slightly different paths can lead to a NULL pointer
> > > dereference in scsi_prep_state_check and have been hit in practice.
> > 
> > Have you checked this with the patches in scsi-misc?  There's a series
> > of patches in there that alters the way sdev handling is done.
> 
> I would have liked to, but the tree referenced in MAINTAINERS does not
> appear to exist:
> 
> git clone git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
> Cloning into 'scsi-misc-2.6'...
> fatal: The remote end hung up unexpectedly

git clone git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git

use the misc branch

James


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi_lib: add NULL check to scsi_setup_blk_pc_cmnd
  2012-07-24  5:01     ` James Bottomley
@ 2012-07-25 19:13       ` Jörn Engel
  0 siblings, 0 replies; 5+ messages in thread
From: Jörn Engel @ 2012-07-25 19:13 UTC (permalink / raw)
  To: James Bottomley; +Cc: linux-scsi

On Tue, 24 July 2012 09:01:41 +0400, James Bottomley wrote:
> On Mon, 2012-07-23 at 15:24 -0400, Jörn Engel wrote:
> > On Mon, 23 July 2012 23:45:55 +0400, James Bottomley wrote:
> > > 
> > > Have you checked this with the patches in scsi-misc?  There's a series
> > > of patches in there that alters the way sdev handling is done.
> > 
> > I would have liked to, but the tree referenced in MAINTAINERS does not
> > appear to exist:
> > 
> > git clone git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6.git
> > Cloning into 'scsi-misc-2.6'...
> > fatal: The remote end hung up unexpectedly
> 
> git clone git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git
> 
> use the misc branch

joern@Sligo:/usr/src/kernel$ git clone --reference git/ git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git
Cloning into 'scsi'...
remote: Counting objects: 869, done.
remote: Compressing objects: 100% (420/420), done.
remote: Total 668 (delta 562), reused 274 (delta 248)
Receiving objects: 100% (668/668), 112.59 KiB, done.
Resolving deltas: 100% (562/562), completed with 110 local objects.
Checking out files: 100% (39127/39127), done.
joern@Sligo:/usr/src/kernel$ cd scsi/
joern@Sligo:/usr/src/kernel/scsi$ git branch
* master

Normally I never use branches, so there is a chance that I'm just
clueless.  But to my untrained eye, this looks as if there is no misc
branch.

Jörn

--
To my face you have the audacity to advise me to become a thief - the worst
kind of thief that is conceivable, a thief of spiritual things, a thief of
ideas! It is insufferable, intolerable!
-- M. Binet in Scarabouche
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-07-25 20:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-23 17:32 [PATCH] scsi_lib: add NULL check to scsi_setup_blk_pc_cmnd Jörn Engel
2012-07-23 19:45 ` James Bottomley
2012-07-23 19:24   ` Jörn Engel
2012-07-24  5:01     ` James Bottomley
2012-07-25 19:13       ` Jörn Engel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.