Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936498AbdLRQ1V (ORCPT ); Mon, 18 Dec 2017 11:27:21 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:57970 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935993AbdLRQ1R (ORCPT ); Mon, 18 Dec 2017 11:27:17 -0500 Date: Mon, 18 Dec 2017 17:27:05 +0100 From: Boris Brezillon To: Andrea Adami Cc: Colin King , Richard Weinberger , kernel-janitors@vger.kernel.org, LKML , Marek Vasut , linux-mtd@lists.infradead.org, Cyrille Pitchen , Brian Norris , David Woodhouse Subject: Re: [PATCH][V2] mtd: sharpslpart: fix overflow on block_adr calculation Message-ID: <20171218172705.59e25d29@bbrezillon> In-Reply-To: References: <20171108161323.30662-1-colin.king@canonical.com> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1970 Lines: 53 On Fri, 10 Nov 2017 17:35:13 +0100 Andrea Adami wrote: > On Wed, Nov 8, 2017 at 5:13 PM, Colin King wrote: > > From: Colin Ian King > > > > 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") > > > > Signed-off-by: Colin Ian King > > --- > > drivers/mtd/parsers/sharpslpart.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/mtd/parsers/sharpslpart.c b/drivers/mtd/parsers/sharpslpart.c > > index 5fe0079ea5ed..0ddb79ac390d 100644 > > --- a/drivers/mtd/parsers/sharpslpart.c > > +++ b/drivers/mtd/parsers/sharpslpart.c > > @@ -192,7 +192,7 @@ static int sharpsl_nand_init_ftl(struct mtd_info *mtd, struct sharpsl_ftl *ftl) > > > > /* create physical-logical table */ > > for (block_num = 0; block_num < phymax; block_num++) { > > - block_adr = block_num * mtd->erasesize; > > + block_adr = (loff_t)block_num * mtd->erasesize; > > > > if (mtd_block_isbad(mtd, block_adr)) > > continue; > > @@ -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 > > > > Thanks for spotting this, > > Acked-by: Andrea Adami Applied. Thanks, Boris