From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 3016A394785; Sat, 17 Oct 2026 17:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256980; cv=none; b=hO/Pgr3zaT5xn36esy0Zt1QHd9jxx/xPQV6NqGOT6grYkGrMpy7XdJa15K613OaTnxyGT+gE4m8qbt4JtvrjcEm8Q5ZBuzr8e5nDIKR6zEDpEEzzpwzMG6pN5u6hfvQ28ZmKyR1AtmAZC1+RFJb6dILmoxFM+DtIAIskTmOns7w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256980; c=relaxed/simple; bh=/NNv9RWHrLLt8GHVnhZ02TztZfsaq8vxpMhKA9IuvsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nulgpWmW0ryDDUNz3c04HebBRZv14bSZdFBUF8gO3CVD6hMVB5UBZcbZcp8z1f7uQb9luDpQETrkS181v6ilyPV6D4792OL40v0fMpZPZG4wQVX8HtsL1IAsCMvxlr9zoCcmhSLMRly7pllmysc0+FbI8ekZBgL+rvlRTA8ZkGI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2ObswA66; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2ObswA66" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 755221F000C4; Sat, 17 Oct 2026 17:09:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792256979; bh=Gg7sIUUbIe1G8Gbc6uHkIhjnCGwX6VLSV/xf138F8Hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2ObswA66HdH0DLY+rowI5Xe16XkMHNeeM/aJDdiXd3zH2mU4CooZvlLAzHsgkPKUT 3MO0tznQWPgkgoEQGUBlgytR2pYuhJ/6aWejZsKfH8BO/3BNuulLN+4dNDq24PUUdA oIgztMc2y8xqyHW6062SukTDgRiEiU47PRf5Ud04= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+b320a4d5f65a61dbbf89@syzkaller.appspotmail.com, =?UTF-8?q?J=C3=B6rn=20Engel?= , Pei Xiao , Miquel Raynal , Sasha Levin Subject: [PATCH 6.6 0413/1674] mtd: block2mtd: Fix divide error when erase_size is zero Date: Sat, 17 Oct 2026 17:44:45 +0200 Message-ID: <20261017160441.727777846@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pei Xiao [ Upstream commit b5965c4221165045e19736794ca5f48ae3d67142 ] The erase size is parsed from the "block2mtd" module parameter and can be set to zero. add_device() then evaluates if (size % erase_size) with a zero divisor, which triggers a divide error: divide error: 0000 [#1] PREEMPT SMP PTI RIP: 0010:add_device drivers/mtd/devices/block2mtd.c:296 [inline] RIP: 0010:block2mtd_setup2+0x592/0xda0 drivers/mtd/devices/block2mtd.c:459 Call Trace: block2mtd_setup+0x27/0xe0 drivers/mtd/devices/block2mtd.c:476 param_attr_store+0x214/0x310 kernel/params.c:589 module_attr_store+0x65/0x90 kernel/params.c:904 kernfs_fop_write_iter+0x3a4/0x540 fs/kernfs/file.c:345 ... Reject a zero erase size before performing the modulo operation so the existing "erasesize must be a divisor of device size" error path reports the invalid argument and frees the device. Fixes: ea6d833a3fdd ("mtd: block2mtd: check device size") Reported-by: syzbot+b320a4d5f65a61dbbf89@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/6a7b58ba.ac361c09.22ff0a.0045.GAE@google.com/ Suggested-by: Jörn Engel Cc: stable@vger.kernel.org Signed-off-by: Pei Xiao Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/devices/block2mtd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index 502c30124aa61..1eb6bcab7adc6 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -297,7 +297,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, } size = bdev_nr_bytes(bdev); - if ((long)size % erase_size) { + if (!erase_size || (long)size % erase_size) { pr_err("erasesize must be a divisor of device size\n"); goto err_free_block2mtd; } -- 2.53.0