From patchwork Wed Nov 8 15:46:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 835868 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gcoEj4kv"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yX9fy3Q0Gz9s7c for ; Thu, 9 Nov 2017 02:47:54 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=R8E0za4YFUq9ll29r7b+vvcQKNkV8LTU05O9GlFniYM=; b=gcoEj4kvjeiRDY qxUqVp4zQ/auA3OkQlKOG6ZP6JkRmm1y1COoyo1fiiy9mlLpur6bbroIKrKaVATCAeSm+id3vc83o C7hKVURKpR2KsSLVRZvCVC6OgHjgYXBi8AxiblxqOEQypq1VCnnbanNMo+c7NAP4+Rb87U/D4gB72 sX8HblOVmpi8J5velzP+CgDXcQPsmxnmbX9mT7z/cPZ9i+GNnwWmvb60h0ubGbFy6pvHDJn0sX035 dGkg8xpKK78I0t0VkwqCjVQhQv82o6iB4xSWV0+J/dQkggSanYvENNpXvaVRUL0960OQLCWnZYTEw gGBh4O4qpgyhJhnIoaug==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eCSZw-0001Wr-BF; Wed, 08 Nov 2017 15:47:48 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eCSZV-0001KV-SF for linux-mtd@lists.infradead.org; Wed, 08 Nov 2017 15:47:23 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1eCSYz-0000Dn-GO; Wed, 08 Nov 2017 15:46:49 +0000 From: Colin King To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen , Andrea Adami , linux-mtd@lists.infradead.org Subject: [PATCH][mtd-next] mtd: sharpslpart: fix overflow on block_adr calculation Date: Wed, 8 Nov 2017 15:46:49 +0000 Message-Id: <20171108154649.30096-1-colin.king@canonical.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171108_074722_070727_4838E4E4 X-CRM114-Status: UNSURE ( 8.15 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [91.189.89.112 listed in list.dnswl.org] -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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") Fixes: fff1e32a50c0 ("mtd: sharpslpart: Add sharpslpart partition parser") Signed-off-by: Colin Ian King --- 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);