From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C088341A4 for ; Mon, 9 Oct 2023 13:48:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vFgSlglJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB471C433C9; Mon, 9 Oct 2023 13:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1696859318; bh=SsX1wG1KKibvEe4TTpEFbnrHiX8V6LdrKDO3Rzbmh2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vFgSlglJTU2BlyJEnL8aP/yDdIi0bzb4UM2kBXLKg/poh6B6j3KmX30TIDfFqKxOB +Gk+qnxdaHz5rqEcpmHxLy5lJDX7UzU7dRMSbx/B8d6enRg00nooBMThMcB1UdaCaF G3Jsyy5uR/+1QB4uuGRzBc4iT8cjhe1+oDXEoSd8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yu Hao , Zhihao Cheng , Miquel Raynal , Richard Weinberger , Sasha Levin Subject: [PATCH 4.14 39/55] ubi: Refuse attaching if mtds erasesize is 0 Date: Mon, 9 Oct 2023 15:06:38 +0200 Message-ID: <20231009130109.190892320@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231009130107.717692466@linuxfoundation.org> References: <20231009130107.717692466@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhihao Cheng [ Upstream commit 017c73a34a661a861712f7cc1393a123e5b2208c ] 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 Link: https://lore.kernel.org/lkml/977347543.226888.1682011999468.JavaMail.zimbra@nod.at/T/ Signed-off-by: Zhihao Cheng Reviewed-by: Miquel Raynal Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- 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 4ee1ff84076dc..f42e4b9fdea1a 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -869,6 +869,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++) -- 2.40.1