From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33CA8C4332F for ; Tue, 7 Nov 2023 16:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234688AbjKGQEf (ORCPT ); Tue, 7 Nov 2023 11:04:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344551AbjKGQEH (ORCPT ); Tue, 7 Nov 2023 11:04:07 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B294D423E; Tue, 7 Nov 2023 07:55:21 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F0F7C433C7; Tue, 7 Nov 2023 15:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699372521; bh=PSUN0NMqDA37h3T4x2vv+KNlbTSCbCjyf1dceKw3+eY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RnRQFOqFlnboJETOzeFV2c5L+v5dX+mpXQuVTrxxOolLFhel3R46BYmzRDwKlQPwH BCu3yMbULhdKvJLw+mgsMhqfPalvjB2Dg3TNu6Esj//Y+8j0X6AlXU7MQr3YC8C3m5 1d/ilTYPJXbzGWKB+PblA2I54eV4kLZOISwQLBlGaRc9Lc4O10uvCDWeuA8PXoV9Sw IX+UjztFHtz/N1k47X8yJJOsv7Y2YtbbuKzPmlDaYFb/pad/84R+472RsM4uzQ+CYz KrLrhDFsKsuO275k3gqMU92kV5thHxrVfnp91p+5xIo5A+myGBlM00I/58MmOLraLK CRQv2ZPqEUItw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Juntong Deng , syzbot+38e876a8aa44b7115c76@syzkaller.appspotmail.com, Dave Kleikamp , Sasha Levin , shaggy@kernel.org, wonguk.lee1023@gmail.com, liushixin2@huawei.com, andrew.kanner@gmail.com, yogi.kernel@gmail.com, code@siddh.me, ghandatmanas@gmail.com, jfs-discussion@lists.sourceforge.net Subject: [PATCH AUTOSEL 4.14 4/9] fs/jfs: Add validity check for db_maxag and db_agpref Date: Tue, 7 Nov 2023 10:54:54 -0500 Message-ID: <20231107155509.3769038-4-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231107155509.3769038-1-sashal@kernel.org> References: <20231107155509.3769038-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.14.328 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juntong Deng [ Upstream commit 64933ab7b04881c6c18b21ff206c12278341c72e ] Both db_maxag and db_agpref are used as the index of the db_agfree array, but there is currently no validity check for db_maxag and db_agpref, which can lead to errors. The following is related bug reported by Syzbot: UBSAN: array-index-out-of-bounds in fs/jfs/jfs_dmap.c:639:20 index 7936 is out of range for type 'atomic_t[128]' Add checking that the values of db_maxag and db_agpref are valid indexes for the db_agfree array. Reported-by: syzbot+38e876a8aa44b7115c76@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=38e876a8aa44b7115c76 Signed-off-by: Juntong Deng Signed-off-by: Dave Kleikamp Signed-off-by: Sasha Levin --- fs/jfs/jfs_dmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c index 070638718be32..713f11dee52aa 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -208,6 +208,12 @@ int dbMount(struct inode *ipbmap) bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel); bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag); bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref); + if (bmp->db_maxag >= MAXAG || bmp->db_maxag < 0 || + bmp->db_agpref >= MAXAG || bmp->db_agpref < 0) { + err = -EINVAL; + goto err_release_metapage; + } + bmp->db_aglevel = le32_to_cpu(dbmp_le->dn_aglevel); bmp->db_agheight = le32_to_cpu(dbmp_le->dn_agheight); bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth); -- 2.42.0