linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: blktrans: fix integer overflow
@ 2015-08-21 14:57 Peng Fan
  2015-09-02 17:02 ` Brian Norris
  0 siblings, 1 reply; 4+ messages in thread
From: Peng Fan @ 2015-08-21 14:57 UTC (permalink / raw)
  To: dwmw2, computersforpeace; +Cc: linux-mtd, linux-kernel, van.freenix

In drivers/mtd/mtd_blkdevs.c:
406	set_capacity(gd, (new->size * tr->blksize) >> 9);
The type of new->size is unsigned long and the type of tr->blksize is int,
the result of 'new->size * tr->blksize' may exceed ULONG_MAX on 32bit
machines.

I use nand chip MT29F32G08CBADBWP which is 4GB and the parameters passed
to kernel is 'mtdparts=gpmi-nand:-(user)', the whole nand chip will be
treated as a 4GB mtd partition. new->size is 0x800000 and tr->blksize is
0x200, 'new->size * tr->blksize' however is 0. This is what we do not want
to see.

Change the type of entry size of mtd_blktrans_dev to unsigned long long
to fix the overflow issue.

Signed-off-by: Peng Fan <van.freenix@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Brian Norris <computersforpeace@gmail.com>
---
 include/linux/mtd/blktrans.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h
index e93837f..3853d74 100644
--- a/include/linux/mtd/blktrans.h
+++ b/include/linux/mtd/blktrans.h
@@ -38,7 +38,7 @@ struct mtd_blktrans_dev {
 	struct mutex lock;
 	int devnum;
 	bool bg_stop;
-	unsigned long size;
+	unsigned long long size;
 	int readonly;
 	int open;
 	struct kref ref;
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-09 23:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-21 14:57 [PATCH] mtd: blktrans: fix integer overflow Peng Fan
2015-09-02 17:02 ` Brian Norris
2015-09-05 13:42   ` Peng Fan
2015-09-09 23:37     ` Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).