Skip to contentSkip to conversation

MTD/JFFS2: Read buffer overflow

PATCH New Roel Kluin 1 participant 1 message Aug 8, 2009 Memory technology devices (MTD)

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 MTD/JFFS2: Read buffer overflow

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

---

drivers/mtd/devices/lart.c +4 -2
index 578de1c..f4359fe 100644
@@ -393,7 +393,8 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
 	* 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 *mtd,struct erase_info *instr)
    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;