linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] sd: fix memory corruption by sd_read_cache_type
@ 2006-02-23  1:02 Stefan Richter
  2006-02-25  2:10 ` [stable] " Chris Wright
  0 siblings, 1 reply; 22+ messages in thread
From: Stefan Richter @ 2006-02-23  1:02 UTC (permalink / raw)
  To: stable, Linus Torvalds; +Cc: linux-kernel, linux-scsi, Al Viro, Jody McIntyre

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;



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

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

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-23  1:02 [PATCH 1/2] sd: fix memory corruption by sd_read_cache_type Stefan Richter
2006-02-25  2:10 ` [stable] " 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
2006-02-26 23:16     ` [PATCH 2.6.15.4 update] sd: fix memory corruption with broken mode page headers Stefan Richter
2006-02-27 20:25       ` [stable] " Chris Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).