Skip to content

Commit 1114e3d

Browse files
Simon KagstromDavid Woodhouse
authored andcommitted
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@netinsight.net> Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent be95745 commit 1114e3d

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎drivers/mtd/mtdoops.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include <linux/interrupt.h>
3434
#include <linux/mtd/mtd.h>
3535

36+
/* Maximum MTD partition size */
37+
#define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024)
38+
3639
#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00
3740
#define OOPS_PAGE_SIZE 4096
3841

@@ -310,21 +313,23 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
310313
return;
311314
}
312315

316+
if (mtd->size > MTDOOPS_MAX_MTD_SIZE) {
317+
printk(KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n",
318+
mtd->index, MTDOOPS_MAX_MTD_SIZE / 1024 / 1024);
319+
return;
320+
}
321+
313322
/* oops_page_used is a bit field */
314323
cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages,
315324
BITS_PER_LONG));
316325
if (!cxt->oops_page_used) {
317326
printk(KERN_ERR "Could not allocate page array\n");
318327
return;
319328
}
320-
cxt->mtd = mtd;
321-
if (mtd->size > INT_MAX)
322-
cxt->oops_pages = INT_MAX / OOPS_PAGE_SIZE;
323-
else
324-
cxt->oops_pages = (int)mtd->size / OOPS_PAGE_SIZE;
325329

330+
cxt->mtd = mtd;
331+
cxt->oops_pages = (int)mtd->size / OOPS_PAGE_SIZE;
326332
find_next_position(cxt);
327-
328333
printk(KERN_INFO "mtdoops: Attached to MTD device %d\n", mtd->index);
329334
}
330335

0 commit comments

Comments
 (0)