public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	torvalds@osdl.org, akpm@osdl.org, alan@lxorguk.ukuu.org.uk,
	linux-scsi@vger.kernel.org, James.Bottomley@SteelEye.com,
	stefanr@s5r6.in-berlin.de
Subject: [patch 18/19] SCSI: fix transfer direction in scsi_lib and st
Date: Fri, 23 Dec 2005 14:48:52 -0800	[thread overview]
Message-ID: <20051223224852.GR19057@kroah.com> (raw)
In-Reply-To: <20051223224712.GA18975@kroah.com>

[-- Attachment #1: scsi-fix-transfer-direction-in-scsi_lib-and-st.patch --]
[-- Type: text/plain, Size: 3467 bytes --]

-stable review patch.  If anyone has any objections, please let us know.

------------------
From: Stefan Richter <stefanr@s5r6.in-berlin.de>

SCSI: fix transfer direction in scsi_lib and st

scsi_prep_fn and st_init_command could issue WRITE requests with zero
buffer length. This may lead to kernel panic or oops with some SCSI
low-level drivers.

Derived from -rc patches from Jens Axboe and James Bottomley.

Patch is reassembled for -stable from patches:
[SCSI] fix panic when ejecting ieee1394 ipod
[SCSI] Consolidate REQ_BLOCK_PC handling path (fix ipod panic)

Depends on patch "SCSI: fix transfer direction in sd (kernel panic when
ejecting iPod)". Also modifies the already correct sr_init_command to
fully match the corresponding -rc patch.


Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/scsi/scsi_lib.c |   13 +------------
 drivers/scsi/sr.c       |   20 +++-----------------
 drivers/scsi/st.c       |   19 +------------------
 3 files changed, 5 insertions(+), 47 deletions(-)

--- linux-2.6.14.4.orig/drivers/scsi/scsi_lib.c
+++ linux-2.6.14.4/drivers/scsi/scsi_lib.c
@@ -1284,18 +1284,7 @@ static int scsi_prep_fn(struct request_q
 				goto kill;
 			}
 		} else {
-			memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
-			cmd->cmd_len = req->cmd_len;
-			if (rq_data_dir(req) == WRITE)
-				cmd->sc_data_direction = DMA_TO_DEVICE;
-			else if (req->data_len)
-				cmd->sc_data_direction = DMA_FROM_DEVICE;
-			else
-				cmd->sc_data_direction = DMA_NONE;
-			
-			cmd->transfersize = req->data_len;
-			cmd->allowed = 3;
-			cmd->timeout_per_command = req->timeout;
+			scsi_setup_blk_pc_cmnd(cmd, 3);
 			cmd->done = scsi_generic_done;
 		}
 	}
--- linux-2.6.14.4.orig/drivers/scsi/sr.c
+++ linux-2.6.14.4/drivers/scsi/sr.c
@@ -320,25 +320,11 @@ static int sr_init_command(struct scsi_c
 	 * these are already setup, just copy cdb basically
 	 */
 	if (SCpnt->request->flags & REQ_BLOCK_PC) {
-		struct request *rq = SCpnt->request;
+		scsi_setup_blk_pc_cmnd(SCpnt, MAX_RETRIES);
 
-		if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))
-			return 0;
-
-		memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));
-		SCpnt->cmd_len = rq->cmd_len;
-		if (!rq->data_len)
-			SCpnt->sc_data_direction = DMA_NONE;
-		else if (rq_data_dir(rq) == WRITE)
-			SCpnt->sc_data_direction = DMA_TO_DEVICE;
-		else
-			SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-
-		this_count = rq->data_len;
-		if (rq->timeout)
-			timeout = rq->timeout;
+		if (SCpnt->timeout_per_command)
+			timeout = SCpnt->timeout_per_command;
 
-		SCpnt->transfersize = rq->data_len;
 		goto queue;
 	}
 
--- linux-2.6.14.4.orig/drivers/scsi/st.c
+++ linux-2.6.14.4/drivers/scsi/st.c
@@ -4196,27 +4196,10 @@ static void st_intr(struct scsi_cmnd *SC
  */
 static int st_init_command(struct scsi_cmnd *SCpnt)
 {
-	struct request *rq;
-
 	if (!(SCpnt->request->flags & REQ_BLOCK_PC))
 		return 0;
 
-	rq = SCpnt->request;
-	if (sizeof(rq->cmd) > sizeof(SCpnt->cmnd))
-		return 0;
-
-	memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd));
-	SCpnt->cmd_len = rq->cmd_len;
-
-	if (rq_data_dir(rq) == WRITE)
-		SCpnt->sc_data_direction = DMA_TO_DEVICE;
-	else if (rq->data_len)
-		SCpnt->sc_data_direction = DMA_FROM_DEVICE;
-	else
-		SCpnt->sc_data_direction = DMA_NONE;
-
-	SCpnt->timeout_per_command = rq->timeout;
-	SCpnt->transfersize = rq->data_len;
+	scsi_setup_blk_pc_cmnd(SCpnt, 0);
 	SCpnt->done = st_intr;
 	return 1;
 }

--

  parent reply	other threads:[~2005-12-23 22:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20051223221200.342826000@press.kroah.org>
2005-12-23 22:47 ` [patch 00/19] -stable review for 2.6.14.5 Greg Kroah-Hartman
2005-12-23 22:47   ` [patch 01/19] ACPI: Add support for FADT P_LVL2_UP flag Greg Kroah-Hartman
2005-12-24 15:38     ` Pavel Machek
2005-12-24 16:14     ` Daniel Drake
2005-12-26 23:54       ` Greg KH
2005-12-23 22:47   ` [patch 02/19] ACPI: Prefer _CST over FADT for C-state capabilities Greg Kroah-Hartman
2005-12-23 22:47   ` [patch 03/19] [NETFILTER]: Fix CTA_PROTO_NUM attribute size in ctnetlink Greg Kroah-Hartman
2005-12-23 22:47   ` [patch 04/19] [NETFILTER]: Fix unbalanced read_unlock_bh " Greg Kroah-Hartman
2005-12-23 22:47   ` [patch 05/19] apci: fix NULL deref in video/lcd/brightness Greg Kroah-Hartman
2005-12-23 22:47   ` [patch 06/19] [PATCH] dpt_i2o fix for deadlock condition Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 07/19] [GRE]: Fix hardware checksum modification Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 08/19] [VLAN]: Fix hardware rx csum errors Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 09/19] [NETFILTER]: Fix NAT init order Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 10/19] [NETFILTER]: Fix incorrect dependency for IP6_NF_TARGET_NFQUEUE Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 11/19] [RTNETLINK]: Fix RTNLGRP definitions in rtnetlink.h Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 12/19] [BRIDGE-NF]: Fix bridge-nf ipv6 length check Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 13/19] [IPV6]: Fix route lifetime Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 14/19] [IPSEC]: Perform SA switchover immediately Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 15/19] [PATCH] Input: fix an OOPS in HID driver Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 16/19] kernel/params.c: fix sysfs access with CONFIG_MODULES=n Greg Kroah-Hartman
2005-12-23 22:48   ` [patch 17/19] SCSI: fix transfer direction in sd (kernel panic when ejecting iPod) Greg Kroah-Hartman
2005-12-23 22:48   ` Greg Kroah-Hartman [this message]
2005-12-23 23:05     ` [patch 18/19] SCSI: fix transfer direction in scsi_lib and st James Bottomley
2005-12-23 23:22       ` [stable] " Chris Wright
2005-12-23 22:48   ` [patch 19/19] setting ACLs on readonly mounted NFS filesystems (CVE-2005-3623) Greg Kroah-Hartman

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=20051223224852.GR19057@kroah.com \
    --to=gregkh@suse.de \
    --cc=James.Bottomley@SteelEye.com \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    --cc=stable@kernel.org \
    --cc=stefanr@s5r6.in-berlin.de \
    --cc=torvalds@osdl.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /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