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 A119FC4332F for ; Tue, 7 Nov 2023 16:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344081AbjKGQVV (ORCPT ); Tue, 7 Nov 2023 11:21:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235604AbjKGQUs (ORCPT ); Tue, 7 Nov 2023 11:20:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 591F13A9A; Tue, 7 Nov 2023 07:54:42 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C64FBC433C8; Tue, 7 Nov 2023 15:54:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699372482; bh=97eecQJk0wc3+ip/nwZbPavKT7n0zht31RP2/tOF7Mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dQ2wLBmkKttLVFtK+v5xj/2ZcrewC6cpNZLFvXZ81Hl/iSFXl1wMNmyx41Iv30Eq7 v1jjrSLm4qMTRHOK1hW2NFIH6av0xlTTiSHRlMXI7UNUz4eYNwl8XhYywqKUFijKln Q+lxCWAF7t9PhX7qrVRFe5jHhj8zIQEUscO9mMupSV4q7fFnXfTfNX1BqgFIoNDJ5m n/Qlveg9Lpq0CIwGxnwUQ6PbgdfRV4QTZHQBdwqqNlsQn4FR2EWQqq5XEBRwgxtKaE k7SReCgvqfkwJwhp9gVKrD3vgrUIt8q+OpryFHuHiyAZPnrWfAy7eNMoPgTeQGx/EA e4reqf9bf8M8Q== 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, code@siddh.me, wonguk.lee1023@gmail.com, yogi.kernel@gmail.com, jfs-discussion@lists.sourceforge.net, ghandatmanas@gmail.com Subject: [PATCH AUTOSEL 4.19 04/11] fs/jfs: Add validity check for db_maxag and db_agpref Date: Tue, 7 Nov 2023 10:54:12 -0500 Message-ID: <20231107155430.3768779-4-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231107155430.3768779-1-sashal@kernel.org> References: <20231107155430.3768779-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.19.297 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 5e20d7270d5f2..eb86d170f2246 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