From nobody Fri Dec 19 11:32:24 2025 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 EBB1A37885; Mon, 18 Dec 2023 14:14:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Sv1yw2hqrzYsp5; Mon, 18 Dec 2023 22:14:00 +0800 (CST) Received: from dggpeml500021.china.huawei.com (unknown [7.185.36.21]) by mail.maildlp.com (Postfix) with ESMTPS id CA832180087; Mon, 18 Dec 2023 22:14:52 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 18 Dec 2023 22:14:52 +0800 From: Baokun Li To: CC: , , , , , , , , , Subject: [PATCH 4/4] ext4: avoid dividing by 0 in mb_update_avg_fragment_size() when block bitmap corrupt Date: Mon, 18 Dec 2023 22:18:14 +0800 Message-ID: <20231218141814.1477338-5-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231218141814.1477338-1-libaokun1@huawei.com> References: <20231218141814.1477338-1-libaokun1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500021.china.huawei.com (7.185.36.21) Content-Type: text/plain; charset="utf-8" When bb_free is not 0 but bb_fragments is 0, return directly to avoid system crash due to division by zero. Fixes: 83e80a6e3543 ("ext4: use buckets for cr 1 block scan instead of rbtr= ee") CC: stable@vger.kernel.org Signed-off-by: Baokun Li --- fs/ext4/mballoc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 2fbee0f0f5c3..e2a167240335 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -845,6 +845,9 @@ mb_update_avg_fragment_size(struct super_block *sb, str= uct ext4_group_info *grp) if (!test_opt2(sb, MB_OPTIMIZE_SCAN) || grp->bb_free =3D=3D 0) return; =20 + if (unlikely(grp->bb_fragments =3D=3D 0)) + return; + new_order =3D mb_avg_fragment_size_order(sb, grp->bb_free / grp->bb_fragments); if (new_order =3D=3D grp->bb_avg_fragment_size_order) --=20 2.31.1