public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: stable@kernel.org, Linus Torvalds <torvalds@osdl.org>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	Al Viro <viro@ftp.linux.org.uk>,
	Jody McIntyre <scjody@modernduck.com>
Subject: [PATCH 1/2] sd: fix memory corruption by sd_read_cache_type
Date: Thu, 23 Feb 2006 02:02:57 +0100 (CET)	[thread overview]
Message-ID: <tkrat.014f03dc41356221@s5r6.in-berlin.de> (raw)

sd: fix memory corruption by sd_read_cache_type

Let sd check more thoroughly before using mode_sense responses for data
length calculation. Fixes memory corruption ("slab error in
cache_free_debugcheck") or kernel panic when buggy disks are connected,
notably Initio SBP-2 bridges.
http://bugzilla.kernel.org/show_bug.cgi?id=6114
http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=182005

Taken from a patch by Al Viro <viro@ftp.linux.org.uk>.
http://marc.theaimsgroup.com/?l=linux-scsi&m=114055884611429

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
---
Patch is applicable to 2.6.14, 2.6.15, 2.6.16.

Index: linux-2.6.16-rc4/drivers/scsi/sd.c
===================================================================
--- linux-2.6.16-rc4.orig/drivers/scsi/sd.c	2006-02-22 22:27:42.000000000 +0100
+++ linux-2.6.16-rc4/drivers/scsi/sd.c	2006-02-22 22:29:10.000000000 +0100
@@ -1342,6 +1342,8 @@ sd_read_cache_type(struct scsi_disk *sdk
 
 	/* Take headers and block descriptors into account */
 	len += data.header_length + data.block_descriptor_length;
+	if (len > 512)
+		goto bad_sense;
 
 	/* Get the data */
 	res = sd_do_mode_sense(sdp, dbd, modepage, buffer, len, &data, &sshdr);
@@ -1354,6 +1356,12 @@ sd_read_cache_type(struct scsi_disk *sdk
 		int ct = 0;
 		int offset = data.header_length + data.block_descriptor_length;
 
+		if (offset >= 512 - 2) {
+			printk(KERN_ERR "%s: malformed MODE SENSE response",
+				diskname);
+			goto defaults;
+		}
+
 		if ((buffer[offset] & 0x3f) != modepage) {
 			printk(KERN_ERR "%s: got wrong page\n", diskname);
 			goto defaults;



             reply	other threads:[~2006-02-23  1:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-23  1:02 Stefan Richter [this message]
2006-02-25  2:10 ` [stable] [PATCH 1/2] sd: fix memory corruption by sd_read_cache_type Chris Wright
2006-02-25 23:07   ` Stefan Richter
2006-02-25 23:22     ` Al Viro
2006-02-26  8:11       ` Stefan Richter
2006-02-26  8:22         ` Al Viro
2006-02-26  9:11           ` Stefan Richter
2006-02-26  0:01     ` Linus Torvalds
2006-02-26  0:17       ` Al Viro
2006-02-26  0:39         ` Linus Torvalds
2006-02-26  8:39           ` Jeff Garzik
2006-02-26  9:00             ` Al Viro
2006-02-26 10:45               ` Jeff Garzik
2006-02-26 11:47                 ` Al Viro
2006-02-26  5:14       ` James Bottomley
2006-02-26  5:31         ` Al Viro
2006-02-26  8:29           ` Stefan Richter
2006-02-26 14:34           ` James Bottomley
2006-02-26 14:57             ` Al Viro
2006-02-26 16:21             ` Stefan Richter

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=tkrat.014f03dc41356221@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=scjody@modernduck.com \
    --cc=stable@kernel.org \
    --cc=torvalds@osdl.org \
    --cc=viro@ftp.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