Patchwork [MTD,NAND] nand_base.c: Fixing past end of the page read, in nand_do_read_oob

login
register
mail settings
Submitter Singh, Vimal
Date July 7, 2009, 11:56 a.m.
Message ID <61715.192.168.10.89.1246967804.squirrel@dbdmail.itg.ti.com>
Download mbox | patch
Permalink /patch/29526/
State New, archived
Headers show

Comments

Singh, Vimal - July 7, 2009, 11:56 a.m.
Check for reading past end of the page, in the function 'nand_do_read_oob', was
missing. This patch fixes it.

Signed-off-by: Vimal Singh <vimalsingh@ti.com>
---
This bug was found while testing with 'NAND test modules: oobtest' (maintained
by Adrian Hunter).
http://git.infradead.org/users/ahunter/nand-tests.git

Patch

--- a/drivers/mtd/nand/nand_base.c	2009-07-07 15:40:35.000000000 +0530
+++ b/drivers/mtd/nand/nand_base.c	2009-07-07 15:40:51.000000000 +0530
@@ -1427,6 +1427,13 @@  static int nand_do_read_oob(struct mtd_i
 		return -EINVAL;
 	}

+	/* Do not allow read past end of page */
+	if ((ops->ooboffs + ops->ooblen) > len) {
+		DEBUG(MTD_DEBUG_LEVEL0, "%s: Attempt to read "
+				"past end of page\n", __func__);
+		return -EINVAL;
+	}
+
 	/* Do not allow reads past end of device */
 	if (unlikely(from >= mtd->size ||
 		     ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) -