public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* misaligned memory access in cmdlinepart.c
@ 2005-04-27 11:03 Timofei V. Bondarenko
  2005-06-06 13:26 ` Timofei V. Bondarenko
  2005-06-06 13:34 ` Jörn Engel
  0 siblings, 2 replies; 11+ messages in thread
From: Timofei V. Bondarenko @ 2005-04-27 11:03 UTC (permalink / raw)
  To: linux-mtd

Hi,

in mtdpart_setup_real()/newpart() command line parser
'this_mtd' structure can be misaligned,
it may cause exception on some kind of CPU.

That happened because the structure allocated in a variable length area 
and got mixed with partition names.

The patch follows.

Regards.
	Timofei.

--- cmdlinepart.c	2005-04-18 18:06:43.000000000 +0400
+++ linux-2.6.x/drivers/mtd/cmdlinepart.c	2005-04-18 18:40:02.971778640 
+0400
@@ -234,12 +234,14 @@ static int mtdpart_setup_real(char *s)
  		 * parse one mtd. have it reserve memory for the
  		 * struct cmdline_mtd_partition and the mtd-id string.
  		 */
+#define THIS_MTD_ALIGN_CONST (sizeof(void*)-1)
  		parts = newpart(p + 1,		/* cmdline */
  				&s,		/* out: updated cmdline ptr */
  				&num_parts,	/* out: number of parts */
  				0,		/* first partition */
  				(unsigned char**)&this_mtd, /* out: extra mem */
-				mtd_id_len + 1 + sizeof(*this_mtd));
+				mtd_id_len + 1 + sizeof(*this_mtd) +
+                                THIS_MTD_ALIGN_CONST);
  		if(!parts)
  		{
  			/*
@@ -252,7 +254,11 @@ static int mtdpart_setup_real(char *s)
  			 return 0;
  		 }

-		/* enter results */	
+		/* align this_mtd */
+                this_mtd = (struct cmdline_mtd_partition *)
+                  (~THIS_MTD_ALIGN_CONST &
+                    THIS_MTD_ALIGN_CONST + (unsigned long)(char*)this_mtd);
+		/* enter results */
  		this_mtd->parts = parts;
  		this_mtd->num_parts = num_parts;
  		this_mtd->mtd_id = (char*)(this_mtd + 1);

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

end of thread, other threads:[~2005-06-07 13:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-27 11:03 misaligned memory access in cmdlinepart.c Timofei V. Bondarenko
2005-06-06 13:26 ` Timofei V. Bondarenko
2005-06-06 13:34 ` Jörn Engel
     [not found]   ` <42A4572C.8020107@ipi.ac.ru>
     [not found]     ` <20050606141453.GF31739@wohnheim.fh-wedel.de>
2005-06-06 15:28       ` Timofei V. Bondarenko
     [not found]       ` <42A460BB.50800@ipi.ac.ru>
     [not found]         ` <20050606162648.GJ31739@wohnheim.fh-wedel.de>
2005-06-06 16:49           ` Timofei V. Bondarenko
2005-06-06 17:44             ` Jörn Engel
2005-06-07  8:30               ` Timofei V. Bondarenko
2005-06-07  9:01                 ` Vitaly Wool
2005-06-07  9:26                   ` Timofei V. Bondarenko
2005-06-07 11:34                   ` Timofei V. Bondarenko
2005-06-07 13:02                 ` Jörn Engel

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