Discussion:
[PATCH] mtd: spi-nor: cast to u64 to avoid uint overflows
Huijin Park
2018-11-13 05:18:38 UTC
Permalink
From: "huijin.park" <***@samsung.com>

The "params->size" is defined as "u64".
And "info->sector_size" and "info->n_sectors" are defined as
unsigned int and u16.
Thus, u64 data might have strange data(loss data) if the result
overflows an unsigned int.
This patch casts "info->sector_size" and "info->n_sectors" to an u64.

Signed-off-by: huijin.park <***@samsung.com>
---
drivers/mtd/spi-nor/spi-nor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index d9c368c..527f281 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2459,7 +2459,7 @@ static int spi_nor_init_params(struct spi_nor *nor,
memset(params, 0, sizeof(*params));

/* Set SPI NOR sizes. */
- params->size = info->sector_size * info->n_sectors;
+ params->size = (u64)info->sector_size * (u64)info->n_sectors;
params->page_size = info->page_size;

/* (Fast) Read settings. */
--
1.7.9.5
Yogesh Narayan Gaur
2018-11-13 06:39:07 UTC
Permalink
Hi Huijin,

I guess this is the v2 of previously send patch [1], please follow version information in patch submission.

--
Regards
Yogesh Gaur
[1] https://patchwork.ozlabs.org/patch/961197/
-----Original Message-----
Huijin Park
Sent: Tuesday, November 13, 2018 10:49 AM
Subject: [PATCH] mtd: spi-nor: cast to u64 to avoid uint overflows
The "params->size" is defined as "u64".
And "info->sector_size" and "info->n_sectors" are defined as unsigned int and
u16.
Thus, u64 data might have strange data(loss data) if the result overflows an
unsigned int.
This patch casts "info->sector_size" and "info->n_sectors" to an u64.
---
drivers/mtd/spi-nor/spi-nor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index
d9c368c..527f281 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2459,7 +2459,7 @@ static int spi_nor_init_params(struct spi_nor *nor,
memset(params, 0, sizeof(*params));
/* Set SPI NOR sizes. */
- params->size = info->sector_size * info->n_sectors;
+ params->size = (u64)info->sector_size * (u64)info->n_sectors;
params->page_size = info->page_size;
/* (Fast) Read settings. */
--
1.7.9.5
______________________________________________________
Linux MTD discussion mailing list
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.infr
adead.org%2Fmailman%2Flistinfo%2Flinux-
mtd%2F&amp;data=02%7C01%7Cyogeshnarayan.gaur%40nxp.com%7C5efd964
86c7244f430b408d649278b65%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%
7C1%7C636776831529836639&amp;sdata=A7hiJMpfxXKTyT6yacIougPRGdHg2o
pL492y3sVtQek%3D&amp;reserved=0
Loading...