Patchwork [09/13] mtd/jffs2: fix read buffer overflow

login
register
mail settings
Submitter Andrew Morton
Date Sept. 18, 2009, 7:51 p.m.
Message ID <200909181951.n8IJpnZg023824@imap1.linux-foundation.org>
Download mbox | patch
Permalink /patch/33889/
State New, archived
Headers show

Comments

Andrew Morton - Sept. 18, 2009, 7:51 p.m.
From: Roel Kluin <roel.kluin@gmail.com>

Prevent a read from mtd->eraseregions[-1]

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/mtd/devices/lart.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch

diff -puN drivers/mtd/devices/lart.c~mtd-jffs2-fix-read-buffer-overflow drivers/mtd/devices/lart.c
--- a/drivers/mtd/devices/lart.c~mtd-jffs2-fix-read-buffer-overflow
+++ a/drivers/mtd/devices/lart.c
@@ -393,7 +393,8 @@  static int flash_erase (struct mtd_info 
 	* erase range is aligned with the erase size which is in
 	* effect here.
 	*/
-   if (instr->addr & (mtd->eraseregions[i].erasesize - 1)) return (-EINVAL);
+   if (i < 0 || (instr->addr & (mtd->eraseregions[i].erasesize - 1)))
+      return -EINVAL;
 
    /* Remember the erase region we start on */
    first = i;
@@ -409,7 +410,8 @@  static int flash_erase (struct mtd_info 
    i--;
 
    /* is the end aligned on a block boundary? */
-   if ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1)) return (-EINVAL);
+   if (i < 0 || ((instr->addr + instr->len) & (mtd->eraseregions[i].erasesize - 1)))
+      return -EINVAL;
 
    addr = instr->addr;
    len = instr->len;