From: "Gavin Lambert" <gavinl@compacsort.com>
To: <dedekind@infradead.org>
Cc: linux-mtd@lists.infradead.org
Subject: RE: MTD pointer alignment
Date: Mon, 4 Dec 2006 10:43:21 +1300 [thread overview]
Message-ID: <030e01c71724$1c4a95a0$4800a8c0@gavinlpc> (raw)
In-Reply-To: <1164961120.576.79.camel@sauron>
Quoth Artem Bityutskiy [dedekind@infradead.org]:
> On Wed, 2006-11-29 at 13:09 +1300, Gavin Lambert wrote:
>> Given that mtdchar assumes that it can mess with the low 2 bits of
>> the MTD pointer it keeps around with impunity, add_mtd_device in
>> mtdcore.c should probably refuse to add any MTD device pointer that
>> doesn't fall on a 4-byte boundary.
>
> Hmm, I personally I do not understand what is this about.
In mtdchar.c, when an MTD character device is opened (mtd_open), its
pointer value is assigned to file->private_data. All subsequent
operations then use the TO_MTD macro, which is defined as:
#define TO_MTD(file) (struct mtd_info *)((long)((file)->private_data) &
~3L)
(ie. masking off the lower two bits). There's even a comment above that
those bits have been hijacked for OTP modes, and it's expecting that
alignment of the pointer is at least 32 bits.
While this is true for a standalone kalloc'd MTD structure, if the MTD
structure is embedded within another structure then it is not
necessarily the case. Since struct mtd_info starts with a byte-sized
field, the default padding rules say that the structure as a whole is
allowed to start on a byte boundary (although on many arches it'll get
16-bit aligned regardless). Hence the 32-bit alignment is most
definitely *not* guaranteed.
If you're going to hijack the bits then you should at the very least
test your assertion in either mtd_open or add_mtd_device, by making it
reject MTD devices that aren't aligned as you'd expect. Otherwise it
leads to a whole raft of weird bugs.
As I said before, though, I'm looking at the MTD sources as of kernel
2.6.15. It's possible this has been sorted out since then. If so, I
apologise.
next prev parent reply other threads:[~2006-12-03 21:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-29 0:09 MTD pointer alignment Gavin Lambert
2006-12-01 8:18 ` Artem Bityutskiy
2006-12-03 21:43 ` Gavin Lambert [this message]
2006-12-04 13:37 ` David Woodhouse
2006-12-04 21:11 ` Gavin Lambert
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='030e01c71724$1c4a95a0$4800a8c0@gavinlpc' \
--to=gavinl@compacsort.com \
--cc=dedekind@infradead.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox