mtd: mtdoops: limit the maximum mtd partition size

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Nov 30 07:59:03 EST 2009


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=1114e3d00f539ecb7a8415663f2a47a80e00a537
Commit:     1114e3d00f539ecb7a8415663f2a47a80e00a537
Parent:     be95745f01677245a061a8f51473ef5ec8ad008e
Author:     Simon Kagstrom <simon.kagstrom at netinsight.net>
AuthorDate: Tue Nov 3 08:08:41 2009 +0200
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Mon Nov 30 12:02:02 2009 +0000

    mtd: mtdoops: limit the maximum mtd partition size
    
    Make the maximum mtdoops partition size to be 8MiB. Indeed, it does
    not make sense to use anything larger than that anyway. This limit
    makes it possible to catch stupid mistakes where the user gives e.g.,
    a rootfs partition to mtdoops (which will happily erase it).
    
    Signed-off-by: Simon Kagstrom <simon.kagstrom at netinsight.net>
    Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/mtdoops.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 06c5382..b016eee 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -33,6 +33,9 @@
 #include <linux/interrupt.h>
 #include <linux/mtd/mtd.h>
 
+/* Maximum MTD partition size */
+#define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024)
+
 #define MTDOOPS_KERNMSG_MAGIC 0x5d005d00
 #define OOPS_PAGE_SIZE 4096
 
@@ -310,6 +313,12 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
 		return;
 	}
 
+	if (mtd->size > MTDOOPS_MAX_MTD_SIZE) {
+		printk(KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n",
+		       mtd->index, MTDOOPS_MAX_MTD_SIZE / 1024 / 1024);
+		return;
+	}
+
 	/* oops_page_used is a bit field */
 	cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages,
 			BITS_PER_LONG));
@@ -317,14 +326,10 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
 		printk(KERN_ERR "Could not allocate page array\n");
 		return;
 	}
-	cxt->mtd = mtd;
-	if (mtd->size > INT_MAX)
-		cxt->oops_pages = INT_MAX / OOPS_PAGE_SIZE;
-	else
-		cxt->oops_pages = (int)mtd->size / OOPS_PAGE_SIZE;
 
+	cxt->mtd = mtd;
+	cxt->oops_pages = (int)mtd->size / OOPS_PAGE_SIZE;
 	find_next_position(cxt);
-
 	printk(KERN_INFO "mtdoops: Attached to MTD device %d\n", mtd->index);
 }
 



More information about the linux-mtd-cvs mailing list