public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Zhihao Cheng <chengzhihao1@huawei.com>
Cc: <richard@nod.at>, <vigneshr@ti.com>, <haver@vnet.ibm.com>,
	<s.hauer@pengutronix.de>, <yhao016@ucr.edu>,
	<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ubi: Refuse attaching if mtd's erasesize is 0
Date: Tue, 2 May 2023 10:56:14 +0200	[thread overview]
Message-ID: <20230502105614.7e849263@xps-13> (raw)
In-Reply-To: <20230423111041.684297-1-chengzhihao1@huawei.com>

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

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2023-05-02  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-23 11:10 [PATCH] ubi: Refuse attaching if mtd's erasesize is 0 Zhihao Cheng
2023-05-02  8:56 ` Miquel Raynal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230502105614.7e849263@xps-13 \
    --to=miquel.raynal@bootlin.com \
    --cc=chengzhihao1@huawei.com \
    --cc=haver@vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=s.hauer@pengutronix.de \
    --cc=vigneshr@ti.com \
    --cc=yhao016@ucr.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox