All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation
@ 2017-11-08 15:46 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2017-11-08 15:46 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, Andrea Adami, linux-mtd
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Multiplying block_num and mtd->erasesize may potentially overflow
as they are both unsigned ints and so the multiplication is evaluated
in unsigned int arithmetic .  Cast block_adr to off_t to ensure
multiplication is off_t sized to avoid any potential overflow.

Detected by CoverityScan, CID#1461264 ("Unintentional integer overflow")

Fixes: fff1e32a50c0 ("mtd: sharpslpart: Add sharpslpart partition parser")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/mtd/parsers/sharpslpart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/parsers/sharpslpart.c b/drivers/mtd/parsers/sharpslpart.c
index 5fe0079ea5ed..b1d97aa3bac4 100644
--- a/drivers/mtd/parsers/sharpslpart.c
+++ b/drivers/mtd/parsers/sharpslpart.c
@@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info *mtd,
 		return -EINVAL;
 
 	block_num = ftl->log2phy[log_num];
-	block_adr = block_num * mtd->erasesize;
+	block_adr = (loff_t)block_num * mtd->erasesize;
 	block_ofs = mtd_mod_by_eb((u32)from, mtd);
 
 	err = mtd_read(mtd, block_adr + block_ofs, len, &retlen, buf);
-- 
2.14.1

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

* [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation
@ 2017-11-08 15:46 ` Colin King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin King @ 2017-11-08 15:46 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, Andrea Adami, linux-mtd
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Multiplying block_num and mtd->erasesize may potentially overflow
as they are both unsigned ints and so the multiplication is evaluated
in unsigned int arithmetic .  Cast block_adr to off_t to ensure
multiplication is off_t sized to avoid any potential overflow.

Detected by CoverityScan, CID#1461264 ("Unintentional integer overflow")

Fixes: fff1e32a50c0 ("mtd: sharpslpart: Add sharpslpart partition parser")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/mtd/parsers/sharpslpart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/parsers/sharpslpart.c b/drivers/mtd/parsers/sharpslpart.c
index 5fe0079ea5ed..b1d97aa3bac4 100644
--- a/drivers/mtd/parsers/sharpslpart.c
+++ b/drivers/mtd/parsers/sharpslpart.c
@@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info *mtd,
 		return -EINVAL;
 
 	block_num = ftl->log2phy[log_num];
-	block_adr = block_num * mtd->erasesize;
+	block_adr = (loff_t)block_num * mtd->erasesize;
 	block_ofs = mtd_mod_by_eb((u32)from, mtd);
 
 	err = mtd_read(mtd, block_adr + block_ofs, len, &retlen, buf);
-- 
2.14.1


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

* NAK: [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation
  2017-11-08 15:46 ` Colin King
@ 2017-11-08 15:57   ` Colin Ian King
  -1 siblings, 0 replies; 6+ messages in thread
From: Colin Ian King @ 2017-11-08 15:57 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, Andrea Adami, linux-mtd
  Cc: kernel-janitors, linux-kernel

On 08/11/17 15:46, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Multiplying block_num and mtd->erasesize may potentially overflow
> as they are both unsigned ints and so the multiplication is evaluated
> in unsigned int arithmetic .  Cast block_adr to off_t to ensure
> multiplication is off_t sized to avoid any potential overflow.
> 
> Detected by CoverityScan, CID#1461264 ("Unintentional integer overflow")
> 
> Fixes: fff1e32a50c0 ("mtd: sharpslpart: Add sharpslpart partition parser")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/mtd/parsers/sharpslpart.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/parsers/sharpslpart.c b/drivers/mtd/parsers/sharpslpart.c
> index 5fe0079ea5ed..b1d97aa3bac4 100644
> --- a/drivers/mtd/parsers/sharpslpart.c
> +++ b/drivers/mtd/parsers/sharpslpart.c
> @@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info *mtd,
>  		return -EINVAL;
>  
>  	block_num = ftl->log2phy[log_num];
> -	block_adr = block_num * mtd->erasesize;
> +	block_adr = (loff_t)block_num * mtd->erasesize;
>  	block_ofs = mtd_mod_by_eb((u32)from, mtd);
>  
>  	err = mtd_read(mtd, block_adr + block_ofs, len, &retlen, buf);
> 

Sorry, ignore this, there is another place that does this that needs
some attention. I'll sent V2 shortly.

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

* NAK: [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation
@ 2017-11-08 15:57   ` Colin Ian King
  0 siblings, 0 replies; 6+ messages in thread
From: Colin Ian King @ 2017-11-08 15:57 UTC (permalink / raw)
  To: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Richard Weinberger, Cyrille Pitchen, Andrea Adami, linux-mtd
  Cc: kernel-janitors, linux-kernel

On 08/11/17 15:46, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Multiplying block_num and mtd->erasesize may potentially overflow
> as they are both unsigned ints and so the multiplication is evaluated
> in unsigned int arithmetic .  Cast block_adr to off_t to ensure
> multiplication is off_t sized to avoid any potential overflow.
> 
> Detected by CoverityScan, CID#1461264 ("Unintentional integer overflow")
> 
> Fixes: fff1e32a50c0 ("mtd: sharpslpart: Add sharpslpart partition parser")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/mtd/parsers/sharpslpart.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/parsers/sharpslpart.c b/drivers/mtd/parsers/sharpslpart.c
> index 5fe0079ea5ed..b1d97aa3bac4 100644
> --- a/drivers/mtd/parsers/sharpslpart.c
> +++ b/drivers/mtd/parsers/sharpslpart.c
> @@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info *mtd,
>  		return -EINVAL;
>  
>  	block_num = ftl->log2phy[log_num];
> -	block_adr = block_num * mtd->erasesize;
> +	block_adr = (loff_t)block_num * mtd->erasesize;
>  	block_ofs = mtd_mod_by_eb((u32)from, mtd);
>  
>  	err = mtd_read(mtd, block_adr + block_ofs, len, &retlen, buf);
> 

Sorry, ignore this, there is another place that does this that needs
some attention. I'll sent V2 shortly.

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

* Re: NAK: [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation
  2017-11-08 15:57   ` Colin Ian King
@ 2017-11-08 16:01     ` Richard Weinberger
  -1 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2017-11-08 16:01 UTC (permalink / raw)
  To: Colin Ian King
  Cc: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Cyrille Pitchen, Andrea Adami, linux-mtd, kernel-janitors,
	linux-kernel

Colin,

Am Mittwoch, 8. November 2017, 16:57:57 CET schrieb Colin Ian King:
> On 08/11/17 15:46, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > Multiplying block_num and mtd->erasesize may potentially overflow
> > as they are both unsigned ints and so the multiplication is evaluated
> > in unsigned int arithmetic .  Cast block_adr to off_t to ensure
> > multiplication is off_t sized to avoid any potential overflow.
> > 
> > Detected by CoverityScan, CID#1461264 ("Unintentional integer overflow")
> > 
> > Fixes: fff1e32a50c0 ("mtd: sharpslpart: Add sharpslpart partition parser")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > 
> >  drivers/mtd/parsers/sharpslpart.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/parsers/sharpslpart.c
> > b/drivers/mtd/parsers/sharpslpart.c index 5fe0079ea5ed..b1d97aa3bac4
> > 100644
> > --- a/drivers/mtd/parsers/sharpslpart.c
> > +++ b/drivers/mtd/parsers/sharpslpart.c
> > @@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info
> > *mtd,> 
> >  		return -EINVAL;
> >  	
> >  	block_num = ftl->log2phy[log_num];
> > 
> > -	block_adr = block_num * mtd->erasesize;
> > +	block_adr = (loff_t)block_num * mtd->erasesize;
> > 
> >  	block_ofs = mtd_mod_by_eb((u32)from, mtd);
> >  	
> >  	err = mtd_read(mtd, block_adr + block_ofs, len, &retlen, buf);
> 
> Sorry, ignore this, there is another place that does this that needs
> some attention. I'll sent V2 shortly.

No need to hurry. :)
I agree that such overflows should be addressed, although they are purely 
theoretical. MTD is being used on small devices only.

Thanks,
//richard 

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

* Re: NAK: [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation
@ 2017-11-08 16:01     ` Richard Weinberger
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Weinberger @ 2017-11-08 16:01 UTC (permalink / raw)
  To: Colin Ian King
  Cc: David Woodhouse, Brian Norris, Boris Brezillon, Marek Vasut,
	Cyrille Pitchen, Andrea Adami, linux-mtd, kernel-janitors,
	linux-kernel

Colin,

Am Mittwoch, 8. November 2017, 16:57:57 CET schrieb Colin Ian King:
> On 08/11/17 15:46, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > Multiplying block_num and mtd->erasesize may potentially overflow
> > as they are both unsigned ints and so the multiplication is evaluated
> > in unsigned int arithmetic .  Cast block_adr to off_t to ensure
> > multiplication is off_t sized to avoid any potential overflow.
> > 
> > Detected by CoverityScan, CID#1461264 ("Unintentional integer overflow")
> > 
> > Fixes: fff1e32a50c0 ("mtd: sharpslpart: Add sharpslpart partition parser")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> > 
> >  drivers/mtd/parsers/sharpslpart.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/mtd/parsers/sharpslpart.c
> > b/drivers/mtd/parsers/sharpslpart.c index 5fe0079ea5ed..b1d97aa3bac4
> > 100644
> > --- a/drivers/mtd/parsers/sharpslpart.c
> > +++ b/drivers/mtd/parsers/sharpslpart.c
> > @@ -244,7 +244,7 @@ static int sharpsl_nand_read_laddr(struct mtd_info
> > *mtd,> 
> >  		return -EINVAL;
> >  	
> >  	block_num = ftl->log2phy[log_num];
> > 
> > -	block_adr = block_num * mtd->erasesize;
> > +	block_adr = (loff_t)block_num * mtd->erasesize;
> > 
> >  	block_ofs = mtd_mod_by_eb((u32)from, mtd);
> >  	
> >  	err = mtd_read(mtd, block_adr + block_ofs, len, &retlen, buf);
> 
> Sorry, ignore this, there is another place that does this that needs
> some attention. I'll sent V2 shortly.

No need to hurry. :)
I agree that such overflows should be addressed, although they are purely 
theoretical. MTD is being used on small devices only.

Thanks,
//richard 


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

end of thread, other threads:[~2017-11-08 16:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-08 15:46 [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation Colin King
2017-11-08 15:46 ` Colin King
2017-11-08 15:57 ` NAK: " Colin Ian King
2017-11-08 15:57   ` Colin Ian King
2017-11-08 16:01   ` Richard Weinberger
2017-11-08 16:01     ` Richard Weinberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.