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 19DE4C4332F for ; Tue, 7 Nov 2023 15:48:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344252AbjKGPsI (ORCPT ); Tue, 7 Nov 2023 10:48:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344288AbjKGPrk (ORCPT ); Tue, 7 Nov 2023 10:47:40 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 409601734; Tue, 7 Nov 2023 07:47:26 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E434C433C7; Tue, 7 Nov 2023 15:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699372046; bh=kKLPun7SBsq2U2ir0tYFAYLFCCntONAkFVUrRYYLQMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EK7lhARJpQME23F4kzspE2zxDNxjKSBFlwCSd9eouCWC26sic3gAVHbtzV3bFpZ1C MFEoV8zW5A3YAKd6Oux+H4URfisRG3Ao9nkKO00u6A1efw5skt7HabBVxb7z4J1t5q rAneMtGTNglwjNBL0JI8czKEVLV80WvQgV/i7Qdz4M4OBbqvNIap2yMwO/NJ4SVSZ2 nytmkTEfASBA+O9hX3MFdW9pVtS+Eg4VT6+njv8gHDzAU+jamnbXQ32yNGC1PF2XDW K6UIs4DdMkavcRWcPBScxOf6GXVQewnkH1QuOftHQqw9vfGcZV+N1HtWFEa+geMEoN eB1A9jj8zfh2Q== 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, ghandatmanas@gmail.com, code@siddh.me, andrew.kanner@gmail.com, yogi.kernel@gmail.com, jfs-discussion@lists.sourceforge.net Subject: [PATCH AUTOSEL 6.6 13/36] fs/jfs: Add validity check for db_maxag and db_agpref Date: Tue, 7 Nov 2023 10:45:55 -0500 Message-ID: <20231107154654.3765336-13-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231107154654.3765336-1-sashal@kernel.org> References: <20231107154654.3765336-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@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 3a1842348112d..4d59373f9e6c9 100644 --- a/fs/jfs/jfs_dmap.c +++ b/fs/jfs/jfs_dmap.c @@ -195,6 +195,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