Message ID | 20230423111041.684297-1-chengzhihao1@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2165060vqo; Sun, 23 Apr 2023 05:14:21 -0700 (PDT) X-Google-Smtp-Source: AKy350aocVj86hLMF34hdrSkWXa7+7hF/9et1smo/UTCgB5nbh+J95hZ9fWvf8mEShIn5TgPacwS X-Received: by 2002:a17:90a:ac09:b0:247:92aa:c9b9 with SMTP id o9-20020a17090aac0900b0024792aac9b9mr9916200pjq.38.1682252061034; Sun, 23 Apr 2023 05:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682252061; cv=none; d=google.com; s=arc-20160816; b=KbuxO+EAoZamBaxtGlvE8Ubt5MrmXyqOHCpskMt65JJWsKrLMWcB5KHXeeBWJNKDF5 Gc3yGZ78uhVWrauIpLkKK9LuZ+XPFqJWiA252+JSXOw2pF7uGOuMd7Y9W51ODb33/6td I3qfwhRivP+xqAFwnMPNWuOUAJpPkuspZY49hMvSAd5tjNd1Rvz5zxBaVwsc49c0r93l /UhxPsIzmbw+5KVPnPd9zUOOe26hWcRr7UPHheQRQ+kQxDN1UJzMH+yntgZ9FGbaZQdE EiLBdhM+uCWQzXX1f8C1Vlytr+1qOWjTn6kLAYPu82Hy0KmW2iInj2Z/gl55tk+xF6oo z1RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=44WNIr8Eog3mVpD+NGi3JuE5z6CS44U1hO2d5gTvINU=; b=C/1F1++8rGqh+fWZwFt55PbGgga6zsHFHgO0AqWuKJ0k1P+fexl7UuCqgKmqKlL2mX hcwJoTxlfSLALDMXSN/XeGI0IlE/TYG4BmhTAGJa8+NrK0VEPOsTlDei/WtBV91eA1lh Bd6gqQOX/bA4oMpDCepg54k77IsMq8be98spO5YO/PdAvRDRhQCJVPQ19KVPuYaMKDOf I1miznnFsTjDdwlwg9L4QT/wNYLLWAgycdP0VY6cSw2QxxVwNACWTV8nLUUEPnvHE7gu YqWNqIr02vHOQadI6Rq90BIbbqqnWI+wuQrAxnvnzz0Gs3JkAhoVSo+A3CEvDXGU2SjU YzNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo7-20020a17090b1c8700b0024b011026aesi11887358pjb.76.2023.04.23.05.14.09; Sun, 23 Apr 2023 05:14:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229839AbjDWLLl (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Sun, 23 Apr 2023 07:11:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjDWLLj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 23 Apr 2023 07:11:39 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A11110C6 for <linux-kernel@vger.kernel.org>; Sun, 23 Apr 2023 04:11:38 -0700 (PDT) Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Q45Ch4n0XzKtfv; Sun, 23 Apr 2023 19:10:40 +0800 (CST) Received: from huawei.com (10.175.127.227) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Sun, 23 Apr 2023 19:11:35 +0800 From: Zhihao Cheng <chengzhihao1@huawei.com> To: <richard@nod.at>, <miquel.raynal@bootlin.com>, <vigneshr@ti.com>, <haver@vnet.ibm.com>, <s.hauer@pengutronix.de>, <yhao016@ucr.edu> CC: <linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH] ubi: Refuse attaching if mtd's erasesize is 0 Date: Sun, 23 Apr 2023 19:10:41 +0800 Message-ID: <20230423111041.684297-1-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763969136887830579?= X-GMAIL-MSGID: =?utf-8?q?1763969136887830579?= |
Series |
ubi: Refuse attaching if mtd's erasesize is 0
|
|
Commit Message
Zhihao Cheng
April 23, 2023, 11:10 a.m. UTC
There exists mtd devices with zero erasesize, which will trigger a
divide-by-zero exception while attaching ubi device.
Fix it by refusing attaching if mtd's erasesize is 0.
Fixes: 801c135ce73d ("UBI: Unsorted Block Images")
Reported-by: Yu Hao <yhao016@ucr.edu>
Link: https://lore.kernel.org/lkml/977347543.226888.1682011999468.JavaMail.zimbra@nod.at/T/
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
drivers/mtd/ubi/build.c | 7 +++++++
1 file changed, 7 insertions(+)
Comments
Hello, chengzhihao1@huawei.com wrote on Sun, 23 Apr 2023 19:10:41 +0800: > There exists mtd devices with zero erasesize, which will trigger a > divide-by-zero exception while attaching ubi device. > Fix it by refusing attaching if mtd's erasesize is 0. > > Fixes: 801c135ce73d ("UBI: Unsorted Block Images") IMHO, this should be backported to keep the vulnerable area as small as possible, so: Cc: stable@vger.kernel.org > Reported-by: Yu Hao <yhao016@ucr.edu> > Link: https://lore.kernel.org/lkml/977347543.226888.1682011999468.JavaMail.zimbra@nod.at/T/ > Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> > --- > drivers/mtd/ubi/build.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c > index 6a2d1ef8d43c..69e92c31ace0 100644 > --- a/drivers/mtd/ubi/build.c > +++ b/drivers/mtd/ubi/build.c > @@ -896,6 +896,13 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, > return -EINVAL; > } > > + /* UBI cannot work on flashes with zero erasesize. */ > + if (!mtd->erasesize) { > + pr_err("ubi: refuse attaching mtd%d - zero erasesize flash is not supported\n", > + mtd->index); > + return -EINVAL; > + } > + > if (ubi_num == UBI_DEV_NUM_AUTO) { > /* Search for an empty slot in the @ubi_devices array */ > for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++) Thanks, Miquèl
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 6a2d1ef8d43c..69e92c31ace0 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -896,6 +896,13 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, return -EINVAL; } + /* UBI cannot work on flashes with zero erasesize. */ + if (!mtd->erasesize) { + pr_err("ubi: refuse attaching mtd%d - zero erasesize flash is not supported\n", + mtd->index); + return -EINVAL; + } + if (ubi_num == UBI_DEV_NUM_AUTO) { /* Search for an empty slot in the @ubi_devices array */ for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++)