public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] megaraid driver fix for 2.5.70
@ 2003-06-03 14:29 Mark Haverkamp
  2003-06-05 14:07 ` James Bottomley
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Haverkamp @ 2003-06-03 14:29 UTC (permalink / raw)
  To: Linus Torvalds, James Bottomley; +Cc: linux-kernel, linux-scsi

A recent change to the megaraid driver to fix some memset calls resulted
in overflowing the arrays being cleared and causing a system panic. 
This patch fixes the problem by making sure that the arrays being
cleared are dimensioned to the correct size.  The patch has been tested
on osdl's stp machines that have megaraid controllers.



===== drivers/scsi/megaraid.c 1.45 vs edited =====
--- 1.45/drivers/scsi/megaraid.c	Sat May 17 14:09:51 2003
+++ edited/drivers/scsi/megaraid.c	Tue Jun  3 07:25:23 2003
@@ -723,7 +723,7 @@
 {
 	dma_addr_t	prod_info_dma_handle;
 	mega_inquiry3	*inquiry3;
-	u8	raw_mbox[16];
+	u8	raw_mbox[sizeof(mbox_t)];
 	mbox_t	*mbox;
 	int	retval;
 
@@ -732,7 +732,7 @@
 	mbox = (mbox_t *)raw_mbox;
 
 	memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
-	memset(mbox, 0, 16);
+	memset(mbox, 0, sizeof(*mbox));
 
 	/*
 	 * Try to issue Inquiry3 command
@@ -2415,7 +2415,7 @@
 {
 	adapter_t	*adapter;
 	mbox_t	*mbox;
-	u_char	raw_mbox[16];
+	u_char	raw_mbox[sizeof(mbox_t)];
 	char	buf[12] = { 0 };
 
 	adapter = (adapter_t *)host->hostdata;
@@ -2424,7 +2424,7 @@
 	printk(KERN_NOTICE "megaraid: being unloaded...");
 
 	/* Flush adapter cache */
-	memset(mbox, 0, 16);
+	memset(mbox, 0, sizeof(*mbox));
 	raw_mbox[0] = FLUSH_ADAPTER;
 
 	irq_disable(adapter);
@@ -2434,7 +2434,7 @@
 	issue_scb_block(adapter, raw_mbox);
 
 	/* Flush disks cache */
-	memset(mbox, 0, 16);
+	memset(mbox, 0, sizeof(*mbox));
 	raw_mbox[0] = FLUSH_SYSTEM;
 
 	/* Issue a blocking (interrupts disabled) command to the card */
@@ -3896,7 +3896,7 @@
 {
 	adapter_t *adapter;
 	struct Scsi_Host *host;
-	u8 raw_mbox[16];
+	u8 raw_mbox[sizeof(mbox_t)];
 	mbox_t *mbox;
 	int i,j;
 
@@ -3912,7 +3912,7 @@
 		mbox = (mbox_t *)raw_mbox;
 
 		/* Flush adapter cache */
-		memset(mbox, 0, 16);
+		memset(mbox, 0, sizeof(*mbox));
 		raw_mbox[0] = FLUSH_ADAPTER;
 
 		irq_disable(adapter);
@@ -3925,7 +3925,7 @@
 		issue_scb_block(adapter, raw_mbox);
 
 		/* Flush disks cache */
-		memset(mbox, 0, 16);
+		memset(mbox, 0, sizeof(*mbox));
 		raw_mbox[0] = FLUSH_SYSTEM;
 
 		issue_scb_block(adapter, raw_mbox);
@@ -4658,7 +4658,7 @@
 static int
 mega_is_bios_enabled(adapter_t *adapter)
 {
-	unsigned char	raw_mbox[16];
+	unsigned char	raw_mbox[sizeof(mbox_t)];
 	mbox_t	*mbox;
 	int	ret;
 
@@ -4691,7 +4691,7 @@
 static void
 mega_enum_raid_scsi(adapter_t *adapter)
 {
-	unsigned char raw_mbox[16];
+	unsigned char raw_mbox[sizeof(mbox_t)];
 	mbox_t *mbox;
 	int i;
 
@@ -4746,7 +4746,7 @@
 mega_get_boot_drv(adapter_t *adapter)
 {
 	struct private_bios_data	*prv_bios_data;
-	unsigned char	raw_mbox[16];
+	unsigned char	raw_mbox[sizeof(mbox_t)];
 	mbox_t	*mbox;
 	u16	cksum = 0;
 	u8	*cksum_p;
@@ -4812,7 +4812,7 @@
 static int
 mega_support_random_del(adapter_t *adapter)
 {
-	unsigned char raw_mbox[16];
+	unsigned char raw_mbox[sizeof(mbox_t)];
 	mbox_t *mbox;
 	int rval;
 
@@ -4841,7 +4841,7 @@
 static int
 mega_support_ext_cdb(adapter_t *adapter)
 {
-	unsigned char raw_mbox[16];
+	unsigned char raw_mbox[sizeof(mbox_t)];
 	mbox_t *mbox;
 	int rval;
 
@@ -4959,7 +4959,7 @@
 static void
 mega_get_max_sgl(adapter_t *adapter)
 {
-	unsigned char	raw_mbox[16];
+	unsigned char	raw_mbox[sizeof(mbox_t)];
 	mbox_t	*mbox;
 
 	mbox = (mbox_t *)raw_mbox;
@@ -5004,7 +5004,7 @@
 static int
 mega_support_cluster(adapter_t *adapter)
 {
-	unsigned char	raw_mbox[16];
+	unsigned char	raw_mbox[sizeof(mbox_t)];
 	mbox_t	*mbox;
 
 	mbox = (mbox_t *)raw_mbox;



-- 
Mark Haverkamp <markh@osdl.org>


^ permalink raw reply	[flat|nested] 9+ messages in thread
* RE: [PATCH] megaraid driver fix for 2.5.70
@ 2003-06-06 13:28 Mukker, Atul
  2003-06-06 13:46 ` James Bottomley
  0 siblings, 1 reply; 9+ messages in thread
From: Mukker, Atul @ 2003-06-06 13:28 UTC (permalink / raw)
  To: 'James Bottomley', Mark Haverkamp
  Cc: Mukker, Atul, Linus Torvalds, Linux Kernel, linux-scsi

> > In the memset cases, what fixed the panic was that the size of the
> > raw_mbox automatic was set to 16 and the memset was using
> > sizeof(mbox_t).  I just increased the size of the raw_mbox so it
> > wouldn't be overflowed.  It sounds like, from what you are 
> saying, that
> > the size of raw_mbox should have been left at 16 and the 
> memset changed
> > to fill 16 bytes and not the sizeof(mbox_t).
> 
> Ah, that's what I couldn't find in the source, thanks.

This is correct. Driver sets up first 16 bytes and firmware sets up rest.
Busy bit is special, driver sets it and firmware clears it.


> I was also separately worried about the memcpy in the issue_scb..()
> routines which looks like it will set the mbox->busy parameter
> (controlled by the driver) to zero.  So I copied Atul to see 
> if this is
> a genuine problem or not.

This is ok. Driver has to set it to busy anyway.

Coming back to main issue, declaring complete mailbox would be superfluous
since driver uses 16 bytes at most. The following patch should fix the panic

--- /usr/src/linux-2.5.70/drivers/scsi/megaraid.c	2003-05-26
21:00:20.000000000 -0400
+++ megaraid.c	2003-06-06 09:14:24.000000000 -0400
@@ -4664,7 +4664,7 @@
 
 	mbox = (mbox_t *)raw_mbox;
 
-	memset(mbox, 0, sizeof(*mbox));
+	memset(mbox, 0, 16);
 
 	memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
 
@@ -4697,7 +4697,7 @@
 
 	mbox = (mbox_t *)raw_mbox;
 
-	memset(mbox, 0, sizeof(*mbox));
+	memset(mbox, 0, 16);
 
 	/*
 	 * issue command to find out what channels are raid/scsi
@@ -4813,12 +4813,9 @@
 mega_support_random_del(adapter_t *adapter)
 {
 	unsigned char raw_mbox[16];
-	mbox_t *mbox;
 	int rval;
 
-	mbox = (mbox_t *)raw_mbox;
-
-	memset(mbox, 0, sizeof(*mbox));
+	memset(raw_mbox, 0, 16);
 
 	/*
 	 * issue command
@@ -4842,12 +4839,9 @@
 mega_support_ext_cdb(adapter_t *adapter)
 {
 	unsigned char raw_mbox[16];
-	mbox_t *mbox;
 	int rval;
 
-	mbox = (mbox_t *)raw_mbox;
-
-	memset(mbox, 0, sizeof(*mbox));
+	memset(raw_mbox, 0, 16);
 	/*
 	 * issue command to find out if controller supports extended CDBs.
 	 */


^ permalink raw reply	[flat|nested] 9+ messages in thread
* RE: [PATCH] megaraid driver fix for 2.5.70
@ 2003-06-06 15:03 Mukker, Atul
  0 siblings, 0 replies; 9+ messages in thread
From: Mukker, Atul @ 2003-06-06 15:03 UTC (permalink / raw)
  To: 'James Bottomley'
  Cc: Mark Haverkamp, Linus Torvalds, Linux Kernel, linux-scsi

> > Coming back to main issue, declaring complete mailbox would 
> be superfluous
> > since driver uses 16 bytes at most. The following patch 
> should fix the panic
> > 
> >  	mbox = (mbox_t *)raw_mbox;
> >  
> > -	memset(mbox, 0, sizeof(*mbox));
> > +	memset(mbox, 0, 16);
> >  
> >  	memset((void *)adapter->mega_buffer, 0, MEGA_BUFFER_SIZE);
> >  
> 
> This, I think, is a bad idea.  It looks intrinsically wrong 
> to allocate
> storage and assign a pointer to it of a type that is longer than the
> allocated storage.  The initial buffer overrun was due to 
> problems with
> this.

IMO then, your original patch should be good.


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

end of thread, other threads:[~2003-06-06 14:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-03 14:29 [PATCH] megaraid driver fix for 2.5.70 Mark Haverkamp
2003-06-05 14:07 ` James Bottomley
2003-06-05 14:33   ` Mark Haverkamp
2003-06-05 14:42     ` James Bottomley
2003-06-05 14:46       ` Mark Haverkamp
  -- strict thread matches above, loose matches on Subject: below --
2003-06-06 13:28 Mukker, Atul
2003-06-06 13:46 ` James Bottomley
2003-06-06 14:15   ` Mark Haverkamp
2003-06-06 15:03 Mukker, Atul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox