From: Suresh Siddha <suresh.b.siddha@intel.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Sasha Levin <levinsasha928@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
dwmw2@infradead.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
linux-mtd@lists.infradead.org, linux-mm <linux-mm@kvack.org>,
Dave Jones <davej@redhat.com>
Subject: Re: mtd: kernel BUG at arch/x86/mm/pat.c:279!
Date: Fri, 07 Sep 2012 15:42:58 -0700 [thread overview]
Message-ID: <1347057778.26695.68.camel@sbsiddha-desk.sc.intel.com> (raw)
In-Reply-To: <CA+55aFzJCLxVP+WYJM-gq=aXx5gmdgwC7=_Gr2Tooj8q+Dz4dw@mail.gmail.com>
On Fri, 2012-09-07 at 11:14 -0700, Linus Torvalds wrote:
> Guys, this looks like a MTD and/or io_remap_pfn_range() bug, and it's
> not getting any traction.
>
> What the f*ck is mtd_mmap() doing, and why? The problem seems to be an
> overflow condition, because reserve_pfn_range() does
>
> reserve_memtype(paddr, paddr + size, want_flags, &flags);
>
> and then the BUG_ON() in reserve_memtype is
>
> BUG_ON(start >= end);
>
> so it very much looks like a paddr+size overflow. However, that makes
> little sense too, since we're working in "u64", so I suspect the
> overflow has happened somewhere earlier.
>
> I really don't see where, though. Could somebody please take a look?
> The mtdchar_mmap() types seem insane (why "u32" for len, for example?
> And that whole
>
> off = vma->vm_pgoff << PAGE_SHIFT;
>
> thing looks like it would overflow, since the whole point of pgoff is
> that if you shift it up by PAGE_SHIFT you need to also extend to
> 64-bit etc.
>
> So I would *guess* that it's the mtdchar_mmap() stuff that overflows
> due to bad types, but maybe it does deeper than that?
>
I started to look into this to see if this is a PAT issue but it does
indeed appear to be a mtd mmap issue.
Sasha, Does the appended fix the issue for you?
--8<--
From: Suresh Siddha <suresh.b.siddha@intel.com>
Subject: mtd: check the starting offset to be mmap'd
We need to check if both the starting offset aswell the total length
being mmap'd are with in the limits. With a large starting offset,
offset + (length-to-be-mapped) can wrap and appear smaller than the
limit. Need to check both start and end.
Also fix the types of the variables start, off, len.
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---
drivers/mtd/mtdchar.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index f2f482b..f79c0fa 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1132,16 +1132,15 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
struct mtd_file_info *mfi = file->private_data;
struct mtd_info *mtd = mfi->mtd;
struct map_info *map = mtd->priv;
- unsigned long start;
- unsigned long off;
- u32 len;
+ resource_size_t start, off;
+ unsigned long len;
if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) {
off = vma->vm_pgoff << PAGE_SHIFT;
start = map->phys;
len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
start &= PAGE_MASK;
- if ((vma->vm_end - vma->vm_start + off) > len)
+ if (off >= len || (vma->vm_end - vma->vm_start + off) > len)
return -EINVAL;
off += start;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-09-07 22:44 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-29 8:48 Sasha Levin
2012-07-30 11:00 ` Sasha Levin
2012-09-07 16:55 ` Sasha Levin
2012-09-07 18:14 ` Linus Torvalds
2012-09-07 22:42 ` Suresh Siddha [this message]
2012-09-07 23:09 ` Linus Torvalds
2012-09-07 23:54 ` Suresh Siddha
2012-09-08 19:57 ` Linus Torvalds
2012-09-09 14:56 ` Suresh Siddha
2012-09-09 15:31 ` Linus Torvalds
2012-09-09 17:01 ` H. Peter Anvin
2012-09-12 10:50 ` Sasha Levin
2012-09-12 10:56 ` Sasha Levin
2012-09-28 9:00 ` Sasha Levin
2012-09-28 16:44 ` Linus Torvalds
2012-09-28 18:05 ` Artem Bityutskiy
2012-09-28 19:13 ` Linus Torvalds
2012-09-28 19:44 ` Sasha Levin
2012-09-28 19:04 ` David Woodhouse
2012-09-28 19:15 ` richard -rw- weinberger
2012-09-28 19:18 ` richard -rw- weinberger
2012-09-29 16:11 ` David Woodhouse
2012-09-29 16:34 ` David Woodhouse
2012-09-09 16:56 ` H. Peter Anvin
2012-09-09 19:04 ` David Woodhouse
2012-09-09 20:33 ` H. Peter Anvin
2012-09-10 5:17 ` Sasha Levin
2012-09-08 8:10 ` Sasha Levin
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=1347057778.26695.68.camel@sbsiddha-desk.sc.intel.com \
--to=suresh.b.siddha@intel.com \
--cc=akpm@linux-foundation.org \
--cc=davej@redhat.com \
--cc=dwmw2@infradead.org \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mtd@lists.infradead.org \
--cc=torvalds@linux-foundation.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