From: "Timofei V. Bondarenko" <timm@ipi.ac.ru>
To: linux-mtd@lists.infradead.org
Subject: Bug: misaligned memory access in cmdlinepart.c
Date: Mon, 18 Apr 2005 15:30:42 -0000 [thread overview]
Message-ID: <4263D29B.704@ipi.ac.ru> (raw)
[-- Attachment #1: Type: text/plain, Size: 324 bytes --]
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 got mixed with partition names
allocated in a variable length area.
I've attached a simle patch, not very elegant though.
Regards.
Timofei.
[-- Attachment #2: alignnewpart.diff --]
[-- Type: text/plain, Size: 1205 bytes --]
--- cmdlinepart.c 2005-04-18 18:06:43.000000000 +0400
+++ bfin/uClinux-dist/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);
reply other threads:[~2005-04-18 15:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4263D29B.704@ipi.ac.ru \
--to=timm@ipi.ac.ru \
--cc=linux-mtd@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.